AI Compass
Compass

Quantisation

Making models smaller without breaking them: int8 and int4, outlier channels, the methods compared, and how to measure the loss.

·2 min read·By Fachredaktion Technik
DETAIL
3 sections

The idea

A weight is normally stored as a 16-bit number. Store it instead as a 4-bit integer with a shared conversion factor per group and the model shrinks to a quarter, and fits on a card it did not fit on before.

What that buys

Format7 bn model70 bn modelTypical quality cost
float1614 GB140 GBBaseline
int87 GB70 GBunder 1 %
int43.5 GB35 GB1 to 3 %
int3 and below2.6 GB26 GBSubstantial, task-dependent

The methods

MethodPrincipleNeeds calibration data
Round to nearestSimply roundno
GPTQCompensate error layer by layeryes, a few hundred examples
AWQProtect important channelsyes
SmoothQuantShift scale between weight and activationyes
Quantisation-aware trainingSimulated during trainingfull training
  • Always calibrate with data resembling production, not arbitrary text.
  • After quantising, measure against your own fixed evaluation set, not against someone else's numbers.
  • Watch the group size: smaller groups are more accurate and need more memory for the scales.
  • Often keep the output layer and embedding at higher precision; they are sensitive and small.

The calculation

Group-wise asymmetric quantisation

s = (max(w) − min(w)) / (2ⁿ − 1) z = round(−min(w) / s) q = clip( round(w/s) + z , 0 , 2ⁿ−1 ) ŵ = (q − z) · s

Per group of weights a scale and a zero point are determined, onto which all weights in that group are mapped.

w
a weight
s
scale factor per group
z
zero point per group
n
bit width

The overhead from the scales

Effective bits per weight

n_eff = n + b_s / g

On top of the bits per weight comes the per-group scale and zero point amortised over the group.

n
bit width of the weights
g
group size
b_s
bits for scale and zero point per group, usually 32

At n = 4 and g = 128 that is 4 + 32/128 = 4.25 bits per weight. At g = 32 already 5.0 bits, that is 18 percent more memory for noticeably better accuracy. That trade-off is the real decision when picking a quantisation format.

Outliers

In large language models a few dimensions carry activations a hundred times larger than the rest. They force the scale factor up and make every other value in the same group correspondingly coarser.

Three counter-strategies:

  • Separate handling. Outlier channels stay in float16 while the rest computes in int8.
  • Shifting. Part of the scale is moved from the activation into the weight so both become well behaved.
  • Importance weighting. Channels with large activations are scaled before quantisation so their error comes out smaller.

Measure rather than assume

  1. 01

    Assemble your own evaluation set

    100 to 300 tasks from real use, with expected results.

  2. 02

    Measure the float16 baseline

    Without that number every comparison is meaningless.

  3. 03

    Measure at each stage

    int8, then int4, each against the same set.

  4. 04

    Break out by task type

    A single overall figure hides that arithmetic suffers more than phrasing.

For a high-risk system under the AI Act this measurement is not optional: changing the numeric representation changes the system and belongs, with its effects, in the technical documentation.

Related courses and sources

PaperFreeEN

Distilling the Knowledge in a Neural Network

A large model teaches a small one what it knows. The basis of the small models running in production today.

For anyone deploying small models in production who wants the basis for it.

ToolFreeEN

Hugging Face model hub

Hundreds of thousands of open models with licence, model card and weights. The first place to look when checking whether a local model is enough for a task.

The licence is on the model card, and not every open model allows commercial use.

Hugging FaceGo to offer
ToolFreeEN

llama.cpp

Running quantised models on ordinary hardware, down to single cards and small boards. The reference implementation for operating without a data centre.

For running without a data centre, down to single cards and small boards.

Was this page helpful?
Quantisation