TL;DR
GPTQ stores a trained language model's weights with 3 or 4 bits each instead of 16, and it does this without any retraining. It works one layer at a time: it rounds one weight, then adjusts the weights that are not yet rounded so they cancel part of the damage, using a matrix built from 128 calibration segments of 2048 tokens each. The authors compressed the 175-billion-parameter OPT model in about four GPU hours on one A100, with almost no loss in perplexity.
Builds on: Quantization, Hessian Matrix, Cholesky Decomposition, Matrix Inverse, Linear Regression, Transformer · Leads to: Post-Training Quantization
Why it mattered
Before GPTQ, the accurate ways to shrink a network needed retraining, and the cheap way (rounding each weight to the nearest level) broke down at 3 bits on models this large. GPTQ showed that a careful one-shot method could handle models with hundreds of billions of parameters. The paper reports that OPT-175B fits on a single 80 GB A100 at 3 bits, where the FP16 version needs five such GPUs. The authors released a reference implementation.
The path to it ran through older work. Post-training quantization methods such as AdaRound were built for vision networks with millions of parameters. Optimal Brain Quantization (OBQ) gave a strong second-order method, but its cost was too high for language models. When open models with tens of billions of parameters appeared in 2022, practical work such as LLM.int8() used simple rounding, which the GPTQ authors showed fails at 3 bits. GPTQ was posted to arXiv in October 2022. It combines OBQ's error compensation with a fixed column order, lazy block updates and a Cholesky reformulation, which together make the method fast enough for 175-billion-parameter models.
The problem
A linear layer multiplies its input by a weight matrix . Quantization replaces each weight with a value from a small grid, for example the 16 levels of a 4-bit code. The obvious approach, round-to-nearest (RTN), ignores what the layer does with its inputs, so a weight can be rounded in the direction that hurts the outputs most.
The better methods look at the layer's output error. OBQ does this well, but its cost grows with the cube of the layer width. For a weight matrix with rows and columns it takes time proportional to , which is far too slow for a model with 175 billion weights.
Two things pull against each other. The layer's output error depends on the weights only through a matrix built from the inputs, the Hessian, so that is the right quantity to minimise. But a model with billions of weights leaves almost no time for per-weight linear algebra on that matrix.
How it works
Take one output row of a layer, with two weights and two sample inputs. The goal is to choose rounded weights that keep both outputs close to the originals. The inputs are summarised in a 2 by 2 matrix , and its inverse is computed once for the layer.
The toy setup: is the full-precision row, the grid is the integers (rounding means going to the nearest whole number), and the inverse Hessian is . Its inverse, the Hessian itself, is , and the layer's squared output error for a row with error is .
- Baseline: round every weight. RTN sends 0.6 to 1 and 0.6 to 1, giving . The layer's squared output error on the samples is 1.6.
- Quantize column 1 first. Round to 1. The error on this weight is . The weight is now fixed.
- Spread the error to column 2. Column 2 is still in full precision, so move it to cancel part of the damage. Compute , then move by . So becomes .
- Quantize column 2. Round to 0. The result is , and the squared error on the samples is 0.80. That is half the RTN error, on the same grid.
Step 3 is the whole method in miniature: rounding is not free, but part of its damage can be paid back by the weights still in full precision.
flowchart LR A["Layer weights and sample inputs"] --> B["Hessian H = 2 X X^T"] B --> C["Inverse, then Cholesky factor"] C --> D["For each column j in order"] D --> E["Round column j to the grid"] E --> F["Spread its error onto columns after j"] F --> D D --> G["Rounded layer"]
The paper's full procedure (its Algorithm 1) adds three ideas to the toy:
- Fixed order. OBQ picks the weight with the smallest error next, which differs per row. GPTQ goes through the columns in one fixed order for every row, so the same inverse serves all rows. The authors found this costs little accuracy on large layers.
- Lazy batches. Updates are applied to blocks of 128 columns at a time, so the GPU does large matrix operations instead of many small memory-bound ones. The updates to later columns are applied once per block.
- Cholesky form. On large matrices, round-off can make the inverse indefinite, which sends the updates in wrong directions. GPTQ computes the Cholesky factor of the inverse once per layer and reads the rows it needs from it. A small dampening term, 1 percent of the average diagonal value, is added to as a safeguard.
The calibration data is 128 random segments of 2048 tokens from the C4 web-text corpus. Layers are quantized in turn, and the inputs to each block come from the already-quantized blocks before it, so earlier errors are included in the calibration.
The math
Layer objective. Let be the weights of a linear layer, the matrix of sample inputs (one column per sample), and the quantized weights. The goal is
with every entry of restricted to the quantization grid. Working one output row at a time, the error of a candidate row is a quadratic form. With ,
Step 2 in symbols (the greedy update). Quantizing one weight to is ranked by , where is the diagonal entry for weight . The other unquantized weights, the set , then move by
Here is column of the inverse.
Step 3 in symbols (the toy numbers). Here and . The error is , so the move on weight 2 is
and , as in the walkthrough.
Block version. When a block of columns is quantized together, the move on the later weights is
where is the set of weights in the block. Only the block of the inverse is inverted, which is why this is cheap.
Runtime. Doing the updates weight by weight costs . The inverse depends only on the inputs, not on the weights, so it is updated once per column rather than once per weight. The total cost becomes , a saving of a factor over OBQ. For the very large layers of GPT-style models that difference is several orders of magnitude.
Results
The paper evaluates perplexity on WikiText-2 (lower is better), plus PTB and C4, and a set of zero-shot tasks. The main numbers for the two largest open models:
- Accuracy at 4 bits. On OPT-175B, GPTQ gives 8.37 against 8.34 for FP16 and 10.54 for RTN. On BLOOM-176B, GPTQ gives 8.21 against 8.11 for FP16 and 8.37 for RTN. RTN on the 175B model is worse than the 10 times smaller FP16 13B model (perplexity 10.13).
- Accuracy at 3 bits. RTN collapses on the large models (7.3e3 on OPT-175B). GPTQ gives 8.68 on OPT-175B and 8.64 on BLOOM-176B, and keeps reasonable perplexity across the OPT and BLOOM families.
- Grouping. Group size 128 brings OPT-175B at 3 bits to 8.45, about 0.1 from FP16, at a cost of about 0.15 extra bits per weight.
- Extreme regimes. At about 2.2 bits per weight (group size 128), the perplexity increase is under 1.5 points. Ternary weights with group size 8 reach 9.20 on OPT-175B.
- Speed. A 3-bit OPT-175B runs at 71 ms per token on one A100, against 230 ms for FP16 on five GPUs, a 3.24 times speedup. On two A6000 GPUs it runs at 130 ms against 589 ms for FP16 on eight GPUs, a 4.5 times latency reduction.
To read the 4-bit row as a number: the RTN gap to FP16 is perplexity points, and the GPTQ gap is points. The GPTQ increase is , about 0.36 percent. The stored weights are four times smaller than FP16 at 4 bits.
What the method does not do
- It is tempting to think GPTQ retrains the model. It runs no gradient steps: it does forward passes over calibration tokens to collect layer inputs, then solves a least-squares-style problem for each layer.
- It is tempting to think each weight should be rounded as close as possible to its original value. The error that matters is the output error, and a weight can be rounded in an apparently worse direction if the others compensate.
- It is tempting to think the greedy order is best. It is a heuristic. On the toy row, the rounding gives output error 0.40, which beats the 0.80 that GPTQ's fixed order reaches. The paper argues the order matters little on average for large layers, not that it is optimal.
- It is tempting to think 3-bit weights make the model three times faster. The speedup comes from moving fewer bytes, not from cheaper multiplications. The paper says its method does not yet speed up the multiplications themselves, because mainstream hardware lacks fast mixed-precision operands, and it quantizes weights only.
- Group size adds bits. A "3-bit" model with groups is slightly larger than three bits per weight.
The main limits: results cover perplexity and zero-shot tasks on OPT and BLOOM only, the C4 calibration data makes the C4 perplexity not fully zero-shot, and activation quantization is left to other techniques.
Reading guide
- Section 1, Introduction. Needs Transformer and Language Model for the setting, and Quantization for the goal.
- Section 2, Related work. Needs Post-Training Quantization to place the methods, and Pruning and Knowledge Distillation as the other compression families.
- Section 3, Background. Needs Linear Regression for the layer objective, Hessian Matrix for , and Matrix Inverse for the update. Read the OBQ equations with those in hand.
- Section 4, The GPTQ algorithm. Needs Cholesky Decomposition for the stable form of the inverse. Algorithm 1 gives the whole method as pseudocode.
- Section 5, Experiments. Needs Perplexity to read the tables, Floating-Point Numbers to see why 16 bits is the baseline, and GPU Memory Hierarchy to follow the speed argument.
Check yourself
QuestionWhy does GPTQ need the inverse Hessian rather than just the weights?Show answer
QuestionA layer has with entries and , and on the integer grid. Round with GPTQ's first step and find the new .Show answer
QuestionWhy does a fixed column order help GPTQ on large models, compared with OBQ's per-row greedy order?Show answer
QuestionA model has 175 billion weights. Compared with FP16, how many times smaller are the quantized weights at 3 bits, ignoring the embedding layers?Show answer
Sources
- Frantar, Ashkboos, Hoefler and Alistarh, "GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers", arXiv:2210.17323. https://arxiv.org/abs/2210.17323
- Reference implementation by the authors. https://github.com/IST-DASLab/gptq