Pidoku

GPTQ (2022)

Module 30 Lesson 30.i 40 min Difficulty 4/5

Prerequisites 10.l, 13.c, 30.h


Before you start: words you need#

WordPlain meaning
Post-training quantization (PTQ)Quantizing a model after training, with no (or very little) further training.
Weight-only quantizationOnly the weights are stored in low precision (here 3 or 4 bits); activations stay in 16-bit. Weights are expanded back to 16-bit inside the kernel.
Round-to-nearest (RTN)The simplest method: round every weight to the closest quantization level, independently.
Calibration dataA small set of real inputs (here 128 text samples) run through the model to see what activations each layer actually receives.
HessianHere: the matrix H = 2·X·Xᵀ built from a layer’s calibration inputs X. It tells you how much the layer’s output changes when weights change together.
Error compensationAfter rounding one weight, adjust the weights not yet rounded so the layer’s output moves back toward the original.
Cholesky decompositionA fast, numerically stable way to factor a symmetric positive-definite matrix, used here to get the needed parts of H⁻¹ once.
Group sizeHow many consecutive weights share one scale (and zero point). “g128” means one scale per 128 weights.

1. The paper#

  • Title: “GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers”
  • Authors: Elias Frantar, Saleh Ashkboos, Torsten Hoefler, Dan Alistarh (IST Austria, ETH Zurich, Neural Magic)
  • Venue: ICLR 2023 (arXiv October 2022).
  • Link: arXiv:2210.17323 · code: IST-DASLab/gptq

2. The problem#

LLM.int8() (30.h) halved memory but did not speed anything up. To run OPT-175B or BLOOM-176B on one GPU you need about 3–4 bits per weight. At that precision, plain round-to-nearest destroys large models: at 3 bits OPT-175B’s perplexity goes from 8.34 to over 7,000.

Better methods existed. Optimal Brain Quantization (OBQ, 2022) rounds weights one at a time and corrects the rest using second-order information. But its cost grows with the cube of the layer width; it took hours for a 100-million-parameter model, and would take years for 175 billion.


3. The idea#

Keep OBQ’s core: quantize a layer’s weights one column at a time, and after each step update the remaining columns to cancel the error just introduced, using the inverse Hessian. Then make it thousands of times faster with three changes:

  1. Arbitrary order. OBQ picks the “easiest” weight next, separately for each row. GPTQ shows that quantizing all rows in the same column order is almost as good for large layers. Now every row shares the same inverse-Hessian updates, so they can be done for the whole matrix at once.
  2. Lazy batch updates. Quantize a block of 128 columns, accumulate the corrections, and apply them to the rest of the matrix in one big matrix multiply. That turns memory-bound small updates into GPU-friendly GEMMs.
  3. Cholesky reformulation. Repeatedly updating H⁻¹ is numerically unstable at this scale. Compute a Cholesky factor of H⁻¹ once (with a little damping added to H) and read every needed row from it.
flowchart LR
  C["128 calibration samples"] --> H["Per layer: H = 2·X·Xᵀ, Cholesky of H⁻¹"]
  H --> B["Take next block of 128 columns"]
  B --> Q["Quantize one column, measure error"]
  Q --> U["Spread error to remaining columns in the block"]
  U --> Q
  U --> L["Block done: lazy update of all later columns (one GEMM)"]
  L --> B
  class C io
  class H,L compute
  class B,Q,U neutral

4. How it works#

The problem GPTQ solves, layer by layer, is:

find quantized Ŵ that minimises  || W·X − Ŵ·X ||²

— keep the layer’s output on real inputs as close as possible, not each weight. That is why it beats RTN: two weights can both be rounded “wrongly” in a way that cancels in the output.

Procedure, as in the paper’s Algorithm 1:

  1. Run the calibration data (128 random 2048-token segments from C4) through the model, layer by layer, using the already quantized earlier layers so errors do not compound unseen.
  2. For each linear layer, build H from its inputs, add damping (1% of the mean diagonal), and take the Cholesky factor of H⁻¹.
  3. Walk the columns left to right in blocks of 128: quantize a column, compute its error scaled by the Cholesky diagonal, subtract that error times the Cholesky row from the remaining columns of the block. After the block, apply the accumulated update to all later columns.
  4. Store integers plus per-group scales and zero points.

The paper also wrote a GPU kernel that multiplies a 3-bit or 4-bit weight matrix by a 16-bit vector, expanding weights to FP16 in registers. Decode is a matrix–vector product, memory-bound (30.a), so reading 4× fewer bytes means close to 4× faster, without quantizing activations.


5. Results#

Speed of quantization: OPT-175B and BLOOM-176B quantized in about 4 GPU hours on one 80 GB A100.

Quality (WikiText-2 perplexity; lower is better; Tables 3 and 5):

ModelFP16RTN 4-bitGPTQ 4-bitRTN 3-bitGPTQ 3-bit
OPT-13B10.1311.3210.313.4e311.61
OPT-175B8.3410.548.377.3e38.68
BLOOM-176B8.118.378.215718.64

At 4 bits GPTQ lost 0.03 perplexity on OPT-175B; RTN lost 2.2 points, worse than the full-precision 13B model. Groups (g128) helped further, especially at 3 bits.

Speed of inference (OPT-175B, 3-bit, batch 1, average per-token latency over 128 tokens, Table 6):

GPUFP16GPTQ 3-bitSpeed-upGPUs needed
A100 80 GB230 ms71 ms3.24×5 → 1
A6000 48 GB589 ms130 ms4.53×8 → 2

The paper notes its own limit: no speed-up for the multiplications themselves (no hardware support for mixed int-float matmuls then), and the gains are for small-batch generation.


6. What held up and what did not#

Held up

  • Layer-wise output reconstruction with second-order error compensation. It is the backbone of most accurate PTQ tools since. In 2026 llm-compressor (vLLM project) and GPTQModel still use GPTQ, and llm-compressor can apply the same algorithm when producing other formats (INT8, FP4) too.
  • Weight-only 4-bit for memory-bound decode. W4A16 (4-bit weights, 16-bit activations) became the standard way to serve on smaller GPUs, and the reason fast mixed-input kernels such as Marlin and Machete were written (25.g).
  • Calibrate in sequence, through already-quantized layers. Standard practice.

Did not, or changed

  • The original kernel was slow at large batch. Dequantize-then-multiply costs compute; once the batch grows, decode becomes compute-bound and the gain shrinks or reverses. Marlin (2024) fixed this up to moderate batch sizes.
  • “Act-order” (quantizing columns in order of decreasing Hessian diagonal, rather than left to right) was added later in community implementations to improve accuracy, with some kernel cost.
  • Pure GPTQ is sensitive to calibration data and can overfit it; AWQ (30.m) was in part a response.
  • At 3 bits and below, newer methods (rotation-based QuaRot/SpinQuant, 30.u; vector quantization such as AQLM and QTIP) beat it.
  • On Hopper and Blackwell, FP8 and NVFP4 with hardware support (13.e, 13.g) often replace INT4 weight-only quantization for high-throughput serving.

7. Where it lives in 2026#

  • Taught in depth: GPTQ and AWQ in 13.c, INT4 inference in 13.f, mixed-input kernels in 25.g, quantization in vLLM in 18.j.
  • vLLM loads GPTQ checkpoints and runs them with Marlin-family kernels (gptq_marlin) where the GPU supports them. Thousands of GPTQ checkpoints are on the Hugging Face Hub.
  • The original AutoGPTQ library is archived; GPTQModel is its maintained successor.

Checked on 13 November 2026.


8. Questions#

  1. What does GPTQ minimise for each layer, and why is that better than rounding each weight?
  2. What is the role of the Hessian H = 2·X·Xᵀ, and where does X come from?
  3. Name GPTQ’s three changes to OBQ and what each one buys.
  4. Why does a 4-bit weight-only kernel speed up batch-1 decode almost 4×, but not large-batch prefill?
  5. Why did the paper report latency for OPT-175B at 3 bits rather than throughput at batch 64?
  6. What is group size, and what does making groups smaller cost?
  7. When would you choose FP8 over GPTQ INT4 on an H100?

9. Further reading#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in