Quantization
Also known as: model quantization
Storing a model's numbers with fewer digits so it takes less memory and runs faster, at the cost of a little quality.
Draft - this entry has not been reviewed yet.
Formal
Converting model weights, and sometimes the working values of inference, from high-detail numbers (often 16 bits each) to coarser ones (8, 4 or fewer bits) by mapping them onto a smaller set of allowed values; it shrinks memory use and speeds up the math while adding small rounding errors.
In plain English
Like saving a photo as a smaller file - it loses a little fine detail you rarely notice, and in return fits on your phone and opens instantly.
In practice
A developer in a municipality tests 8-bit and 4-bit versions of the same open model on 200 real questions from case officers; the 8-bit one does as well as the original, the 4-bit one slips on sums, so she picks 8-bit.
Why it matters
Memory is usually what limits where a model can run, and using half the bits needs roughly half the memory - often the difference between using hardware you already own and renting capacity in someone else's cloud.
Technical deep dive
The basic scheme is affine (uniform) quantization: a real value x is mapped to an integer q = clamp(round(x / s) + z, q_min, q_max) and approximately recovered as x̂ = s · (q − z), where s is the scale and z the zero point. Symmetric quantization fixes z = 0 and suits roughly zero-centred weights; asymmetric quantization spends the extra parameter on skewed ranges such as post-ReLU activations. Granularity matters as much as bit width: one scale per tensor is cheap but coarse, per-channel scales are standard for weights, and LLM weight quantization at 4 bits usually uses per-group scales (for example one scale per 128 consecutive weights), which adds a small storage overhead but sharply reduces error.
There are two families of methods. Post-training quantization (PTQ) converts an already trained model, sometimes using a small calibration set to choose ranges. Quantization-aware training (QAT) simulates rounding during training or fine-tuning, using a straight-through estimator for gradients, and recovers more accuracy at low bit widths at the cost of a training run. Large language models brought specific problems: LLM.int8() (Dettmers et al., 2022) showed that a few activation feature dimensions contain large outliers that break naive 8-bit schemes, and handled them in 16-bit; SmoothQuant migrates activation outliers into the weights with a per-channel rescaling; GPTQ quantizes weights layer by layer using approximate second-order information; AWQ protects the weight channels that matter most for activations. QLoRA introduced the 4-bit NormalFloat (NF4) data type for fine-tuning on quantized base models.
It is important to be clear about what is quantized. Weight-only schemes (W4A16, W8A16) store weights compactly but dequantize them for 16-bit arithmetic; they mainly help memory-bound decoding, where speed tracks bytes read per token. Weight-and-activation schemes (W8A8 in INT8 or FP8) also use low-precision tensor-core math and help compute-bound prefill. FP8 comes in two variants, E4M3 and E5M2, trading mantissa precision against range, and newer hardware adds 4-bit floating-point formats. The KV cache can be quantized separately. In the llama.cpp ecosystem, GGUF files carry block-wise formats such as Q4_K_M and Q8_0.
The memory arithmetic is simple: 70 billion parameters take about 140 GB at 16 bits, 70 GB at 8 bits and roughly 35-40 GB at 4 bits including scales, which can decide whether a model fits on one accelerator. The failure modes are less obvious. Degradation is uneven: perplexity and general benchmarks may barely move while arithmetic, code, long-context retrieval or languages other than English can degrade noticeably, so evaluation should use task-specific data. Very low bit widths (3 bits and below) usually need QAT or careful methods. Quantization differs from distillation, which trains a new smaller model, and from pruning, which removes parameters; the three are often combined.
What to learn first
Everything this builds on, foundations first.
- Training data
- →Model training
- →Model weights
- →Quantization
Relationships
- Requires
- Model weights
- Alternative to
- Knowledge distillation
Sources & further reading
Reference works
- Jacob et al. (2018), Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference
- Dettmers et al. (2023), QLoRA - Efficient Finetuning of Quantized LLMs
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Check yourself
Loading…