What is quantization in AI?
Storing a model's numbers with less precision, such as 4 bits instead of 16, so it needs far less memory and can run on smaller hardware, at some cost in accuracy.
intermediate · Also called Quantisation
A model is a very large set of numbers. Each one has to be stored, and the question is how precisely. Quantization means storing them less precisely, to save space.
The arithmetic
Meta's Llama 3 8B has 8 billion numbers, published at 16 bits each. 16 bits is 2 bytes, so the model needs about 16 GB just to hold its weights.
Store each number in 8 bits and it needs about 8 GB. Store each in 4 bits and it needs about 4 GB, a quarter of the original. That is the difference between needing a large graphics card and fitting on a much smaller one.
The sum is the same at any size: parameters times bytes per parameter. It is the first sum to do before you try to run an open model yourself.
What you give up
Fewer bits means each number is rounded more coarsely. Picture recording every price in a shop to the nearest pound instead of the nearest penny. Most totals come out close; a few do not. A quantized model behaves the same way: close to the original on much of its work, a little worse on some of it.
The better methods are careful about where to round. Hugging Face describes them as lowering memory while trying to keep as much accuracy as possible, and some need a calibration pass on sample data to choose the rounding well. Squeezing all the way to 1 or 2 bits is where those careful methods are needed most.
Memory for the weights
16 GBfits a 24 GB graphics card
What rounding does to 8 weights (65,536 possible values)
| Weight | Stored | Off by |
|---|---|---|
| 0.8137 | 0.8137 | <0.0001 |
| -0.2291 | -0.2291 | <0.0001 |
| 0.0412 | 0.0412 | <0.0001 |
| -0.6675 | -0.6675 | <0.0001 |
Hollow: the weight as trained. Filled: the value stored at this many bits.
8 billion weights × 16 bits = 16 GB just to hold them. That fits a 24 GB graphics card, with no room counted for the conversation. Each weight is now one of 65,536 values, off by up to less than 0.0001 here.
Memory is weights × bits ÷ 8, for the weights alone; the KV cache needs more on top. The weights are made up and rounded the simplest way, to evenly spaced steps; real methods choose their steps more carefully.
Where you see it
If you download an open model to run at home, with tools built on llama.cpp for example, you will usually be offered the same model at several bit sizes. The smaller file loads on smaller hardware; the larger one is closer to the original.
Hugging Face lists more than 20 quantization methods in its own library, some going as low as 1 bit, each suited to different hardware.
How to choose
Start from the memory you have. Pick the largest version that fits with some room to spare, since a long conversation needs memory for the KV cacheKV CacheWork a model saves from the text it has already read, so it is not redone for every new token. Prompt caching keeps that work between requests and charges less for it. on top of the weights. Then test it on your own tasks, because the averages in a model card may not match your use.
Sources