Shows that large transformers develop a few activation feature dimensions with very large values, which ruin 8-bit quantization with a shared scale; uses vector-wise scales and keeps those outlier dimensions in 16-bit (NeurIPS 2022).
Quantization: Compressing Models to Integers
Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.
Intuition
The idea in plain words, before the symbols.
When a large model generates text one token at a time for a small batch, each step reads every weight from memory but does only a little arithmetic per byte read. Speed is then limited by memory bandwidth, not by arithmetic, and moving fewer bytes can raise throughput, though the actual speedup depends on the kernels, the hardware, the batch size and which tensors are quantized.
Quantization stores weights, and sometimes activations, as low-bit integers such as INT8 or INT4, with a scale factor that maps the integers back to approximate floating-point values. Memory falls in proportion to the bits: a 70-billion-parameter model needs about 140 GB for 16-bit weights, 70 GB at 8 bits and 35 GB at 4 bits, before the scales, the activations and the KV cache are counted.
A central difficulty, especially for large language models, is outliers: a few large weights or activations force a large scale, which leaves too few integer levels for all the ordinary values (Dettmers et al., 2022).
Study prompts for this section: Intuition
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Mathematics
Definitions, assumptions and the derivation.
Uniform quantization (per-tensor)
Given a tensor of weights with minimum and maximum , choose one step size for the whole tensor and round onto integer levels:
Here is the number of bits (8 for INT8, 4 for INT4), an integer from 1 to 16 in the code below, and and are the smallest and largest entries of a nonempty tensor of finite float32 values. This is an asymmetric (min–max) quantizer: the offset shifts the range, so integer level stands for and level for . Integer-only schemes round the offset to an integer zero point and write , so that the real value 0 is represented exactly (Jacob et al., 2018).
When every entry is equal (a single value, or a row of zeros), and the quotient would be . One level is then enough: and reproduce the tensor exactly. This branch is a definition chosen for that case, not a measured result.
The code below computes this definition in floating point. Three details matter:
- Rounding. It computes the quotient in float64 and rounds it to the nearest integer, sending exact halves to the even integer, as
np.rounddoes. That rounds the computed quotient, which is not always the exact real one. At , the float32 entries give a computed quotient of exactly for the middle entry, so it goes to level (), although the exact nearest level is (). - Endpoints. It keeps every reconstructed level inside and sets the top level to exactly. Without that step, for , where is the largest float32, the sum loses the to cancellation.
- Underflow. The final conversion to float32 rounds to nearest, which can turn a tiny level into a subnormal number or zero. This narrowing is the only step where the code allows floating-point underflow.
Finer-grained scaling: per-channel / row-wise
Instead of one scale for the whole matrix, use one scale per output channel/row. For signed symmetric quantization:
This usually improves quality because different channels have different ranges of values. Here must be an integer with : at , and there is no nonzero level, which is narrower than the affine rule's . Symmetric quantization keeps the real value 0 at integer level and uses the levels , leaving unused. An all-zero row has ; by the same convention as above, and exactly, with no division.
The two formulas are different quantizers, not two spellings of one. At , the tensor reconstructs as under the affine rule and as under the symmetric one. Dettmers et al. (2022) describe both families for 8-bit inference, absmax (symmetric) and zeropoint (asymmetric) quantization; these formulas are teaching versions, not the whole LLM.int8() method.
Clipping and rounding
A scale can cause two different errors. A value whose rounded code falls outside is clipped: it is reconstructed at the end of the range, however far beyond the range it lies. A value inside the range is rounded to the nearest level, so it is off by at most half a step, . The absmax scale above never clips, because the largest magnitude maps exactly to ; the price is that one large value sets the step for every other value that shares its scale. A smaller scale, such as one chosen before an outlier is seen, keeps a fine step for the ordinary values and clips the outlier instead. The practice after the demo works through both errors on a example.
Per-row scales let each row pay only for its own range. When every row has the same largest magnitude, each row's absmax scale equals the shared one, so per-row and shared scales give the same result. Group-wise scales, described next, can still help then. If both rows are , both row scales are and the root-mean-square error is ; with one scale for each group of two weights, and , it falls to .
Group-wise scales
At 4 bits even one scale per row is often too coarse. Group-wise quantization splits each row into groups of consecutive weights, commonly 64 or 128, and gives each group its own scale. The scales cost memory too: a 16-bit scale for every 128 weights adds bits per weight, so a "4-bit" model stores about 4.125 bits per weight, or more if each group also has a zero point.
Beyond rounding: GPTQ, AWQ and SmoothQuant
Rounding each weight to its nearest level is the simplest choice, not the most accurate one. Three widely used methods for large language models do better with a little calibration data:
- GPTQ (Frantar et al., 2023) quantizes a layer's weights one column at a time, aiming to keep the layer's outputs on calibration inputs (one column per calibration token) close to the original, . After each column it adjusts the columns not yet quantized to compensate for the rounding error, using approximate second-order information (the inverse of ). It brought 175-billion-parameter models to 3–4 bits per weight in about four GPU hours.
- AWQ (Lin et al., 2024) quantizes weights only. It observes that about 1% of weight channels matter most, and that they are the ones multiplying large activations, not the ones with the largest weights. It scales those channels up before quantization and divides the matching activations by the same factor, which leaves the product unchanged but reduces their relative rounding error. The scales are chosen from calibration activations, without backpropagation.
- SmoothQuant (Xiao et al., 2023) targets 8-bit weights and activations. Activation outliers sit in a few channels, which makes activations hard to quantize while weights are easy. Writing the layer as , with one row of per token and one column per input channel , it moves part of the difficulty into the weights with an equivalent rescaling, , where and is the default balance.
Study prompts for this section: Mathematics
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Code
The same calculation as runnable code, in the notation of the derivation.
import numpy as np
rng = np.random.default_rng(0)
w = rng.normal(size=10000).astype(np.float32)
def quantize_uniform(w, bits=8):
# Affine min-max quantization. Domain: w is a nonempty float32 ndarray (ndim >= 1)
# of finite values, never converted or modified; bits is an int or NumPy integer
# from 1 to 16, not a bool. Returns int32 levels, float delta, float32 reconstruction.
if type(w) is not np.ndarray or w.dtype != np.float32:
raise TypeError("w must be a float32 ndarray")
if w.ndim == 0 or w.size == 0 or not np.isfinite(w).all():
raise ValueError("w must be nonempty, at least 1-D and finite")
if isinstance(bits, bool) or not isinstance(bits, (int, np.integer)):
raise TypeError("bits must be an integer")
if not 1 <= bits <= 16:
raise ValueError("bits must be from 1 to 16")
qmax = 2 ** int(bits) - 1
wmin, wmax = float(w.min()), float(w.max()) # exact: every float32 is a float64
if wmin == wmax: # zero range: Delta = 0, every entry at level 0, exact reconstruction
return np.zeros(w.shape, dtype=np.int32), 0.0, w.copy()
delta = (wmax - wmin) / qmax
x = w.astype(np.float64) # widen the array itself before any arithmetic
wq = np.clip(np.round((x - wmin) / delta), 0, qmax).astype(np.int32)
level = np.clip(wq * delta + wmin, wmin, wmax) # stay inside [wmin, wmax]
level[wq == qmax] = wmax # the top level is wmax exactly, even after cancellation
with np.errstate(under="ignore"): # only this float64 -> float32 narrowing may underflow
what = level.astype(np.float32)
return wq, delta, what
q8, d8, what8 = quantize_uniform(w, bits=8)
q4, d4, what4 = quantize_uniform(w, bits=4)
print("RMSE INT8:", round(float(np.sqrt(((w - what8) ** 2).mean())), 6), "delta:", round(d8, 6))
print("RMSE INT4:", round(float(np.sqrt(((w - what4) ** 2).mean())), 6), "delta:", round(d4, 6))
print("memory reduction: fp16->int8 ~2x, fp16->int4 ~4x (weight storage)")
q, d, what = quantize_uniform(np.array([3.0, 3.0, 3.0], dtype=np.float32), bits=4)
print("constant input: q", q.tolist(), "delta", d, "w_hat", what.tolist())
q, d, what = quantize_uniform(np.array([0.0, 0.5, 1.5, 2.5, 3.0], dtype=np.float32), bits=2)
print("halves round to even: q", q.tolist(), "delta", d)
Study prompts for this section: Code
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Demo
Change an input, predict the result, and see which quantities respond.
Explore Quantization: Compressing Models to Integers
Observation guide
Optional and ungraded. Opening a guide saves nothing.
Choose what to inspect in Quantization: Compressing Models to Integers, then open its guide.
The demo below asks you to predict which scaling strategy copes with an outlier before it shows the quantization error. The point is that a single shared scale can spend most integer levels on one large value, while per-channel scales recover resolution for the ordinary rows.
The demo uses the signed symmetric formula, with one absmax scale for the whole matrix or one per row; it does not run the affine code above. Its fixed 4×8 matrix never contains an all-zero row, so the branch is not reached there, and its byte counts cover the stored integers only, not the scales.
Study prompts for this section: Demo
Each button copies a prompt about this section to your clipboard, for an AI assistant you already use. Nothing is sent by this site.
Practice
Quantize eight weights with three choices of 4-bit scale and find which error each makes, clipping or rounding. Then change one weight and compare again.
Concept: Quantization: Compressing Models to Integers
What is the smallest example of Quantization you can work through by hand, and what does it show?
DetailsEfficiency
Reference id
concept:efficiency/quantizationAfter the first pass
Go deeper
Optional material for a second reading. Sources are always shown; the other panels open from their headings or from these links, and closing one keeps what you wrote or revealed.What to look for in each sectionChoose a section and what you expect to see in it, then read short advice.
Section by section
Choose what to look for in each section
Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.

Start with the picture, metaphor, or geometric mechanism.
Choose what you expect to see in this section of Quantization: Compressing Models to Integers.
Questions to ask of the pictureChoose a part of the picture and what you expect, then read short advice.
Looking at the picture
Questions to ask of the picture
Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.
Which part of the picture should you look at first?
Pick the part of the picture you expect to explain Quantization: Compressing Models to Integers.
Sources
References for this page
A reference shows where an idea comes from; it does not vouch for every step on this page.Quantizes each layer's weights one column at a time, updating the remaining columns to compensate for rounding error with approximate second-order information; 175B-parameter models reach 3–4 bits in about four GPU hours (ICLR 2023).
Finds that about 1% of weight channels matter most and that they are identified by activation size, then scales those channels up before low-bit weight-only quantization, without backpropagation (MLSys 2024).
Moves quantization difficulty from activations, which have outlier channels, to weights with an equivalent per-channel rescaling, so both can be stored in 8 bits (ICML 2023).
Defines the affine scheme r = S(q − Z), with a real-valued scale S and an integer zero point Z, and trains with simulated quantization so inference can run in integer arithmetic (CVPR 2018).
What each claim rests on1 claim, each with its sources, where it appears on this page, and its caveats.
Claims and sources
Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.
The checks were made by this site, not by an independent reviewer.
Dettmers et al. show transformer-scale 8-bit inference needs separate normalization constants and mixed-precision handling for emergent outlier features. Frantar et al. support post-training weight quantizat...
This covers uniform quantization with scales and the effect of outliers. The page describes GPTQ, AWQ and SmoothQuant in words but does not implement them, and it reports no model accuracy or hardware speedup.
Dettmers et al. support 8-bit scaling and dequantization, the loss of precision when one scale must cover an outlier, vector-wise scales, and keeping outlier dimensions in higher precision. Frantar et al. support low-bit weight quantization of GPT models that controls the reconstruction error and reduces memory movement.
Explain it without the pageWrite your own explanation before asking for feedback. Your draft and any hints stay while this page is open.
Practice · Quantization: Compressing Models to Integers
Try the idea in your own words
Reduce memory and bandwidth by storing weights/activations in low-bit integers (INT8/INT4) with careful scaling to limit accuracy loss.
Concept · Selected for practice
Quantization: Compressing Models to Integers
What it rests on: Sources: LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale; GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Tr...
Context and links
Efficiency
Explain the mechanism
For Quantization: Compressing Models to Integers: What is the smallest example of Quantization you can work through by hand, and what does it show? Explain your answer, including what changes, why, and which assumption matters.
A rough first thought is enough. Your draft stays when you change tasks.
Your draft stays on this page and is cleared when you leave or reload.
A little help · Explain
Open one hint at a time. These are suggestions, not your answer or a grade.
0 of 3 hints shown for this question.
Clearing your answer keeps this help record. Outside help is your own report; this page cannot check it.
Where am I stuck? (optional)
Take your draft to a feedback conversation
No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.
Write an attempt before copying a feedback prompt.
A draft, or an AI reply to it, is not a test of what you have learned. To check that, try a different case later without help.
Ask about this pagePick one item on this page and copy a prompt about it into an AI assistant you already use. Notes you write here stay in this browser.
rng = np.random.default_rng(0)Your question
Choose what your question is about
Pick the idea, equation, source, code, claim, misconception or demo state you want to ask about. The prompt you copy includes it, so the answer can stay on that item.Open the draft below to save one note and next action in this browser.
Quantization: Compressing Models to Integers
What is the smallest example of Quantization you can work through by hand, and what does it show?
Fixed prompts generated from this item. They are not comments from people or independent reviews.
The 5 cited sources must support this exact item, not just the surrounding topic.
Connect the definition to one equation, piece of code or demo before widening the discussion.
Change one input, then check that the same relationship holds in the mathematics, the code and the demo.
You can state the mechanism in your own words
Local action draftNo local draft saved yetOpen when you are ready to write one next action
This draft stays in this browser and is attached to this item only.
- What the 5 cited sources say about this exact item
- The definition, its prerequisites, and a contrasting concept
- The equation or code that makes the concept concrete
- One demo state that shows what stays the same as the inputs change
- You can state the mechanism in your own words
- You can name the prerequisite that would clear up the confusion
- You can predict how the result changes when one input changes
Reference id
concept/concept-notebook/efficiency/quantization
concept:efficiency/quantization