← Back to all chapters

Chapter 31Down the Rabbit Hole: How GPTQ Rounds a 175B Model to 3 Bits Without Breaking It

8 min read
quantizationllm-inferencerabbit-holedeep-learning

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.

  • FP169.34
  • RTN 4-bit110
  • GPTQ 4-bit9.55
OPT-66B WikiText2 perplexity (lower is better): FP16, round-to-nearest at 4 bits, GPTQ at 4 bits.

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).

  • A100 FP16230 ms
  • A100 3-bit71 ms
  • A6000 FP16589 ms
  • A6000 3-bit130 ms
Milliseconds per token for OPT-175B: FP16 vs the paper's 3-bit kernel, on two GPUs.

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.

StrategyAnaBenCleoTotal
Round each alone$0.50$0.50$0$1.00 (50 cents too much)
In order, pass the leftover$0.50about $0.11, rounds to $0$0$0.50 (exact)
start1: round w12: w2 to 0.1143: round to 000.500.5w1w2dashed: plain roundingRTN [0.5, 0.5]loss 0.19GPTQ [0.5, 0]loss 0.02
Schematic of the three-friends row in weight space, inputs 90% correlated. The shaded valley is an illustrative equal-loss contour: sliding along it barely moves the output.

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.

1/4Start
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.

GPTQ on one row, w = [0.30, 0.30, -0.10], grid step 0.5. Step through.

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.

GPTQ's three changes. Click a box.
weight matrix, columns quantized left to right128 columnseager updateslaterlaterlaterone matmul pushes the block's errors right
Lazy batches, schematic. Inside the active 128-column block, updates are eager; the rest of the matrix gets one matrix multiply per block.
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 Q

The 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 correlationBitsRTNGPTQRatio
0.940.01460.00285.2x
0.930.06470.01384.7x
0.040.01460.01381.1x
0.030.06410.06031.1x
  • corr 0.9, 4-bit5.2x
  • corr 0.9, 3-bit4.7x
  • corr 0, 4-bit1.1x
  • corr 0, 3-bit1.1x
Toy layer: how many times smaller GPTQ's output error is than RTN's (the Ratio column). Correlation is the fuel.

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 H and 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#

© 2026 Bharat Kaurav. Built with Next.js & Tailwind.

>_ bk@netherwatcheresc to close

Welcome, reader. Type help to see what this shell can do.