Pidoku

Quantization Overview and Decision Guide

Module 13 Lesson 13.b 1h 30m Difficulty 3/5

Prerequisites 10.k, 10.l, 13.a


Before you start: words you need#

10.k taught the number formats (FP16, BF16, FP8, INT8, INT4, FP4) and 10.l the mechanics of quantization: scales, zero points, granularity, symmetric vs. asymmetric. This lesson assumes both and answers the engineering question: which quantization should I use for my model, my hardware and my workload? The next lessons go deep on each choice:

LessonTopic
13.c4-bit weights with GPTQ and AWQ
13.dQuantizing activations too (SmoothQuant and friends)
13.eFP8 and INT8 — the safe default
13.fINT4 and lower: kernels, formats, limits
13.gFP4 (NVFP4, MXFP4) on Blackwell and MI355X
13.hQuantizing the KV cache

Three shorthand names you will see everywhere:

ShorthandMeaning
W8A8Weights in 8 bits, activations in 8 bits — the matrix multiply itself runs in 8 bits.
W4A16Weights stored in 4 bits, converted to 16 bits inside the kernel; the multiply runs in 16 bits. Called weight-only quantization.
W4A4Weights and activations both in 4 bits — what FP4 tensor cores run.

1. Problem → Why → Optimization#

PROBLEM
  Decode reads every weight from GPU memory for every token. A 70B model at
  16 bits is 140 GB; on an H100 (3.35 TB/s) that is a 42 ms floor per step,
  so at most ~24 tokens/s for one user.

WHY IT HAPPENS
  At batch 1, a decode matrix multiply does ~1 FLOP per byte read. The H100
  can do ~295 FLOPs per byte it reads (its "ridge point", 6.a). The arithmetic
  units sit idle >99% of the time, waiting for bytes.

OPTIMIZATION
  Store weights (and/or activations, and/or the KV cache) in fewer bits.
  Fewer bytes per step → proportionally faster decode.

HOW IT WORKS
  Map each block of values onto a small set of levels, store the level
  numbers plus a scale per block, rebuild approximate values inside the kernel.

TRADE-OFFS
  ↓ memory, ↓ bandwidth, sometimes ↑ compute throughput (low-precision tensor cores)
  ↑ rounding error → possible quality loss
  ↑ tooling and validation work

WHEN TO USE
  Almost always for production LLM serving. 8-bit is close to free.
  4-bit when you are decode-bound or memory-bound and quality allows.

WHEN NOT TO USE (yet)
  - Prefill-heavy workloads with weight-only schemes (no gain, 13.f)
  - Before validating quality on YOUR task
  - Before fixing scheduling: 2x on a server stuck at batch 4 is worth less
    than fixing the batch (13.a)

Diagram — Which kind of quantization?#

flowchart TB
  S{"What limits you?"}
  S -->|"decode speed or memory at small batch"| W["Weight quantization"]
  S -->|"prefill or high-batch throughput"| A["Weights + activations<br/>FP8, or FP4 on Blackwell"]
  S -->|"concurrency: KV memory"| K["KV cache quantization (13.h)"]
  W --> W8{"How aggressive?"}
  W8 -->|"8-bit"| I8["FP8 / INT8<br/>near-lossless, simple rounding works"]
  W8 -->|"4-bit"| I4["NVFP4 / MXFP4 on new GPUs,<br/>AWQ / GPTQ INT4 elsewhere"]
  I8 --> E["Evaluate on YOUR task,<br/>not perplexity alone"]
  I4 --> E
  A --> E
  K --> E

  class S,W8 queue
  class W,K,I8,I4 memory
  class A compute
  class E neutral

2. The decision guide#

This is the practical core of the lesson. Checked against engine and vendor documentation on 11 November 2026.

STEP 0: Does the model maker publish a quantized checkpoint?
  In 2026 most large open models ship official FP8 and often NVFP4 versions
  (DeepSeek, Qwen, Kimi, GLM, Llama, Nemotron, gpt-oss in MXFP4 …).
  → Use it. The maker calibrated it and usually published its accuracy.
    Only quantize yourself when no official version exists or you need a
    different format.

STEP 1: What hardware?
├─ NVIDIA Blackwell (B200, B300, GB200/GB300, RTX 50, GB10)
│   ├─ FP8 W8A8               safe default, ~2x vs BF16
│   └─ NVFP4 W4A4             ~1.5–2x more on top; validate quality (13.g)
├─ NVIDIA Hopper (H100, H200)
│   ├─ FP8 W8A8               safe default ← START HERE
│   └─ INT4 W4A16 (AWQ/GPTQ)  for decode-bound or memory-bound serving (13.c)
├─ AMD MI300X / MI325X
│   └─ FP8 W8A8; INT4 weight-only through ROCm kernels
├─ AMD MI350X / MI355X
│   ├─ FP8 W8A8
│   └─ MXFP4 / MXFP6          native 4- and 6-bit tensor cores (13.g)
├─ Older NVIDIA (A100, L4, A10G, T4) — no FP8 tensor cores
│   ├─ INT8 W8A8 with SmoothQuant (13.d), or INT8 weight-only
│   └─ INT4 W4A16 (AWQ/GPTQ with Marlin kernels)
└─ CPU, Apple Silicon, consumer GPUs
    └─ GGUF k-quants (Q4_K_M etc., 15.e) or MLX quantization

STEP 2: What workload shape?
├─ DECODE-HEAVY (chat, agents, reasoning; output ≫ input)
│   └─ Any of the above helps; 4-bit helps most.
├─ PREFILL-HEAVY (RAG, summarization, long documents)
│   └─ Weight-only (W4A16) gives ~nothing. Use W8A8 or W4A4 so the
│      multiply itself runs in low precision.
└─ MEMORY-CONSTRAINED (the model does not fit)
    └─ 4-bit. Fitting at all beats everything.

STEP 3, separately: long contexts or many concurrent users?
  → Also quantize the KV cache to FP8 (13.h). At long context this is often a
    bigger win than going from 8-bit to 4-bit weights.

3. Simple analogy#

Shipping by weight. Your freight bill is per kilogram, and much of the cargo is packaging. Quantization is repacking into smaller boxes: the same goods, less weight, lower cost — up to the point where goods get damaged.

Different goods tolerate different packing. In a transformer, the feed-forward weights pack well, the attention projections less well, and a few small pieces (the output head, MoE routers) are fragile. Good quantization packs each piece as tightly as it can bear.


4. Tiny example — the four decisions#

Every quantization scheme is four choices (10.l explains each):

1. WHAT          weights only? + activations? + KV cache?
2. HOW MANY BITS 8, 6, 4, 3, 2?
3. GRANULARITY   one scale per tensor, per channel, or per block of 16/32/64/128 values?
4. SCALES        computed offline from sample data (static) or at run time (dynamic)?

The named methods are just points in that space:

Method / format    What      Bits  Granularity              Scales
──────────────────────────────────────────────────────────────────────────────
FP8 (E4M3)         W + A     8     per-tensor or per-channel  static or dynamic
                                   (+ per-token for A)
INT8 SmoothQuant   W + A     8     per-channel W, per-token A static/dynamic
GPTQ               W         4/3   group of 128               static, error-corrected
AWQ                W         4     group of 128               static, activation-aware
NVFP4              W + A     4     block of 16, FP8 scale     static W, dynamic A
MXFP4              W (+A)    4     block of 32, power-of-2    static W, dynamic A
GGUF Q4_K_M        W         ~4.8  super-blocks of 256        static
KV FP8             KV cache  8     per-tensor or per-head     static (calibrated) or dynamic

Once you see the four axes, the zoo of names stops being intimidating.


5. Technical explanation#

The gain, by phase and scheme#

Typical ranges on current engines, relative to BF16, for a dense or MoE model large enough to be memory-bound in decode. Your numbers will differ; measure.

                          Decode gain   Prefill gain   Weight memory   Typical quality change
BF16 (baseline)              1.0x          1.0x           1.00x          —
FP8 W8A8 (Hopper+)           1.6–2.0x      1.5–1.9x       0.50x          < 0.5 points
INT8 W8A8 (SmoothQuant)      1.6–1.9x      1.4–1.8x       0.50x          0.2–1 points
INT8 weight-only             1.6–1.9x      ~1.0x          0.50x          < 0.5 points
INT4 W4A16 (AWQ/GPTQ, g128)  2.3–3.5x      0.9–1.1x       0.28x          1–3 points
NVFP4 W4A4 (Blackwell)       2.5–4x        2.5–3.5x       0.28x          1–3 points, model-dependent
INT3 / 2-bit                 3–4x          ~0.9x          0.16–0.22x     large; rarely usable
FP8 KV cache                 depends*      —              KV 0.5x        < 0.5 points

* KV quantization’s gain depends on how many bytes per step are KV versus weights (12.f). At long context and high batch, KV bytes dominate and the gain can exceed that of weight quantization.

Why the prefill column looks like that#

Weight-only (W4A16):
  Weights are converted back to 16 bits inside the kernel; the MULTIPLY still runs in 16 bits.
  Prefill is compute-bound (12.c) → fewer weight bytes do not help.
  The conversion adds work → it can even be slightly SLOWER.

W8A8 and W4A4:
  Both inputs of the multiply are low precision → the tensor cores run 2x (FP8)
  or 4x (FP4) faster than BF16 (4.f). Prefill IS faster.

This is the single most important thing to understand about quantization, and the most common misconception. It is why the guide asks about workload shape.

What to quantize and what to leave#

QUANTIZE AGGRESSIVELY
  FFN / expert weights   most of the parameters (≥90% in MoE models), robust

QUANTIZE WITH CARE
  Attention q/k/v/o      more sensitive; errors propagate through attention

USUALLY LEAVE IN HIGHER PRECISION
  Embeddings             a lookup, so no bandwidth win; quality cost out of proportion
  LM head                errors go straight into the next-token probabilities
  Norm weights           tiny and scale-critical
  MoE router weights     a wrong expert choice is catastrophic; they are tiny anyway

QUANTIZE SEPARATELY
  KV cache               13.h

The first and last few layers are often kept at higher precision; in most models they are disproportionately sensitive. Official checkpoints list exactly which layers they excluded — read their quantization_config.

Validating a quantized model#

From 11.k, because it matters:

L1 NUMERICAL   logit error, KL divergence, top-1 agreement vs. BF16
               target: KL < 0.01, top-1 > 99%
L2 TASK        benchmarks ON YOUR DOMAIN, not perplexity alone
L3 BEHAVIOUR   long generations, instruction following, tool-call and JSON validity,
               reasoning traces, refusals
L4 PRODUCTION  A/B test with human or model-judge evaluation

L3 is where 4-bit schemes usually show their cost, and where teams that stopped at L2 get surprised. Reasoning models are especially sensitive: small per-token errors compound over thousands of thinking tokens, so evaluate them on long traces.


6. Under the hood: where the speedup comes from#

W4A16 decode multiply, per weight tile:

  memory → registers:  4 bits per weight   ← 4x less traffic than 16-bit
  registers:           unpack 2 weights per byte
                       convert: w = (q − z) × s   (16-bit arithmetic)
  tensor core:         16-bit multiply-accumulate

The unpack + convert costs ~10–20 extra operations per weight. Decode has
arithmetic to spare (intensity ~1 vs. a ridge of ~300), so this is free.
In PREFILL the same extra work is NOT free: you are already compute-bound.

Production W4A16 kernels (Marlin and its successors such as Machete, plus vendor kernels) go further: they reorder weights at load time so unpacking is branch-free and memory access is coalesced (6.b), and they feed the converted values straight into the tensor cores. They reach close to the 4x bandwidth gain at small batch, against ~1.5x for a naive convert-then-multiply.

W4A4 (NVFP4, MXFP4) removes the conversion entirely: the tensor cores read 4-bit values and their block scales directly (13.g).


7. Performance implications#

The gains in section 5 do not multiply with batching gains. Quantization shrinks the weight-read term, which batching was already sharing across users. At batch 256, weights are a smaller share of the bytes moved per step, so weight quantization helps less and KV quantization and low-precision compute help more.


8. Production implications#

  • Quantize offline and ship the quantized checkpoint. Never quantize at server start-up.
  • Record the exact recipe in your model registry (21.b): format, bits, group size, excluded layers, calibration data, tool and version.
  • Tools in 2026: llm-compressor (vLLM project; FP8, INT8, GPTQ, AWQ, NVFP4, MXFP4, KV and attention quantization), NVIDIA TensorRT Model Optimizer (ModelOpt: FP8, NVFP4, INT4 AWQ for TensorRT-LLM, vLLM and SGLang), AMD Quark (FP8, MXFP4, MXFP6, and NVFP4 export for MI355X), bitsandbytes for quick experiments, and llama.cpp’s llama-quantize for GGUF. The original AutoAWQ project was deprecated in 2025; its methods live on in llm-compressor.
  • Calibrate on data that looks like your traffic. Calibrating on Wikipedia and serving code is measurably worse (13.c).
  • Check that your engine has a fast kernel for the scheme on your GPU. A 4-bit model on a slow fallback path can be slower than BF16.
  • Keep the BF16 checkpoint deployable for rollback.

9. Common mistakes#

  1. Expecting prefill gains from weight-only quantization.
  2. One scale for a whole tensor at 4 bits. Accuracy collapses; 4-bit needs small blocks.
  3. Quantizing the LM head, embeddings and MoE router with everything else.
  4. Validating with perplexity only.
  5. Assuming published accuracy deltas transfer to your task.
  6. Ignoring the official checkpoint and spending a week reproducing it worse.

10. Hands-on exercise#

A. Run the guide. For three workloads you know (or invent plausible ones), walk the decision guide and justify your recommendation, including the GPU.

B. Measure the phase asymmetry. Serve a model in BF16 and as INT4 weight-only (W4A16). Measure prefill throughput (long prompt, 1 output token) and decode throughput (short prompt, long output) for both. Confirm decode improves ~2.5x and prefill does not, and explain it with arithmetic intensity (6.a).

C. Layer sensitivity. Quantize a small model three ways: everything at 4 bits; everything except the LM head and embeddings; FFN only. Compare an evaluation score and the memory of each. Which gives the best quality per byte?

D. Official vs. home-made. If your model has an official FP8 checkpoint, quantize the BF16 model to FP8 yourself with llm-compressor and compare both on the same evaluation. Explain any difference.


11. Interview questions#

  1. Why does quantization speed up decode? Give the mechanism.
  2. Why does weight-only quantization not speed up prefill, while FP8 W8A8 does?
  3. What are the four axes that define a quantization scheme?
  4. Which layers would you keep in higher precision, and why?
  5. You are deploying on B200s. How do you choose between FP8 and NVFP4?
  6. How do you validate a quantized model before deployment?
  7. When does KV cache quantization matter more than weight quantization?

12. Further reading#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in