Bookmarks

Quantisation

quantization

Compressing the weights and computations of a trained model into lower-precision numbers — integers or short floats — to reduce memory use and speed up inference.

Also: quantization, weight quantisation, model quantisation

checked 9 Nov

All terms

A neural network weight is stored as a 16- or 32-bit floating-point number, but it can be written as an 8- or even 4-bit one: the model takes several times less memory, inference runs faster, and quality changes only slightly. Quantised models are therefore the usual way to run an LLM on a single graphics card.

How much memory precision saves

PrecisionBytes per weightA 7-billion-parameter model
FP324≈ 28 GB
FP16, BF162≈ 14 GB
INT8, FP81≈ 7 GB
INT4, FP40.5≈ 3.5 GB

That covers the weights only: activations and the KV cache take memory separately, and they can be quantised too. On the other hand, at low weight precision more numbers fit per cycle, so on formats the hardware supports, such as FP8, speed rises as well.

Formats and methods

INT8 is integers: each value is obtained from a float by multiplication by a scale, and the scale is calibrated on a small sample of data. FP8 is 8-bit floating-point formats with two layouts: E4M3 (4 bits of exponent and 3 of mantissa) and E5M2 (5 and 2), that is, a choice between precision and range of values. FP4 and 4-bit integers are an extreme case: quality depends heavily on the compression method.

MethodHow it works
RTNsimple rounding to a low-precision grid; the default option in many tools
GPTQpost-training quantisation based on second-order information: compresses a 175-billion-parameter model to 3–4 bits in roughly four GPU-hours without noticeable loss of quality
AWQfinds about 1% of salient weights from the activation distribution and protects them by scaling; no backpropagation needed
QATquantisation is built into the training or fine-tuning itself, so the loss is smaller

Quality loss

Quantisation does not preserve quality in full, so the quantised version is compared with the original on one’s own tasks. Sensitive tensors and layers can be kept at higher precision: the tools even point out where the divergence after compression is greatest.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • fine-tuning

    Fine-tuning changes the weights for the sake of task quality, while quantisation merely compresses already-trained weights for the sake of memory and speed.

In depth in the references

where the topic is covered in detail

Appears in the references