Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Explainers/Inference

What is quantization? Running AI models in 4 bits

Three papers on rounding model weights to 4 or 8 bits: why outliers break it, and how LLM.int8(), GPTQ and AWQ cope.

Derpx065 Oct · 7 min read
Contents
The idea in one sentenceHow it worksStep 1: what quantization isStep 2: why one outlier breaks itStep 3: the fix in LLM.int8(): set the outliers asideStep 4: group-wise quantizationStep 5: GPTQ: round with compensationStep 6: AWQ: protect the weights that matterWhat the papers foundWhat to be careful aboutSources
0% read · 7 min leftBack to top ↑
On this page0%
Contents
The idea in one sentenceHow it worksStep 1: what quantization isStep 2: why one outlier breaks itStep 3: the fix in LLM.int8(): set the outliers asideStep 4: group-wise quantizationStep 5: GPTQ: round with compensationStep 6: AWQ: protect the weights that matterWhat the papers foundWhat to be careful aboutSources

Large language models store billions of numbers, usually 16 bits each. Quantization stores each number with fewer bits, such as 8 or 4, so the model needs less memory and fits on fewer GPUs. The hard part is that a few unusual numbers can ruin the rounding for everything else. This article follows three papers that handle it in different ways.

Papers

LLM.int8(): Dettmers, Lewis, Belkada, Zettlemoyer, 2022. arxiv.org/abs/2208.07339. NeurIPS 2022.

GPTQ: Frantar, Ashkboos, Hoefler, Alistarh. ICLR 2023. arxiv.org/abs/2210.17323

AWQ: Lin, Tang, Tang, Yang, Chen, Wang, Xiao, Dang, Gan, Han. MLSys 2024. arxiv.org/abs/2306.00978

The idea in one sentence

Rounding numbers to a few levels is easy, but an outlier (a number much bigger than the rest) stretches the levels and ruins the small numbers, so good methods either set outliers aside, round with compensation, or protect the numbers that matter most.

How it works

Step 1: what quantization is

Quantization maps each number to the nearest of a small set of levels, and stores only the level's index. With 4 bits there are 16 levels. Reading the model back means multiplying the index by a step size.

The step size is the scale sss. In the common "absmax" form (used in LLM.int8() and AWQ) you set sss so the largest absolute value in the group lands on the top level. Toy example (made up, 4-bit with levels −7-7−7 to 777):

  • Numbers: −0.62, −0.21, 0.05, 0.18, 0.33, 0.71, −0.44, 0.09-0.62,\ -0.21,\ 0.05,\ 0.18,\ 0.33,\ 0.71,\ -0.44,\ 0.09−0.62, −0.21, 0.05, 0.18, 0.33, 0.71, −0.44, 0.09.
  • Largest absolute value is 0.710.710.71, so s=0.71/7≈0.101s = 0.71 / 7 \approx 0.101s=0.71/7≈0.101.
  • Divide each number by sss and round: −6, −2, 0, 2, 3, 7, −4, 1-6,\ -2,\ 0,\ 2,\ 3,\ 7,\ -4,\ 1−6, −2, 0, 2, 3, 7, −4, 1.
  • Read back by multiplying by sss: −0.61, −0.20, 0, 0.20, 0.30, 0.71, −0.41, 0.10-0.61,\ -0.20,\ 0,\ 0.20,\ 0.30,\ 0.71,\ -0.41,\ 0.10−0.61, −0.20, 0, 0.20, 0.30, 0.71, −0.41, 0.10. The biggest error is 0.05.

Some methods also use a zero-point zzz, a shift so that a range not centred on zero uses all the levels. LLM.int8() describes both forms. Toy example: numbers range from −0.24-0.24−0.24 to 0.960.960.96, with 16 levels (0 to 15). Then s=1.2/15=0.08s = 1.2 / 15 = 0.08s=1.2/15=0.08 and z=3z = 3z=3. The number 0.50.50.5 becomes round(0.5/0.08)+3=9\mathrm{round}(0.5 / 0.08) + 3 = 9round(0.5/0.08)+3=9, and reads back as 0.08×(9−3)=0.480.08 \times (9 - 3) = 0.480.08×(9−3)=0.48.

1Original number
2Divide by scale
3Round to nearest level
4Store small integer
5Multiply by scale to use

Step 2: why one outlier breaks it

Take the same list but replace 0.090.090.09 with an outlier 8.08.08.0 (toy example). Now s=8/7≈1.14s = 8 / 7 \approx 1.14s=8/7≈1.14. The numbers become: −1, 0, 0, 0, 0, 1, 0, 7-1,\ 0,\ 0,\ 0,\ 0,\ 1,\ 0,\ 7−1, 0, 0, 0, 0, 1, 0, 7. Six of the eight ordinary numbers now share only the levels −1-1−1, 000 and 111, and four of them are zero. The detail is gone.

NormalNo outlier: s about 0.10, the small numbers keep distinct levels
→
With outlierOne outlier at 8.0: s about 1.14, most small numbers round to 0

The LLM.int8() paper shows this happens in real models. Beyond about 6.7 billion parameters, some hidden-state dimensions get values up to 20 times larger than the others. At 6.7B these outliers sit in only 6 dimensions out of the whole network, yet they matter a lot: setting them to zero raised validation perplexity by 600 to 1000%, while removing the same number of random dimensions changed it by about 0.1%. (Perplexity is a score for how surprised the model is by real text. Lower is better.) Note that these outliers are in the activations (the values flowing through the model as it reads text), not in the stored weights.

Step 3: the fix in LLM.int8(): set the outliers aside

LLM.int8() has two parts:

  1. Vector-wise quantization: one scale per row of the input and per column of the weights, so an outlier only hurts its own row or column.
  2. Mixed-precision decomposition: the few dimensions with any value above a threshold of 6.0 (about 0.1% of dimensions) are multiplied in 16-bit. All the other values, more than 99.9%, are multiplied in 8-bit. The two results are added.

On C4 validation perplexity (Table 1), plain absmax 8-bit gets worse as models grow, while LLM.int8() matches full precision:

Model size32-bitInt8 absmaxLLM.int8()
6.7B13.3014.5913.24
13B12.4519.0812.45

Step 4: group-wise quantization

Another way to limit an outlier's damage is to give each small group of numbers its own scale. A group of 128 weights is common, written "g128". Toy example with groups of 4, using the outlier list from Step 2:

  • Group 1: −0.62, −0.21, 0.05, 0.18-0.62,\ -0.21,\ 0.05,\ 0.18−0.62, −0.21, 0.05, 0.18. Its own scale is 0.62/7≈0.0890.62 / 7 \approx 0.0890.62/7≈0.089, giving −7, −2, 1, 2-7,\ -2,\ 1,\ 2−7, −2, 1, 2. Fine detail survives.
  • Group 2: 0.33, 0.71, −0.44, 8.00.33,\ 0.71,\ -0.44,\ 8.00.33, 0.71, −0.44, 8.0. The outlier ruins only this group: the numbers become 0, 1, 0, 70,\ 1,\ 0,\ 70, 1, 0, 7.

The cost is that each group stores its own scale. GPTQ reports that groups of 128 cost about 0.15 extra bits per weight, and groups of 1024 cost about 0.02. In GPTQ's tests, groups of 128 moved the 4-bit and 3-bit results to within 0.1 to 0.3 perplexity of the uncompressed model on its largest models.

Step 5: GPTQ: round with compensation

GPTQ is post-training: it takes a finished model and needs no retraining. It works one layer at a time. For each layer with weights WWW, it tries to find quantized weights W^\hat{W}W^ that keep the layer's output close, meaning it minimizes ∥WX−W^X∥22\lVert WX - \hat{W}X \rVert_2^2∥WX−W^X∥22​ on a small sample of real inputs XXX.

It quantizes the columns of WWW in turn. After each column is rounded, the leftover error is spread over the columns not yet quantized, so they can compensate. This uses second-order information (how the error changes with each weight, from the inverse of a matrix called the Hessian built from the sample inputs). Two tricks (a fixed column order and batched updates) let it quantize a 175B model in about four GPU hours.

Column 1
Column 2
Column 3
Column 4

Round column 1 to the grid and measure the error

Step 1 of 6

Results on OPT-175B, WikiText2 perplexity (Table 3), where lower is better:

MethodBitsPerplexity
Full precision168.34
Round to nearest410.54
GPTQ48.37
Round to nearest37300
GPTQ38.68

Step 6: AWQ: protect the weights that matter

AWQ is also post-training and weight-only. Its first finding: keeping only 1% of weights in 16-bit greatly cuts the error, but only if you pick those weights by looking at the activations, not at the weights themselves. A weight that gets multiplied by large activations matters more. In its Table 1 (OPT-6.7B, 3-bit, groups of 128, WikiText perplexity), plain rounding gives 23.54. Keeping 1% in 16-bit chosen by activations gives 11.39. Chosen by weight size it gives 22.37, and chosen at random 24.23.

Mixed 16-bit and 3-bit storage is awkward on hardware. So AWQ instead multiplies the important weight channels by s>1s > 1s>1 before rounding, and divides the matching input by sss, which leaves the layer's output mathematically unchanged. A bigger weight takes up more of the grid, so its rounding error is smaller in comparison. With s=2s = 2s=2 on the important 1% of channels, perplexity falls from 23.54 to 11.92. A larger sss hurts the other channels, so AWQ searches for a good scale per channel on a small calibration sample.

Why 4-bit weights are faster: the AWQ paper observes that weight access dominates memory traffic on-device, so 4-bit weights cut it fourfold. Its TinyChat system reaches more than 3 times the speed of a Hugging Face FP16 setup.

What the papers found

LLaMA-2 7B, WikiText2 perplexity, groups of 128 (AWQ paper, Table 4; lower is better):

BitsRound to nearestGPTQAWQ
16 (baseline)5.475.475.47
45.735.695.60
36.666.436.24
  • At 4 bits with groups, all three cost little. At 3 bits the gap between plain rounding and smarter methods is clearer.
  • Perplexity is an average over ordinary text. It does not prove the model still does your task as well.

What to be careful about

  • These are three different tools. LLM.int8() quantizes both weights and activations to 8-bit. GPTQ and AWQ quantize only weights, to 3 or 4 bits. Do not mix their numbers.
  • GPTQ states two limits: it gives no speedup in the multiplication itself on mainstream hardware (it saves memory loading), and its results do not quantize activations.
  • LLM.int8() studies only Int8 and inference, not training.
  • GPTQ and AWQ both use a small calibration sample. AWQ argues that it overfits that sample less, because it uses no backpropagation or reconstruction.
  • Results are for the models tested (OPT, BLOOM, LLaMA). In GPTQ's tests plain rounding at 4 bits broke OPT-66B (perplexity 110 versus 9.34 at full precision), so odd cases exist.
Key takeaways
  • Quantization maps numbers to a few levels using a scale. One outlier forces a large scale and crushes the rest.
  • LLM.int8() found real outlier dimensions in activations from about 6.7B parameters and handles them in 16-bit.
  • Group-wise scales (for example 128 weights per group) keep an outlier's damage local, for about 0.15 extra bits per weight.
  • GPTQ rounds column by column and compensates the error. AWQ protects the weight channels that meet large activations. At 4 bits both stay close to full precision on the papers' tests.

Sources

  • Dettmers, Lewis, Belkada, Zettlemoyer. LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale, 2022.
  • Frantar, Ashkboos, Hoefler, Alistarh. GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers, ICLR 2023.
  • Lin, Tang, Tang, Yang, Chen, Wang, Xiao, Dang, Gan, Han. AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration, MLSys 2024.
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Retrieval · 7 minHow does vector search work? (HNSW explained)Inference · 6 minSpeculative decoding explained: making AI answer fasterLLM Systems · 7 minWhy do AI chatbots make things up?Distributed Systems · 7 minHow does Raft work? Getting computers to agree
Start here
01Why do AI chatbots make things up?02How does Raft work? Getting computers to agree03Mamba explained: an alternative to Transformers