FP16 and BF16 are still floating-point formats. INT8 stores weights and activations as 8-bit integers with a separate scale (and sometimes zero point) mapping real values into 256 discrete levels. That is roughly 4× smaller than FP32 and fast on tensor cores INT8 paths—the dominant precision for mobile, edge, and high-QPS server inference.
INT8 is rarely used for full training from scratch; it shines after a model is trained in FP32/BF16. The capstone Quantization lecture wires INT8 into end-to-end deployment pipelines.
Learning Objectives
By the end of this lesson, students should be able to:
- Explain symmetric and asymmetric INT8 quantization with scale and zero point.
- Distinguish weight-only vs activation quantization.
- Describe post-training quantization (PTQ) vs quantization-aware training (QAT).
- Run a basic INT8 dynamic quantization example in PyTorch.
- Anticipate accuracy loss and how calibration data mitigates it.
From Float to INT8
Quantization maps a floating value x to integer q:
Symmetric: q = round(x / scale), dequantize as x ≈ q × scale.
Asymmetric: q = round(x / scale + zero_point), allowing the zero of the float range to map to a non-zero integer—useful for skewed activation distributions.
| Format | Bits | Values | Typical Use |
|---|---|---|---|
| FP32 | 32 | Continuous | Training master weights |
| FP16 / BF16 | 16 | Continuous | Mixed precision training |
| INT8 | 8 | −128…127 (signed) | Inference weights & activations |
Weight-Only vs Full INT8
Weight-Only INT8
- Weights quantized; activations stay FP16/FP32
- Easier PTQ, smaller accuracy hit
- Common in LLM serving (W8A16)
Weight + Activation INT8 (W8A8)
- Maximum speed and memory win
- Needs calibration or QAT
- Standard in CV edge deployment
PyTorch: Dynamic INT8 Quantization
Dynamic quantization converts weights to INT8 at load time; activations quantized on the fly during inference. Great first step for LSTM/Linear models on CPU; GPU INT8 paths vary by backend.
Calibration and Accuracy
Static INT8 chooses scale / zero_point by running representative batches (calibration set) and recording activation min/max or histograms (entropy, percentile methods). Skipping calibration—or using mismatched data—causes clipping and accuracy collapse.
Always measure accuracy, latency, and memory on a held-out set after INT8 conversion. A 0.5% metric drop may be acceptable for 3× speedup; a 5% drop usually is not.
Speedups depend on kernel support, memory bandwidth, and whether activations are quantized. Unfused CPU paths may show modest gains; GPU tensor core INT8 GEMMs show the largest wins.
Knowledge Check
- Short Answer: How many values can signed INT8 represent? Answer: 256 (−128 to 127).
- Short Answer: What is a quantization scale? Answer: Float factor mapping integer q back to approximate real value x ≈ q × scale.
- True/False: INT8 is standard for training LLMs from scratch. Answer: False—inference/deployment focus; training uses FP16/BF16/FP32.
- Multiple Choice: Dynamic quantization quantizes weights: (a) at train time, (b) at inference with on-the-fly activations, (c) never. Answer: (b) for activations; weights at convert time.
- Short Answer: What is a zero point? Answer: Integer offset in asymmetric quantization aligning float zero to an int value.
- Short Answer: What is calibration? Answer: Running sample data to choose scales for activations (static quant).
- Short Answer: What does W8A16 mean? Answer: 8-bit weights, 16-bit activations.
- True/False: INT8 always halves model accuracy. Answer: False—well-calibrated INT8 often loses <1% on vision tasks.
- Multiple Choice: Larger compression vs FP32: (a) FP16, (b) BF16, (c) INT8. Answer: (c).
- Short Answer: PyTorch function for quick linear INT8? Answer:
torch.quantization.quantize_dynamic.
Key Takeaways
- INT8 maps floats to 256 levels via scale (and optionally zero point).
- Primary win: smaller models and faster inference, especially W8A8 on tensor cores.
- Use calibration or QAT to control accuracy loss; always re-evaluate metrics.
- Weight-only INT8 is the gentlest entry; full INT8 maximizes performance.
- Next: Quantization — the full deployment workflow capstone.
Hands-on idea: Quantize a small MLP dynamically; plot accuracy vs latency on CPU. Discuss when GPU INT8 backends (TensorRT, torch.compile) are needed.
Discussion prompt: Why do LLM servers often use weight-only INT4/INT8 while activations stay FP16?