Quantization
Quantization represents a model's weights, and sometimes its activations, with fewer bits per number, such as 8-bit or 4-bit integers instead of 16- or 32-bit floating point, to cut memory use and speed up inference.
Every parameter in a neural network is a number, and by default those numbers are stored as 16- or 32-bit floating-point values. Quantization maps them onto a coarser scale. Hugging Face's documentation describes the common case of going from 32-bit floats to 8-bit integers, which can represent only 256 different values. A scale factor and a zero point define how the original range of values is stretched over those 256 steps, and anything outside the chosen range is clipped to the nearest end.
The payoff is memory. A model with 70 billion parameters needs about 140 gigabytes just for its weights at 16 bits each, about 70 gigabytes at 8 bits and about 35 gigabytes at 4 bits. That is often the difference between needing several data centre GPUs and fitting on one, or between a model that needs a server and one that runs on a laptop. Integer arithmetic can also be faster on hardware built for it, and moving fewer bytes out of memory speeds up generation, which is usually limited by memory bandwidth.
The cost is precision, and the work is in limiting the damage. Post-training quantization converts a finished model, using a small calibration dataset to measure the range of values flowing through it. Quantization-aware training simulates the rounding during training so the model learns to tolerate it. For large language models, Tim Dettmers and colleagues showed in August 2022 with LLM.int8() that a small number of extreme outlier values dominate performance; keeping those in 16-bit while multiplying more than 99.9% of values in 8-bit halved inference memory for models up to 175 billion parameters without degradation.
Lower bit widths followed quickly. GPTQ, from Elias Frantar and colleagues in October 2022, quantized a 175-billion-parameter model to 3 or 4 bits in about four GPU hours with negligible accuracy loss, letting it run on a single GPU and speeding up inference by about 3.25 times on an NVIDIA A100 and 4.5 times on an A6000 compared with 16-bit. Formats like these are why so many open-weight models are downloaded in 4-bit or 8-bit versions to run on personal machines.
Quantization is not free. Lower precision can hurt quality on harder tasks, the effect varies by model and method, and the energy saving is not guaranteed: benchmarks cited in Hugging Face's documentation found the 4-bit NF4 format could raise energy use on models under 3 billion parameters because unpacking the numbers costs more than it saves. A quantized model should be judged by testing it on the work it will actually do.
It means representing a model's numbers with fewer bits, for example 8-bit or 4-bit integers instead of 16-bit or 32-bit floating point. This shrinks the model's memory footprint and can make it faster to run, at the cost of some numerical precision. Usually a little, sometimes not measurably. Careful methods such as LLM.int8() at 8 bits and GPTQ at 3 to 4 bits reported negligible accuracy loss on very large models. Quality drops faster at very low bit widths and on smaller models, so results should be checked on the tasks that matter. They are quantized versions of a model in which each weight is stored in 4 or 8 bits. A 4-bit version needs roughly a quarter of the memory of the 16-bit original, which is why it can run on a consumer graphics card or laptop where the full model would not fit. Post-training quantization converts a model after training is finished, often using a small calibration dataset to set value ranges. Quantization-aware training simulates the reduced precision during training so the model adapts to it. The first is cheaper and more common; the second usually preserves more accuracy.Common questions
What does quantization mean in AI?
Does quantization make a model worse?
What do 4-bit and 8-bit models mean?
What is the difference between post-training quantization and quantization-aware training?
Search for "LLM quantization", "post-training quantization" or a specific method such as GPTQ to see how models are compressed. The research papers on arXiv and the documentation of libraries such as Hugging Face Transformers and Optimum explain the methods reliably. When a model card or vendor claims a quantized version is as good as the original, look for the benchmark scores of both versions side by side.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.