以下提供了一些 QAT 技巧。
- Keras 模型
-
对于 Keras 模型,创建浮点训练计算图前,请设置
backend.set_learning_phase(1)
,创建浮点评估计算图前,请设置backend.set_learning_phase(0)
。此外,应先调用backend.clear_session()
,而后再调用backend.set_learning_phase()
。Tensorflow1.x QAT API 是专为 TensorFlow 原生训练 API 而设计的。在 QAT 内使用 Kerasmodel.fit()
API 可能导致出现某些“nodes not executed”(节点未执行)问题。建议在 Tensorflow2 量化工具内将 QAT API 与 Keras API 搭配使用。 - 丢弃
- 实验证明 QAT 在没有丢弃 (dropout) 运算的情况下更有效。该工具当前不支持执行含 dropout 的微调,在运行 QAT 前,应移除或禁用 dropout。方法是使用 tf.layers 时设置
is_training=false
,或者使用 tf.keras.layers 时调用tf.keras.backend.set_learning_phase(0)
。 - 超参数
- QAT 类似于浮点模型训练/微调,因此 QAT 中同样需要使用浮点模型训练/微调中使用的技术。需要微调的重要参数包括优化器类型和学习率曲线等。