Hessian-Aware Rounding
Rounding each weight to the nearest grid point is not optimal — the layer-wise reconstruction objective has a closed-form correction, and that is what GPTQ computes.
The layer-wise objective
Post-training quantization methods almost never optimise the end-to-end loss — that would need labels, backpropagation through the whole network, and far more compute. Instead they fix each layer in turn and ask that its output be preserved on a small calibration set.
Let a linear layer have weights and let hold calibration inputs as columns. Then
so the problem decouples across the output rows, each governed by the same matrix , the Hessian of the row objective.
The optimal correction
Let , let be the current row, and fix coordinate to the quantized value . Among all satisfying that constraint, the one minimising is
where is the -th standard basis vector.
Assumptions
, so the objective is strictly convex and exists; the constraint is the single linear equation . No assumption is made about the other coordinates — they are all free to move, which is precisely the point.
Derivation
Write and form
A strictly convex quadratic under one linear equality constraint; KKT reduces to stationarity of the Lagrangian.
.
Stationarity in δ.
, hence , which is well defined because [H^{-1}]_{qq} > 0 for .
Impose the constraint to identify the multiplier.
Strict convexity makes this stationary point the unique global minimiser.
Substitute back, and rewrite c in terms of the rounding residual.
Key idea
Read the formula: is the -th column of the inverse Hessian, so the correction spreads over every remaining coordinate, in proportion to how strongly each is coupled to through the input covariance. Round-to-nearest is the special case where you refuse to apply this correction at all.
The minimum objective value incurred by fixing coordinate is
So the greedy rule is: quantize next the coordinate with the smallest — small rounding residual, or a direction the data barely constrains.
Doing it for the whole row without inversions
Naively, after fixing you would re-invert the Hessian restricted to the remaining coordinates. That would be per row. It is unnecessary.
Let and let index its coordinates with . Writing for with row and column removed,
a rank-one correction followed by deletion.
- Accumulate over the calibration set and damp: .
- Compute once — shared by all rows, since the proposition showed they share .
- For in a fixed order, and for all rows in parallel: a. Set . b. Apply to the not-yet-quantized coordinates. c. Update by the rank-one deletion above.
- Emit the quantized weights and the per-group scales.
Is the correction actually needed?
Suppose is not diagonal. Then there exist a weight vector and a quantization grid for which round-to-nearest incurs strictly larger layer-wise error than the corrected procedure.
The gap is governed by : the more correlated the inputs, the more there is to gain. Since the input activations of a transformer layer are strongly correlated across channels, this is the regime that applies.
What this does not say
The objective optimised here is layer-wise output reconstruction on a calibration set, not the model's loss. Three gaps follow, and they are all real:
- Error accumulates across layers. Each layer is optimised assuming its input is the unquantized model's input; once earlier layers are quantized, that assumption is false. Sequential variants that feed quantized activations forward address this partially.
- Calibration set dependence. is estimated from a few hundred sequences; a distribution shift at deployment invalidates it, and nothing in the derivation bounds that.
- Reconstruction is a proxy. Nothing here shows small layer-wise MSE implies small degradation in generation quality. The literature reports that it usually does; that is an empirical regularity, not a consequence of any of the results above.
References
- PaperY. LeCun, J. Denker, S. Solla (1989). Optimal Brain Damage
- PaperB. Hassibi, D. Stork (1992). Second Order Derivatives for Network Pruning: Optimal Brain SurgeonThe constrained-quadratic argument reproduced below originates here, for pruning.
- PaperE. Frantar, S. Ashkboos, T. Hoefler, D. Alistarh (2023). GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- PropositionThe layer-wise objective is a quadratic form in the weight errorproof includedReconstruction error decouples across output rows and equals a quadratic form with Hessian 2XXᵀ.
- TheoremOptimal update under a fixed roundingproof includedFixing one weight to its quantized value, the error-minimising correction to the remaining weights has a closed form involving one column of the inverse Hessian.
- CorollaryThe cost of quantizing a coordinateproof includedThe incurred error is the squared rounding residual divided by twice the corresponding diagonal entry of the inverse Hessian.
- LemmaInverse Hessian after deleting a coordinateproof includedRemoving one coordinate updates the inverse Hessian by a rank-one correction, so the whole sweep costs one inversion rather than one per weight.
- PropositionRound-to-nearest is suboptimal whenever inputs are correlatedproof includedIf the input covariance is not diagonal, rounding each weight independently is strictly worse than the corrected update for some weight vector.