Lab

Quantisation

Quantisation: Storing a model's weights with fewer bits, in blocks that share a scale, so the model takes less memory and runs faster at a small cost in quality.

A model is trained with its weights stored as 16-bit or 32-bit numbers. Quantisation stores them with fewer bits, so the file is smaller and the model needs less memory. Because generating text is usually limited by how fast weights can be read from memory, a smaller model also runs faster.

The basic trick is a shared scale. Take q4_0, one of the oldest formats in llama.cpp. It cuts the weights into blocks of 32. For each block it picks a scale from the largest value, then rounds every weight to one of 16 levels, a 4-bit code. To use the weight, the runtime multiplies the code back by the scale. The scale itself takes 16 bits per block, so q4_0 costs 4.5 bits per weight, not 4.

Rounding loses information, and the scale decides how much. One unusually large value in a block stretches the scale, so every other weight in that block is rounded more coarsely. Newer formats fight this. Q4_K_M groups sub-blocks into super-blocks, gives each sub-block its own scale and minimum, quantises those scales too, and spends extra bits on the most sensitive tensors.

The result is a trade-off rather than a free lunch. Fewer bits mean a smaller, faster model whose outputs drift further from the original. Which format is good enough depends on the model and the task.

The explainer lets you quantise a block of weights yourself and see the rounding error, and how it grows into a worse model.

See it working

Explore it in What quantisation does to a model

Watch real llama.cpp formats round a block of weights, and see why blocks, scales and outliers decide how much a smaller file costs in quality.

Open the explainer