quantization aware training qat
**Quantization-Aware Training (QAT)** is **the training methodology that simulates quantization effects during training by inserting fake quantization operations in the forward pass** — enabling models to adapt to reduced precision (INT8, INT4) during training, achieving 1-2% higher accuracy than post-training quantization while maintaining 4× memory reduction and 2-4× inference speedup on hardware accelerators.
**QAT Fundamentals:**
- **Fake Quantization**: during forward pass, quantize activations and weights to target precision (INT8), perform computation in quantized domain, then dequantize for gradient computation; simulates inference behavior while maintaining float gradients
- **Quantization Function**: Q(x) = clip(round(x/s), -128, 127) × s for INT8 where s is scale factor; round operation non-differentiable; use straight-through estimator (STE) for backward pass: ∂Q(x)/∂x ≈ 1
- **Scale Computation**: per-tensor scaling: s = max(|x|)/127; per-channel scaling: separate s for each output channel; per-channel provides better accuracy (0.5-1% improvement) at cost of more complex hardware support
- **Calibration**: initial epochs use float precision to stabilize; insert fake quantization after 10-20% of training; allows model to adapt gradually; sudden quantization at start causes training instability
**QAT vs Post-Training Quantization (PTQ):**
- **Accuracy**: QAT achieves 1-3% higher accuracy than PTQ for aggressive quantization (INT4, mixed precision); gap widens for smaller models and lower precision; PTQ sufficient for INT8 on large models (>1B parameters)
- **Training Cost**: QAT requires full training or fine-tuning (hours to days); PTQ requires only calibration (minutes); QAT justified when accuracy critical or precision
Go deeper with CFSGPT
Get AI-powered deep-dives, save terms, and run advanced simulations — free account.
Create Free Account