My account

Quantization

Quantization stores the model's numbers with fewer bits, like FP8 or INT4 instead of BF16. It saves memory and memory reading, so decode gets faster and more chats fit on a GPU. But it adds small rounding errors, and the quality loss is often uneven between tasks and languages. Choose the format by hardware and workload, and prove quality with evals split by group.

Not reviewedWritten with AI helpReading time: 12 minShop assistant examplePython

Author: bezzad

Contents

The problem: half the cost, the same answers?

GPU rent is the biggest line in our shop assistant’s bill. A teammate opens a Pull Request that changes one line: the 8B model now runs with INT4 weights. “The weights are 4 times smaller. I tried 20 prompts and the answers look the same.”

Two weeks later, support sees more broken return forms, and some Persian customers get strange answers. On average, the model was fine. In some groups, it was not.

What quantization is

A model is billions of numbers. Normally each is stored in BF16: 16 bits, 2 bytes. Quantization stores them with fewer bits.

The same 8B model, bits per numberBF1616 bitsabout 16 GBFP88 bitsabout 8 GBINT44 bitsabout 4 to 5 GBFewer bits: less memory to hold and read, but more rounding error
Fewer bits per number make the model smaller and faster to read, but each number is rounded more.
  1. Rounding. With 4 bits there are only 16 possible values. Each weight is rounded to the nearest one.
  2. Scales. To keep the rounding small, numbers are split into small groups, and each group gets its own scale factor. That is why INT4 is “about 4 to 5 GB”, not exactly 4.
  3. Smart methods. Methods like GPTQ and AWQ choose the rounding so that the most important weights lose the least. They need a small set of example text (calibration data).
  4. The result is a small error in every layer. Usually small enough. Sometimes not, as we will see.

What can be quantized

What Common formats Main win Notes
Weights only INT4 (AWQ, GPTQ), INT8 Less memory, faster decode at small batches The math still runs in 16 bits inside the kernel.
Weights and activations FP8, INT8 Also faster math, so prefill and big batches gain too Needs hardware support, for example FP8 on recent NVIDIA GPUs.
KV cache FP8, sometimes lower About twice as many tokens in flight with FP8 Often a big win for long chats. Check quality too.

Check what your GPU and your serving engine support. A format that has no fast kernel on your hardware can be slower than BF16.

Where the speed comes from

Quantization is not “4 times smaller, so 4 times faster”. The win depends on where the GPU is limited.

  1. Decode at small batches is memory-bound. The GPU reads all weights in every step. Half the bytes means close to half the reading time. Weight-only INT4 shines here.
  2. Prefill and big batches are compute-bound. Fewer bytes to read do not help much. Only formats that also make the math faster, like FP8 on supporting hardware, help here.
  3. Freed memory is the hidden win. Smaller weights leave more room for the KV cache. More tokens in flight means bigger batches, so more users per GPU. This is often where the cost saving really comes from.
  4. Kernels matter. The same format can be fast in one engine and slow in another. Measure on your setup.

Quality: check every group

The loss from quantization is often small on average, but it is not spread evenly.

Example scores: the drop is not the same in every groupEnglish chat9292Persian chat9086Valid JSON forms9995Long chats8887BF16INT4
Example numbers only. The English score did not move, but Persian chat and JSON forms dropped.

Areas that often feel it first:

  1. Exact formats, like JSON with the right field values.
  2. Math, code and reasoning, where one small error changes the whole result.
  3. Long contexts, where small errors add up over many tokens.
  4. Some non-English languages. Research suggests some languages can lose more than English. Test each language you serve.
  5. Smaller models. A small model often loses more from the same format than a big one.

So the eval must be split by group. A simple check:

def compare(base, quant, max_drop=1.0):
    ok = True
    for group, score in base.items():
        drop = score - quant[group]
        if drop > max_drop:
            ok = False
        print(f"{group:<18} {score:5.1f} {quant[group]:5.1f} drop {drop:4.1f}")
    return ok

base  = {"english_chat": 92, "persian_chat": 90, "json_valid": 99}
quant = {"english_chat": 92, "persian_chat": 86, "json_valid": 95}
print("ship" if compare(base, quant) else "do not ship")   # do not ship

A safe way to roll it out

  1. Build the eval set first, from real traffic: each language, each task type, short and long chats.
  2. Start with the gentlest format your hardware supports, often FP8. Go lower only if you need to.
  3. Run the eval on both versions, and set a clear limit for the drop in each group.
  4. Load test both at your latency targets, and compare cost per million tokens. The saving must be real.
  5. Release to a small share of traffic, and watch quality signals: thumbs down, broken forms, support reopen rate.
  6. Keep the BF16 version ready to switch back.

Common mistakes

Mistake Result Right way
“I tried 20 prompts, it looks the same.” Hidden drops in some groups. An eval set split by language and task.
Looking only at the average score One group gets much worse unseen. A limit for every group.
Expecting 4 times faster from 4 times smaller Disappointment at big batches. Know if you are memory-bound or compute-bound, and measure.
A format with no fast kernel on your GPU Slower than before. Check hardware and engine support.
Not using the freed memory Little cost saving. Let the engine use it for more KV cache and bigger batches.

Summary in six lines

  1. Quantization stores numbers with fewer bits: FP8, INT8, INT4.
  2. It saves memory and memory reading, so decode gets faster and more chats fit.
  3. Weight-only formats help most at small batches; FP8 math also helps prefill and big batches.
  4. Quantizing the KV cache can almost double the tokens in flight.
  5. Quality loss is uneven: check each language and task on its own.
  6. Prove it with evals and a load test, then release step by step.

Done reading this lesson?Mark it as finished so it shows in your lessons list and report card.