Trade a tiny accuracy budget for huge size and speed wins
Modern hardware is much faster at int8 matmul than fp32 — sometimes 4x. Memory consumption drops proportionally. The cost: a small accuracy hit, usually <1% on standard benchmarks for well-quantized models. For LLMs, int4 weight-only quant (one of the most active areas in 2025-2026) lets you fit 7B-param models in 4GB.
Three flavors of quantization
- Dynamic quantization — weights stored as int8, activations quantized on-the-fly during inference. One-line setup. Best for transformer-shaped models dominated by Linear layers.
- Static (post-training) quantization (PTQ) — both weights and activations quantized, calibrated on a small dataset. Faster than dynamic but more setup.
- Quantization-Aware Training (QAT) — train with simulated quantization in the forward pass. Best accuracy but slowest to set up.
torchao — the modern API
The historical torch.quantization / torch.ao.quantization modules are being migrated to the standalone torchao package. torchao is where modern int8 / int4 / weight-only / GPTQ / AWQ techniques live. For new projects, start there.
Where quantization helps and hurts
- Helps: large transformer FFN, big embedding tables, LLM serving.
- Hurts: tiny models where the per-op overhead dominates, models with many non-Linear ops (the unquantized portions become the bottleneck).