Sub topic 13
How much quality you give up when you quantise
This chapter assumes you know that quantisation stores weights in fewer bits, and that you can read names like Q4KM. Here the question is what that costs in output quality.
What gets lost
Quantisation rounds each weight to a nearby value on a coarser grid. Each weight is slightly wrong, and the errors add up across billions of weights. The model still works, but its predicted probabilities drift a little from the original model's.
The loss does not grow evenly. Going from 16 bits to 8 changes almost nothing. Going from 4 bits to 2 changes a lot, because the grid becomes very coarse.
Typical size and quality steps
The figures below are approximate. They vary by model, and the sizes are for an 8B-parameter model.
| Format | Bits per weight (approx.) | Size for 8B | Typical quality effect |
|---|---|---|---|
| Q8_0 | 8.5 | 7.9 GiB | Hard to tell from 16-bit |
| Q6_K | 6.6 | 6.1 GiB | Very close to 16-bit |
| Q5_K_M | 5.7 | 5.3 GiB | Small loss |
| Q4_K_M | 4.85 | 4.5 GiB | Small but measurable loss, a common default |
| Q3_K_M | 3.9 | 3.6 GiB | Noticeable loss |
| Q2_K | about 3 | about 3 GiB | Often clearly degraded |
You can reproduce the size column with the formula from the memory chapter:
def weights_gib(params_billion, bits_per_weight):
return params_billion * 1e9 * bits_per_weight / 8 / 2**30
formats = {
"Q8_0": 8.5,
"Q6_K": 6.56,
"Q5_K_M": 5.69,
"Q4_K_M": 4.85,
"Q3_K_M": 3.91,
}
for name, bits in formats.items():
print(f"{name}: {weights_gib(8.0, bits):.2f} GiB")Measuring the loss
Perplexity measures how surprised a model is by a reference text. Lower is better. Compare a quantised file against a higher-precision file of the same model on the same text:
llama-perplexity -m model-Q4_K_M.gguf -f wiki.test.raw -ngl 99Run the same command on model-Q8_0.gguf. The gap between the two numbers is the cost of the smaller file. Perplexity is a proxy. It does not show how the model behaves on your own tasks.
Rules of thumb
- Larger models tolerate quantisation better. A 4-bit 14B model usually beats an 8-bit 7B model, even though the 14B file is only about 1 GiB larger.
- Small models (1B to 3B) lose more at 4 bits and below.
- Code, maths, and structured output tend to break before casual chat does.
- Below about 3 bits, expect more errors and repetition, and spend time testing.
- Newer K-quant and importance-matrix (imatrix) files often keep more quality at the same size than older formats, so file origin matters.
A practical procedure
- Pick the largest model that fits your memory budget at Q4KM, with room for the KV cache.
- If memory is left over, move up to Q5KM or Q6_K, or raise the context length.
- If it does not fit, first try a smaller context. Drop to Q3 only as a last step.
- Run your own prompts on the final file before you rely on it.
Exercise
You have about 8 GiB for weights. Compare a 14B model at Q4KM (4.85 bits per weight) with a 7B model at Q8_0 (8.5 bits per weight). Which fits, and which would you try first?
Show answer
The 14B file needs 14e9 × 4.85 / 8 / 2^30 ≈ 7.9 GiB. The 7B file needs 7e9 × 8.5 / 8 / 2^30 ≈ 6.9 GiB. Both fit the weights budget, but the 14B leaves almost no room for the KV cache. Try the 14B first, since larger models tolerate 4-bit well, and shorten the context or use a smaller KV cache if memory is tight. Fall back to the 7B at Q8_0 if it does not fit.