Return the standard quantization-aware-training recipe.
The QAT analogue of get_default_qconfig: it uses the same grid geometry
for activations and weights, but wraps each observer in a
lucid.quantization.FakeQuantize module. During training that wrapper both
refreshes (scale, zero_point) from live statistics and applies
straight-through fake-quantization, so the training graph experiences the exact
rounding / clamping of int8 inference while gradients keep flowing. Fine-tuning
under that simulated error lets the weights adapt to it, recovering accuracy that
plain PTQ leaves on the table for aggressive (low-bit or quantization-sensitive)
models.
- Activations — a per-tensor-affine
quint8fake-quant driven by aMovingAverageMinMaxObserver. The moving average smooths the per-batch range so the simulated grid does not jitter from step to step during training. - Weights — a per-channel-symmetric
qint8fake-quant onch_axis=0, matching the eventual inference-time weight quantization exactly.
Returns
QConfigA recipe whose two factories build lucid.quantization.FakeQuantize
modules (rather than bare observers) for activations and weights.
Notes
- Install it with
lucid.quantization.prepare_qat, notlucid.quantization.prepare; after training,lucid.quantization.convertfolds the fake-quant statistics into a genuinely quantized model. - The standard QAT schedule toggles the two
FakeQuantizeswitches over time — observe + fake-quant early, then freeze the observer (and BN stats) as training converges — vialucid.quantization.FakeQuantize.disable_observer, etc. - Activations use a moving-average min/max here rather than a histogram: the range is re-estimated every step, so a cheap running statistic is both sufficient and more stable than a per-step histogram.
Examples
>>> import lucid.quantization as Q
>>> qat = Q.get_default_qat_qconfig()
>>> type(qat.activation()).__name__
'FakeQuantize'
>>> type(qat.weight()).__name__
'FakeQuantize'See Also
get_default_qconfig—The static-PTQ counterpart (bare observers, no fake-quant).get_default_qat_qconfig_mapping—Installs this recipe as a model-wide mapping.- lucid.quantization.FakeQuantize—The wrapper both factories build.