4.3.13 · D3Pretraining & Fine-Tuning LLMs

Worked examples — Quantization (INT8, INT4, GPTQ)

2,440 words11 min readBack to topic

The scenario matrix

Every quantization problem you will meet is one of these cells. We will hit all of them.

Cell Case class What makes it tricky Example
A Symmetric, all-positive values zero-point unused, range wastes negative half Ex 1
B Symmetric, mixed sign the standard weight case Ex 2
C Affine (asymmetric), all-positive (activations after ReLU) ; must place 0 exactly Ex 3
D Degenerate: all weights equal / → division blows up Ex 4
E Outlier destroys the range per-tensor fails, per-group rescues Ex 5
F Limiting bit-width: INT8 → INT4 → INT2 error grows as step doubles Ex 6
G GPTQ error compensation (interacting weights) round one weight, fix the rest via Ex 7
H Real-world word problem: does it fit the GPU? bytes, scale overhead, bandwidth Ex 8
I Exam twist: clamp an out-of-range value forgetting the clamp = garbage Ex 9

Prerequisite ideas we lean on: Weight Distributions in Neural Nets, Hessian and Second-Order Methods, AWQ (Activation-aware Weight Quantization), and the sibling methods in LoRA and QLoRA and Mixed-Precision Training (FP16, BF16).


The picture we keep returning to

Before any numbers: quantization is snapping real values onto a ruler with evenly spaced ticks. The tick spacing is . A value lands on its nearest tick; the tiny gap between the value and the tick is the error.

Figure — Quantization (INT8, INT4, GPTQ)

Ex 1 — Cell A: symmetric, all positive


Ex 2 — Cell B: symmetric, mixed sign (the normal weight case)


Ex 3 — Cell C: affine (asymmetric) on ReLU activations


Ex 4 — Cell D: the degenerate zero-range input


Ex 5 — Cell E: one outlier ruins per-tensor, per-group saves it

Figure — Quantization (INT8, INT4, GPTQ)

Ex 6 — Cell F: the limiting bit-width (INT8 → INT4 → INT2)

Figure — Quantization (INT8, INT4, GPTQ)

Ex 7 — Cell G: GPTQ error compensation by hand


Ex 8 — Cell H: real-world word problem, does it fit?


Ex 9 — Cell I: the exam twist — clamp or die


Recap of the matrix

Recall Which example covered which cell?

A → Ex 1 · B → Ex 2 · C → Ex 3 · D → Ex 4 · E → Ex 5 · F → Ex 6 · G → Ex 7 · H → Ex 8 · I → Ex 9

Recall Why does per-group beat per-tensor for outliers?

A single outlier sets the shared huge, collapsing all small weights to tick 0. A separate scale per small group keeps their ruler fine.

Recall In GPTQ, if a weight rounds up and inputs are positively correlated, which way does the neighbour move?

Down — the correction has a negative sign for a positive error and positive off-diagonal.


Cloze checkpoints

The symmetric INT4 scale for is ====. Dropping from INT8 to INT4 makes the step grow because ==the level count shrinks from 127 to 7. Per-group quantization stores one scale per block of weights to survive outliers. The GPTQ correction pushes error into the remaining weights weighted by the inverse Hessian . An out-of-range integer must be clamped== to before storing.