Quantisation advanced 7 min read 12 flashcards

GPTQ and Second-Order Weight Rounding

Why rounding each weight to its nearest grid point is not the best rounding, how the Hessian of the layer reconstruction error tells you what to do instead, and what the approximations cost.

Round-to-nearest quantisation treats every weight independently. That is optimal if the objective is the error in the weights, and the objective is not the error in the weights. It is the error in the layer's output, and because output error is a quadratic form over the whole weight vector, rounding one weight up creates an error that a compensating adjustment to a different weight can partly cancel. Exploiting that is the difference between 4-bit models that work and 4-bit models that do not.

The objective

For one linear layer with weights \(W\) and calibration inputs \(X\), minimise

\[\left\lVert W X - \hat{W} X \right\rVert_2^2\]

over quantised \(\hat{W}\). Expanding shows the error depends on \(W\) only through \(H = 2XX^\top\), the Hessian of this objective with respect to the weights. \(H\) is a \(d_{\text{in}} \times d_{\text{in}}\) matrix computed once per layer from a few hundred calibration samples.

Exact minimisation is combinatorial. Optimal Brain Quantisation, adapting the older Optimal Brain Surgeon pruning framework, gives a greedy solution: quantise one weight, then update all remaining unquantised weights in closed form to compensate for the error just introduced. The update uses the inverse Hessian:

\[\delta_{\text{remaining}} = -\frac{w_q - \hat{w}_q}{[H^{-1}]_{qq}}\,\left(H^{-1}\right)_{:,q}\]

which says: distribute the error over the other weights in proportion to how correlated their inputs are with this one.

What GPTQ changes to make it fast

OBQ picks, at each step, the weight whose quantisation would cost least, which requires re-evaluating the whole ordering after every update. GPTQ (Frantar et al., 2023, arXiv:2210.17323) makes three changes:

Quantise in a fixed order, left to right along the input dimension, rather than greedily choosing. The ordering turns out to matter far less than the compensation itself, and fixing it means the same Hessian inverse serves all rows.

Process all output rows simultaneously, since they share \(H\). This turns per-weight scalar updates into matrix operations.

Batch the updates in blocks of 128 columns, applying compensation lazily outside the block, which keeps the working set in cache.

The result quantises a 175B-parameter model in a few GPU-hours. Numerical stability comes from Cholesky factorisation of \(H^{-1}\) and from damping the diagonal, typically by adding one percent of the mean diagonal value, since \(H\) is often near-singular.

When it breaks

The Hessian is only as good as the calibration set. \(H = 2XX^\top\) is computed from a sample, usually 128 sequences. If that sample does not represent deployment traffic, the compensation optimises for the wrong input distribution. Quantising an English calibration set and serving multilingual traffic is a documented way to lose accuracy that the calibration perplexity will not show.

Layer-wise reconstruction ignores error propagation. Each layer is quantised to minimise its own output error against the original model's inputs, so errors accumulated in earlier layers are not accounted for. Sequential variants that feed each layer the already-quantised model's activations address this and are meaningfully better at low bit width.

The activation-order option matters more than its default suggests. Quantising columns in order of decreasing activation magnitude, rather than left to right, reduces error noticeably on models with strong outlier channels, and it complicates the grouping so it is off by default in several implementations. On outlier-heavy models it is worth turning on.

It does not touch activations. GPTQ is a weight-only method, so the speedup it delivers is a memory-bandwidth speedup during decoding, not a compute speedup. On a prefill-dominated or compute-bound workload the gain is small, and expecting otherwise is a common planning error.

Damping is doing more than it looks. Near-singular Hessians arise routinely when the calibration set is small relative to the input dimension, and the damping constant is what keeps the inverse finite. Too little and the compensation explodes; too much and it degenerates toward round-to-nearest.

Check yourself

12 flashcards for this concept

Click a card to reveal the answer.

Drill the whole track