Chapter 31Down the Rabbit Hole: How GPTQ Rounds a 175B Model to 3 Bits Without Breaking It
I've been writing int8 and int4 CPU kernels lately: a VNNI path for torchao's DA8W4 linear layer, and a faster sub-byte DequantizeLinear for ONNX Runtime. That work moves packed 4-bit numbers around and expands them, bit-exactly. I'd never asked where those numbers come from. Someone decided which of 16 values each weight becomes, and my kernels inherit that decision. For a big share of Hub 4-bit checkpoints, the answer is GPTQ.
Rounding is not harmless#
OPT-66B has WikiText2 perplexity 9.34 in FP16. Round every weight to the nearest 4-bit grid point (RTN, one grid per row) and it goes to 110. At 3 bits RTN breaks every model in the paper: OPT-175B goes from 8.34 to about 7,300.
Same weights, same 4-bit grid, GPTQ: OPT-66B lands at 9.55; 3-bit OPT-175B at 8.68. No extra bits, no retraining, no gradients. About 128 sample sequences, 4.2 hours for OPT-175B on one A100. Only which grid point changes.
Why anyone bothers#
OPT-175B in FP16 is about 350 GB, five 80 GB A100s. At batch 1 each weight is read once for about two FLOPs, so time per token is roughly bytes over memory bandwidth. The paper's kernel took 3-bit OPT-175B from 230 to 71 ms per token on an A100 (3.24x), and from 589 to 130 ms on an A6000 (4.53x).
None of that comes from less math. Weights are expanded to FP16 right before the multiply. The win is fewer bytes moved, so it shrinks as batch grows, and at big batch weight-only int4 can be slower than FP16 because dequantizing is extra work.
A bill split between three friends#
The restaurant takes payments in 50-cent steps. Ana owes $0.30, Ben $0.30, and Cleo is owed $0.10. The group owes $0.50.
| Strategy | Ana | Ben | Cleo | Total |
|---|---|---|---|---|
| Round each alone | $0.50 | $0.50 | $0 | $1.00 (50 cents too much) |
| In order, pass the leftover | $0.50 | about $0.11, rounds to $0 | $0 | $0.50 (exact) |
That's GPTQ: round one weight, push its error onto the weights you haven't rounded. Same as Floyd-Steinberg dithering. GPTQ's upgrade is that it knows how much each remaining weight should absorb, from the data.
weights: 0.30 0.30 -0.10 rounded: ? ? ? inputs 1 and 2 are 90% correlated
Plain rounding would give [0.5, 0.5, 0], layer loss 0.19.
The loss is smaller than it sounds#
GPTQ never sees the real loss. It quantizes one linear layer at a time and asks how far the quantized layer's output is from the original's on calibration inputs X:
minimize over Ŵ: ‖ W X − Ŵ X ‖²
loss(row) = δ · (X Xᵀ) · δᵀ where δ = ŵ − w
H = 2 X XᵀIt splits into independent rows with the same quadratic form. The "Hessian" is just twice the covariance of the layer's inputs, independent of the weights, computed once and shared across all 4096 rows. Correlated inputs are the slack: push one weight up and the other down and the output barely moves. In the bill, Ana and Ben were the correlated pair.
Optimal Brain Surgeon, with "set to zero" swapped out#
The update is from 1992: Hassibi and Stork's Optimal Brain Surgeon deleted one weight and adjusted the others to minimize damage under a quadratic loss. Quantization replaces "set to 0" with "set to its grid point". One Lagrange multiplier gives:
δ = − (w_q − quant(w_q)) / [H⁻¹]_qq · H⁻¹[:, q]
ΔL = (w_q − quant(w_q))² / (2 [H⁻¹]_qq)Every other weight moves along column q of the inverse Hessian, scaled by the error just made: correlated inputs move most, unrelated ones not at all. A large [H⁻¹]_qq means input q is well explained by the others, so its error is cheap.
From a beautiful idea to something that finishes#
OBQ (2022) applied this greedily, each row picking its own cheapest-next weight. Each row then needs its own inverse Hessian updated every step: O(d_row · d_col³), about an hour for ResNet-50 size. OPT-175B was out by roughly three orders of magnitude.
The toy implementation (numpy, Algorithm 1 with per-row grids)
def gptq(W, X, bits, block=128, damp=0.01):
W = W.copy()
rows, cols = W.shape
H = 2 * X @ X.T
H += damp * np.mean(np.diag(H)) * np.eye(cols)
U = np.linalg.cholesky(np.linalg.inv(H)).T # upper factor of H^-1, once
S, Z = row_grids(W, bits) # per-row scale and zero
Q = np.zeros_like(W)
for i in range(0, cols, block):
j2 = min(i + block, cols)
W1 = W[:, i:j2].copy()
E = np.zeros_like(W1)
Ub = U[i:j2, i:j2]
for j in range(j2 - i):
w = W1[:, j:j + 1]
q = quant(w, S, Z, bits)
Q[:, i + j] = q[:, 0]
err = (w - q) / Ub[j, j]
W1[:, j:] -= err @ Ub[j:j + 1, j:] # fix the rest of the block now
E[:, j] = err[:, 0]
W[:, j2:] -= E @ U[i:j2, j2:] # one lazy update for the rest
return QThe test that convinced me#
The story predicts that with uncorrelated inputs H is diagonal, the update moves nothing, and GPTQ collapses to plain rounding. The toy builds a 256 x 512 layer, 4,096 calibration tokens with AR(1) features plus four 20x outlier channels, and reports relative output error:
| Input correlation | Bits | RTN | GPTQ | Ratio |
|---|---|---|---|---|
| 0.9 | 4 | 0.0146 | 0.0028 | 5.2x |
| 0.9 | 3 | 0.0647 | 0.0138 | 4.7x |
| 0.0 | 4 | 0.0146 | 0.0138 | 1.1x |
| 0.0 | 3 | 0.0641 | 0.0603 | 1.1x |
Correlation is the fuel. It's a synthetic layer, so I read nothing into exact numbers, but the direction is what the math says.
Where it breaks#
All the failure modes looked like one problem: it fits whatever you show it.
Five failure modes, with numbers
- Calibration overfit. GPTQ solves exact least squares on 128 sequences. "Quantization Hurts Reasoning?" (COLM 2025) quantized DeepSeek-R1-Distill-Qwen-1.5B to 3 bits: GPTQ calibrated on WikiText2 averaged 28.3 on reasoning benchmarks, calibrated on math data 38.1, BF16 48.7. AWQ, with no error feedback, moved only 1.8 points.
- Perplexity hides damage. The same study: 3-bit GPTQ dropped an 8B distilled Llama from 33.3 to 23.3 on AIME-120 and 49.5 to 39.1 on GPQA-Diamond. At 4 bits, roughly 0.4 to 3.9 points. Other work finds instruction following and hallucination detection degrading before perplexity moves.
- Outliers. Past about 6.7B parameters, a few hidden dimensions carry activations 10 to 100x larger, dominating
Hand wasting min-max grid levels. Act-order (quantize high-activation columns first) and group-wise scales exist mostly for this. Act-order isn't in the paper; it's in the reference repo. - Small models, low bits. At 3 bits OPT-125M goes from 27.65 to 53.85. Wider layers have more redundancy: the 3-bit gap shrinks from +6.3 at OPT-1.3B to +0.34 at OPT-175B.
- "Optimal" is local. Each step is optimal given earlier choices, but the whole is a greedy pass over an integer least-squares problem that is NP-hard in general. Better solvers exist.
What came after#
GPTQ's loop survived even as it was beaten. QuIP proved its LDLQ rounding equivalent to GPTQ's, then rotated weights with random orthogonal matrices so nothing dominates. QuIP# used a fast Hadamard transform and rounded groups of 8 weights onto the E8 lattice. On Llama-2-70B at 2 bits, OPTQ (GPTQ) scored 123.9 perplexity in QuIP's table and QuIP 6.33, against FP16 at 3.32. QuIP# later reached 3.91 against FP16 at 3.12, measured at a longer context, so the two tables don't compare directly. QTIP used trellis codes. Most keep error-feedback rounding as the inner step; what changed is what feeds it.
The question I'm left with#
Is the 1992 surgeon still earning its keep after rotation? QuaRot reports lossless 6- and 8-bit Llama-2 with RTN and no calibration, and OptRot argues RTN can occasionally beat GPTQ on suitably transformed weights. But most rotation papers use GPTQ as the final quantizer, so no one has separated rotation's gain from second-order rounding's. They interact: rotation changes H.
Next I'd like to rotate one real layer and compare RTN against GPTQ while sweeping input correlation like my toy, then test a 4-bit checkpoint when calibration text looks nothing like what users send. That second gap is the one I'd worry about in production.
My kernels are still in review: the torchao VNNI PR and the ONNX Runtime sub-byte DequantizeLinear PR are both open as I write. The Lean proofs that the fast paths match bit for bit are in lean-perf-proofs/torchao-da8w4-vnni and lean-perf-proofs/onnxruntime-subbyte-dequant. They cover what the kernels do with the 4-bit numbers, not whether those numbers were well chosen. That's GPTQ's job.
Sources#
- Frantar, Ashkboos, Hoefler, Alistarh. GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers. ICLR 2023.
- Frantar, Singh, Alistarh. Optimal Brain Compression (OBQ). NeurIPS 2022.
- Hassibi, Stork. Second Order Derivatives for Network Pruning: Optimal Brain Surgeon. NIPS 1992.
- Dettmers et al. LLM.int8(). NeurIPS 2022.
- Lin et al. AWQ. MLSys 2024.
- Chee et al. QuIP. NeurIPS 2023.
- Tseng et al. QuIP#. ICML 2024.
- Tseng et al. QTIP. NeurIPS 2024.
- Ashkboos et al. QuaRot. NeurIPS 2024.
- OptRot. 2025.
- Quantization Hurts Reasoning? An Empirical Study on Quantized Reasoning Models. COLM 2025.
- Lee et al. Exploring the Trade-Offs: Quantization Methods, Task Difficulty, and Model Size in LLMs. IJCAI 2025.
- IST-DASLab/gptq, the reference implementation (act-order lives here).