Skip to content

Quantization

Storing a model's numbers with fewer bits, for example 8 or 4 instead of 16 or 32, so it becomes smaller, faster and cheaper with only a small loss in quality.

Also int8 · 4-bit · model compression

Fig. / How it works
32-BIT4-BIT2-BIT
Role · kind
Using and applyingTechnique
Level
Intermediate

Instead of writing every price as 12.3456789, you round to 12.35. You lose a tiny bit of precision but the price list gets much shorter and quicker to read.

Where it fits

+All relationships as a list

See it on the full map

Try it

Shrinking a model by rounding its weights
Loading interactive widget…
TakeawayFewer bits per weight make models smaller and cheaper. Done naively, a few outlier weights wreck the model; giving each small group its own scale keeps GPT-2 almost intact down to 4 bits.

How it works

A model’s weights are usually stored as 16- or 32-bit floating-point numbers. Most of that precision is not needed to make good predictions. Quantization rounds the weights to a small set of levels that fit in fewer bits.

The basic recipe for one group of weights:

  1. Find their range, say from −0.8 to 0.8.
  2. Divide that range into 2ᵇ evenly spaced levels (256 levels for 8 bits, 16 for 4 bits).
  3. Store each weight as the index of its nearest level, plus one shared scale factor for the group.

Memory shrinks proportionally: from 16 to 4 bits is a 4× saving, which is what lets large language models with billions of parameters run on a single consumer GPU or even a phone. Because moving weights from memory is often the real bottleneck, smaller weights also mean faster serving.

The cost is rounding error. At 8 bits it is usually negligible; at 4 bits and below, methods that quantize in small groups, keep a few sensitive weights at higher precision, or briefly retrain help preserve quality.

The math

Symmetric quantization of weight ww with bb bits and scale s=max⁡∣w∣/(2b−1−1)s = \max|w| / (2^{b-1} - 1):

q=round(w/s),w^=s⋅qq = \text{round}(w / s), \qquad \hat{w} = s \cdot q

Everyday use cases

  • Case 01

    LLMs on laptops and phones

    4-bit quantized open models fit in consumer memory.

  • Case 02

    Cheaper serving

    Smaller weights mean less memory traffic, more users per GPU and lower cost.

Strengths, weaknesses and when to use it

Strengths

  • Large memory savings (16-bit to 4-bit is four times smaller).
  • Often faster inference on supporting hardware.

Weaknesses

  • Quality drops, slightly at 8 bits and more at very low bit widths.
  • Hardware and software support varies.

When to use itWhen a model is too big or too slow for where it needs to run.

Compare with

Check yourself

  1. Q01

    A model has 7 billion weights. Roughly how much memory do the weights need at 4 bits each?

    Show answer

    A: About 3.5 GB 7 billion × 0.5 bytes = 3.5 GB (at 16 bits it would be 14 GB).

Go deeper