TL;DR
Most neural networks are trained and stored with 32-bit floating-point numbers. Quantization replaces those numbers with low-precision integers, usually 8-bit, and maps them back to approximate real values when needed. The model becomes about four times smaller than its float32 version, and integer arithmetic is faster and cheaper on most hardware. The price is a small rounding error on every value.
The method is mostly a rule for choosing a scale and an offset, plus a check that the rounding error does not change the answers the model gives.
Where you'll see it: running large language models on laptops and phones, serving image classifiers on edge devices, and cutting GPU memory so a bigger model fits on one card.
Intuition
Rulers with fewer marks
Measure a table with a ruler marked in tenths of a millimetre and you get an answer to a tenth. Measure it with a ruler marked only in whole millimetres and the answer is still good enough for most jobs, and the ruler is simpler to make and to read. Quantization is the second ruler. A float32 weight carries about seven significant decimal digits. An 8-bit integer can take only 256 values. If you choose the 256 values carefully, placed where the weights actually live, the network barely notices.
Why does it exist? Memory is the first reason. A model's weights must be read from memory for every token or every image, and memory traffic is often the bottleneck, not arithmetic. Fewer bits per weight means fewer bytes to move. Integer multiply-add units are also smaller and cheaper in silicon and energy than floating-point ones.
The rounding grid
Take a range of real values, say from to . Cut that range into 256 equal steps. Every real value is replaced by the nearest step. The steps form a grid, and the error for any value is at most half a step. That is the whole idea. The rest of the work is choosing the range well and handling the arithmetic.
- rounding error, step 0.5
The sawtooth shape is the important picture. Error grows as a value moves away from a grid point and then snaps back at the next one. Over many weights, these errors are small, close to random, and tend to cancel in sums.
flowchart LR A["Float32 weights"] --> B["Pick scale and zero point from the range"] B --> C["Round to integers in the 8-bit range"] C --> D["Integer matrix multiply (accumulate in int32)"] D --> E["Rescale to real values"] E --> F["Next layer"]
The math
Affine quantization
Let be a real value. Choose a scale (a real number, the size of one grid step) and an integer zero point (the integer that represents real zero). The quantized value is
where for signed 8-bit integers and . The function goes to the nearest integer, and forces values outside the range to the nearest end. Dequantization maps back:
The difference is the quantization error.
Given observed values with minimum and maximum , the usual choice makes the grid cover exactly that range:
The zero point is what allows real zero to be represented exactly. If then and . Exact zeros matter because padding, masks and ReLU outputs are full of them.
Symmetric quantization
Many libraries use a simpler scheme with . Set for signed 8-bit. Zero is then automatically on the grid, and the integer arithmetic has no offset terms to handle. The cost is that a range such as wastes about a third of the grid: the scale must cover , so the part below is never used.
Error bound
Because moves a value at most half a step, for any inside the range
Halving the step doubles the number of levels and halves this bound. Each extra bit of precision therefore halves the worst-case error. The bound says nothing about how the error affects the loss, which is what matters in practice.
Quantized matrix multiply
For a layer (a matrix multiply) with quantized inputs and weights, substitute and . The accumulated sum becomes
The sum is a sum of integer products, which can be accumulated exactly in 32-bit integers. Only one floating-point multiply by is needed per output, usually folded into a single rescale. Most of the arithmetic is integer.
Worked examples
Take a layer whose weights have and , and use signed 8-bit integers with and .
- Scale: .
- Zero point: .
- Quantize : , rounds to , plus gives .
- Dequantize: . The error is .
- Quantize : , rounds to , plus gives . Dequantize: . The error is .
- Quantize : , rounds to , plus gives , exactly the top of the range. Dequantize: . The error is .
- Quantize : , and exactly.
Interpretation: every error is below the bound . Zero is recovered exactly because of the zero point. The stored values are 8-bit integers, a quarter of the float32 size.
Suppose a language model has weights.
- In float32 each weight takes 4 bytes, so the weights need GB.
- In float16 each weight takes 2 bytes, so GB.
- In 8-bit integers each weight takes 1 byte, so GB. Add a few percent for scales and zero points.
- In 4-bit integers each weight takes half a byte, so GB plus overhead.
Interpretation: at 4 bits the model fits in the memory of a consumer laptop, where the float32 version needs about 28 GB before counting activations. The arithmetic is also cheaper, but the memory saving is the one most people feel first, because generating each token reads all the weights once.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Activations with a few very large outliers | One outlier stretches the range, so ordinary values share a few grid points and lose precision | Per-channel scales, clipping the range, or keeping outlier channels in higher precision |
| Very low bit width (for example 4 bits or fewer) on a sensitive model | Error accumulates over many layers and accuracy drops sharply | Use per-group scales, or quantization-aware training |
| Hardware without fast integer kernels | Quantized weights are unpacked back to float, so there is no speedup and some overhead | Choose a format the hardware supports, or quantize only weights and keep floating-point arithmetic |
| Quick post-training quantization on a small model | Some layers lose more than the average suggests | Measure accuracy on a held-out set per layer, and fine-tune or use quantization-aware training if needed |
| Quantization applied to layers that feed a softmax or normalisation | Small errors in the logits or statistics change the output distribution | Keep those layers in floating point |
Quantization pairs naturally with Pruning. Pruning removes weights, quantization shrinks the ones that remain, and together they cover much of the Model Compression toolbox. A quantized model whose accuracy has slipped can often be recovered with a short Fine-Tuning run, using the quantized arithmetic in the forward pass and a straight-through estimate of the rounding in the backward pass.
History
Fixed-point arithmetic was common in digital signal processing and early neural hardware long before deep learning. Researchers in the 2010s asked how few bits a trained network could use. Vanhoucke, Senior and Mao (2011) showed that 8-bit fixed-point arithmetic could speed up a neural network on CPUs with little loss of accuracy. Courbariaux and colleagues pushed further with binary and very low-bit weights in 2015, arguing that the network could learn to tolerate coarse values.
The method became standard for deployment after Jacob and colleagues at Google (2017) described an integer-only inference scheme, with the affine mapping and zero point given above. Later work on large language models ran into outlier activations that broke naive 8-bit schemes. Dettmers and colleagues (2022) addressed this by keeping a few outlier channels in higher precision, which made 8-bit inference practical for models with billions of parameters.
Check yourself
QuestionA layer's weights span the range . Using 8-bit unsigned integers with and , what is the scale ?Show answer
. Each integer step is about in real units, so the largest possible rounding error is about .
QuestionUsing the scale and zero point , quantize and dequantize the result. What is the error, and does it respect the bound ?Show answer
, which rounds to . So and . The error is , which is less than the bound . The error is positive because rounded up.
QuestionWhy does the zero point exist when symmetric quantization with would be simpler to compute?Show answer
With an offset, the integer arithmetic needs extra correction terms, which costs time. The zero point exists because an asymmetric range such as would waste grid points on the empty negative side under symmetric quantization. It lets the grid match the real range exactly and still represent zero exactly. Symmetric quantization trades some of that accuracy for simpler arithmetic.
QuestionA model's accuracy drops by 6 points after 8-bit quantization, mostly in one layer whose activations contain rare values near 100 while typical values are near 1. Explain the cause and suggest one fix.Show answer
The rare large values stretch the range, so the scale becomes about . Typical values near 1 then fall into only one or two grid steps, and most of their information is lost. One fix is to clip the range at a percentile so rare outliers are saturated, accepting a small error on them. Another is to keep that layer, or those specific outlier channels, in higher precision.
Sources
- Jacob et al., Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference (2017): https://arxiv.org/abs/1712.05877
- Gholami et al., A Survey of Quantization Methods for Efficient Neural Network Inference (2021): https://arxiv.org/abs/2103.13630
- Dettmers et al., LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale (2022): https://arxiv.org/abs/2208.07339