Kolkata ·  
AI engineering
beyond text
deep · 6 min

Quantization

Storing a model's weights in fewer bits, so it's smaller and faster, for some loss in quality.

updated 29 Sept 2026

Say we go to download Llama 3.1 8B to run on a laptop. There isn't one file. There's a list:

  • F16, 14.96 GiB
  • Q8_0, 7.95 GiB
  • Q6_K, 6.14 GiB
  • Q4_K_M, 4.58 GiB
  • Q2_K, 2.95 GiB

Same model, same training, five sizes. The smallest is a fifth of the biggest. So what got thrown away, and how much does it hurt? That's quantization: storing a model's weights in fewer bits. Let's work out what those names mean, and then which one to pick.

Rounding onto a small grid

A weight in a trained model is a 16-bit number like 0.021 or −0.118. A 4-bit number can only take 16 different values. Quantizing to 4 bits means squeezing every weight onto one of those 16 steps.

The plain way works on small blocks of weights, say 32 neighbours at a time. We find one scale for the block, so the weight furthest from zero lands on the top or bottom step. We divide every weight by that scale and round to the nearest whole number. Now each weight is a small integer, and we store the 32 integers plus the one scale.

To use a weight, the engine multiplies the integer back by the scale. We get something close to the original, but not the original. The gap is the rounding error.

That's called round-to-nearest, and llama.cpp's Q4_0 is exactly this: blocks of 32, each weight rebuilt as integer times block scale.

Why bother with blocks? Because big language models have a few weights and features with values far larger than the rest. One giant number stretches the scale, and all the ordinary numbers next to it get squeezed onto two or three steps. With one scale per block, the damage stays in that block. These outliers were exactly what broke early 8-bit attempts; the fix back in 2022 kept the few outlier dimensions in 16-bit and ran more than 99.9% of the math in 8-bit, which halved the memory with no loss even on a 175-billion-parameter model.

Now the names. The scales take space too, so a "4-bit" file isn't quite 4 bits. The newer K-quants group blocks into super-blocks with a small scale (sometimes also a minimum) per block, which comes to 4.5 bits per weight for Q4_K. The _M in Q4_K_M means it mixes types across the model's tensors, averaging about 4.9 bits. Q4_0 and Q8_0 are the old plain-rounding formats, now marked legacy.

Why smaller is also faster

Here's how fast each of those files generates text on the same machine:

From 29 tokens a second to 72, just by shrinking the file. Reading the prompt barely changed, though (923 tokens a second at F16, 784 to 865 for the rest). Why would one speed up and not the other?

That's prefill and decode. Generating each new token means reading every weight once, so the speed is set by how many bytes have to come out of memory. Fewer bits, fewer bytes, faster tokens. Reading the prompt does a lot of math on each weight it loads, so it's limited by arithmetic instead, and smaller weights don't help much. The local models article shows the same thing from the hardware side.

Notice the chart flattens at the bottom. Below about 4 bits, speed mostly sits between 70 and 80 tokens a second while quality keeps falling. That end of the list buys size, not much speed.

The same logic holds on servers. For Llama 3.1 in vLLM, 4-bit weights with 16-bit activations (people write that W4A16) cut latency by 1.5 to 2.5 times and cost per query by 2 to 3 times when requests come one at a time. But under heavy batching, the work is limited by arithmetic, and formats that also shrink the activations to 8 bits (W8A8) got the most throughput.

Smarter than rounding

Plain rounding treats every weight the same. Is that a problem? At 4 bits it's noticeable, at 3 it falls apart. So the methods people actually use look at a small sample of text first (calibration data) to see how the model uses its weights, then round with that in mind.

GPTQ fixes errors as it goes. When rounding one weight adds error, it nudges the not-yet-rounded weights to make up for it, using information about how sensitive the output is to each one. It got 175-billion-parameter models to 3 or 4 bits in about four GPU hours.

AWQ noticed that about 1% of weights matter far more than the rest, and that you find them by looking at the activations flowing through them, not at the weights. It scales those channels up before rounding so they lose less. It doesn't need backpropagation, so it's less likely to overfit the calibration sample.

llama.cpp's version of the idea is an importance matrix, a file you pass to the quantizer that says which weights matter most. The very low-bit "I-quants", like IQ2_XXS, are built on it.

How much quality goes

Perplexity is a measure of how surprised the model is by real text, lower is better. Here's LLaMA3-8B at 16 bits and after three methods at 4 and 3 bits:

At 4 bits the smart methods sit close to the original. At 3, plain rounding is way off and the smart ones hold. At 2 bits (off the chart), everything breaks, with perplexities in the hundreds up to the millions.

A bigger study of Llama 3.1 ran more than half a million evaluations, including chat, coding and long documents. With well-tuned methods, 8-bit floating point was effectively lossless, 8-bit integers lost 1 to 3%, and 4-bit GPTQ kept about 99% of the original's score, 98.9% on coding.

Bigger models hold up better. The 70B LLaMA3 shrugged off low bit widths far better than the 8B.

Where people get confused

Those two studies sound like they disagree. One says LLaMA3 still loses a noticeable amount, the other says 4-bit rivals 8-bit. Line them up by method and bit width and they mostly agree. The gloomy one includes plain rounding, and its warning is mostly about 3 bits and below. The upbeat one used tuned GPTQ at 4 bits with good calibration data, and argues that untuned settings make losses look bigger than they need to. So when someone quotes a number, ask which method and how many bits.

Perplexity also isn't your task. A drop that looks tiny there might matter more for what you're doing, or less. Run your own evals on the quantized model before switching.

A few smaller traps. Don't quantize a file that's already quantized; llama.cpp warns it can wreck quality, so always start from the 16- or 32-bit original. The KV cache is a separate choice from the weights. And trying to win the quality back with a quick LoRA fine-tune afterwards made the 8B model worse, not better.

One naming clash: the vector index article uses "quantization" for compressing embedding vectors in a search index. Same idea of fewer bits, different thing being squeezed.

Back to the list

So which file? Q4_K_M is where most people start: a third of the F16 size, more than twice the speed, and a small loss when it was made with a smart method. Q8_0 if you have the room (even plain rounding at 8 bits scored 6.2 against the original's 6.1 on that perplexity test). Q2_K only if nothing else fits, and test it hard, because at that point the model may simply be broken. And if the model only just fits at 4 bits, it's worth trying a smaller model at 8 bits against it on your own questions. Nobody has a table that answers that one for your task.

Further reading