TL;DR
SmoothQuant is a way to run a large language model with 8-bit integers for both the weights and the activations, which makes inference faster and halves memory use compared with 16-bit. It needs no retraining. A per-channel scale is computed once from a few calibration sentences, and it moves the hard part of quantization, large outliers in the activations, into the weights, where those outliers are easy to handle. The output of every matrix multiplication stays the same in exact arithmetic.
Builds on: Post-Training Quantization, Diagonal Matrix, Transformer · Leads to: AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration
Why it mattered
A 175-billion-parameter model needs about 350 GB to store in 16-bit floats, which is more than five 80 GB GPUs. Before SmoothQuant, the practical choices were to quantize only the weights, which saves memory but not compute, or to keep outlier channels in 16-bit, which is accurate but slow to run. SmoothQuant showed that a plain 8-bit integer matrix multiply can be used for every linear layer and attention product in models such as OPT, BLOOM, GLM, Llama and Mixtral. The paper reports up to 1.56 times faster inference and about 2 times less memory, and it fits the 530-billion-parameter MT-NLG model on a single 8-GPU node.
The problem
Quantizing a matrix means choosing a scale, so that the largest value in the group maps to the largest integer, and then rounding each value. With 8 bits there are 256 levels, so the scale sets how much precision each value gets. Two facts from the paper make this hard for activations:
- Weights are easy. The weight matrices of these models have a flat, uniform distribution. Quantizing them to 8 bits, and even to 4 bits, costs little accuracy.
- Activations have outliers. Past about 6.7 billion parameters, a few channels of the activations become about 100 times larger than typical values. Those channels stretch the scale. A non-outlier channel that should have about 256 levels ends up with only 2 or 3, and its rounding error is large.
Per-channel quantization, which gives each channel its own scale, solves this accuracy problem. But the paper notes that GEMM kernels on GPUs can only apply scales along the outer dimensions of a matrix multiplication, after the multiply. A per-channel scale on the activations would have to be applied inside the multiply, which those kernels do not support at speed. So existing 8-bit methods had to choose between accuracy and speed.
How it works
The walkthrough uses a tiny linear layer with 2 input channels, 2 output channels, and one example input, so every step can be checked by hand. The real method works the same way on each linear layer of a transformer.
- Write the layer. The layer computes Y = X W, where X is the activation matrix (tokens by input channels) and W is the weight matrix (input channels by output channels). Take X = [[10, 0.5]] (one token, two channels) and W = [[0.2, 0.1], [0.4, 0.3]]. Then Y = [10 times 0.2 + 0.5 times 0.4, 10 times 0.1 + 0.5 times 0.3] = [2.2, 1.15]. Check: the first output is 2 + 0.2 = 2.2.
- See the problem. Channel 1 of X has max magnitude 10, and channel 2 has max magnitude 0.5. A single 8-bit scale for the whole activation tensor would be set by 10, so channel 2's value 0.5 is represented with about 0.5 divided by 10 times 127, which is about 6 levels. Check: 0.5 / 10 = 0.05, and 0.05 times 127 is about 6.4.
- Pick a smoothing factor per channel. Choose s_j for each input channel j. Divide the activation channel by s_j and multiply the matching weight row by s_j. The paper's rule is s_j = max|X_j|^alpha / max|W_j|^(1 - alpha), with alpha = 0.5 as the default. For channel 1: max|X_1| = 10 and max|W_1| (row 1 of W) = 0.2, so s_1 = sqrt(10) / sqrt(0.2) = sqrt(50) = 7.07. For channel 2: max|X_2| = 0.5 and max|W_2| = 0.4, so s_2 = sqrt(0.5) / sqrt(0.4) = sqrt(1.25) = 1.12. Check: channel 1 is now scaled down by 7.07, and channel 2 by 1.12, so the two channels end up with similar sizes.
- Apply the factors. The new activation is X_hat = X diag(s)^(-1) = [10 / 7.07, 0.5 / 1.12] = [1.41, 0.45]. The new weight is W_hat = diag(s) W, so row 1 becomes 7.07 times [0.2, 0.1] = [1.41, 0.71], and row 2 becomes 1.12 times [0.4, 0.3] = [0.45, 0.34]. Check: the product X_hat times W_hat should equal Y.
- Confirm the output is unchanged. First output: 1.41 times 1.41 + 0.45 times 0.45 = 1.99 + 0.20 = 2.19, which matches 2.2 up to rounding. Second: 1.41 times 0.71 + 0.45 times 0.34 = 1.00 + 0.15 = 1.15. So the layer computes the same answer. Check: the rounding is only from the two-digit decimals used here.
- Quantize. Both X_hat and W_hat now have channel magnitudes near 1.4 and 0.45, which are much closer than 10 and 0.5. Quantize each with an 8-bit integer scale and run an INT8 matrix multiply, which the GPU kernels support.
The smoothing factors are computed once, offline, from calibration sentences. At run time the division by s is folded into the previous layer's weights, so there is no extra work per token.
flowchart LR A["Calibration sentences"] --> B["Measure max of each activation channel and each weight row"] B --> C["Compute s_j with alpha = 0.5"] C --> D["Fold 1 over s into previous layer; multiply weight rows by s"] D --> E["Quantize activations and weights to INT8"] E --> F["INT8 matrix multiply on GPU"]
The math
Let X in R^(T by C_i) be an activation matrix with T tokens and C_i input channels. Let W in R^(C_i by C_o) be a weight matrix. A linear layer computes Y = X W. A per-channel smoothing vector s in R^(C_i) with positive entries leaves the product unchanged when applied in the reverse direction to the two factors:
Here diag(s) is the diagonal matrix whose entries are s, and diag(s)^(-1) divides each channel by its scale. Each column of X is divided by one entry of s, and each row of W is multiplied by the same entry. The two changes cancel exactly.
Step 3 in symbols: choosing s
Quantization error for a channel is smallest when its maximum magnitude is close to that of the other channels, because then every channel uses a similar number of levels. The paper picks s_j to balance the two factors' maxima. With the migration strength alpha between 0 and 1:
Here max|X_j| is the largest activation magnitude in channel j over the calibration data, and max|W_j| is the largest weight magnitude in row j of W. After smoothing, the scaled activation channel has maximum max|X_j| / s_j, and the scaled weight row has maximum s_j max|W_j|. With alpha = 0.5, both become sqrt(max|X_j| max|W_j|), so they are equal.
Step 4 in symbols: the rounding error
For a symmetric 8-bit quantizer with maximum m, the step size is m / 127 and the rounding error is at most half a step. A channel with maximum m_j therefore has error about m_j / 254. The method reduces the activation channels' maxima and raises the weights' maxima by the same factor, so the error budget is shared between the two sides instead of falling entirely on the activations.
Worked example: the layer from the walkthrough
Take alpha = 0.5 and the numbers from step 3. Under one per-tensor 8-bit scale, the step size is set by the largest channel. Before smoothing that is 10 / 127 = 0.079 for channel 1 and 0.5 / 127 = 0.0039 for channel 2, so the two channels differ by a factor of 20 and the small channel gets few levels. After smoothing the maxima are 1.41 and 0.45, so the steps are 1.41 / 127 = 0.0111 and 0.45 / 127 = 0.0035. The factor between channels drops to about 3. The small channel now uses a step of 0.0111 for its value 0.447, which is about 40 levels, where before its value 0.5 got about 6.
Results
The paper evaluates OPT, BLOOM and GLM models on seven zero-shot tasks including LAMBADA, then MT-NLG 530B, and later adds LLaMA-family, Falcon, Mistral and Mixtral models.
- Accuracy. On OPT-175B, SmoothQuant W8A8 stays close to the 16-bit model on every evaluation dataset; its average over the seven tasks is 66.4 to 66.8 against 66.9 for FP16. The W8A8 baseline, ZeroQuant and Outlier Suppression give nearly random results on that model, which shows that naive 8-bit activation quantization breaks at this scale. LLM.int8() matches accuracy by keeping outliers in 16-bit, at a latency cost.
- Perplexity. On LLaMA-7B, WikiText-2 perplexity (the paper's Table 6) is 11.51 for the 16-bit model and 11.56 for W8A8 SmoothQuant. Lower perplexity is better, so the gap is small.
- Speed in PyTorch. On one A100 80 GB GPU, SmoothQuant-O3 reaches up to 1.51 times speedup and 1.96 times memory saving for OPT models. LLM.int8() is slower than FP16 in most cases.
- Speed in FasterTransformer. Up to 1.56 times lower latency than the FP16 FasterTransformer baseline on OPT-13B and OPT-30B.
- Scale. MT-NLG 530B quantizes to W8A8 with negligible loss. Serving it needs 8 GPUs instead of 16, at similar latency, so a model over 500 billion parameters fits in one node of 8 A100 80 GB GPUs.
- Migration strength. Accuracy is good for alpha between 0.4 and 0.6. Below 0.4 the activations are hard to quantize; above 0.6 the weights are. The paper uses 0.5 for most models and a larger value, such as 0.75, for GLM-130B, which has more outliers.
Limits. The method targets activation outliers in channels, and the paper's tests cover the models listed above. The calibration step depends on a sample of text, so the scales are only as good as that sample. The speedups are measured on specific GPUs and frameworks. Appendix A discusses weight-only quantization, which the paper treats as a different trade-off.
Reading guide
- Abstract and Section 1 (Introduction). The memory argument and the outlier problem. Needs Post-Training Quantization and Quantization.
- Section 2 (Preliminaries). Matrix multiplication with scales and the INT8 kernel setup. Needs Matrix Multiplication and Floating-Point Numbers.
- Section 3 (Review of quantization difficulty). The three observations about outliers. The per-channel argument relies on Diagonal Matrix. Compare with LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale, which handles the same outliers by mixed precision.
- Section 4 (SmoothQuant). The equivalence and the formula for s. This is the core of "The math" above. Needs Transformer, since the method is applied to attention and feed-forward layers, and Layer Normalization, since the scale is folded into the layer before it.
- Section 5 (Experiments). Tables for accuracy, speed and memory. Needs GPU Memory Hierarchy to read the latency numbers.
- Section 6 (Related work). Other low-bit methods, such as GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transfor..., which quantizes weights only.
Check yourself
QuestionRecall: in one sentence, what does SmoothQuant move from the activations into the weights, and why is that helpful?Show answer
It moves the outlier scale from the activation channels into the weight rows, using a per-channel factor s that is divided out of the activations and multiplied into the weights. Weights are already easy to quantize, so the extra difficulty is cheap to absorb, and the activations become easy enough for an 8-bit integer multiply.
QuestionComputation: an activation channel has max magnitude 16 and the matching weight row has max magnitude 1. With alpha = 0.5, what is s_j, and what are the new maxima of the activation channel and the weight row?Show answer
s_j = 16^0.5 / 1^0.5 = 4 / 1 = 4. The activation channel's new maximum is 16 / 4 = 4. The weight row's new maximum is 4 times 1 = 4. Both are 4, so they now share the same quantization difficulty.
QuestionWhy: why does the paper choose alpha around 0.5 for most models, and what happens if alpha is too small or too large?Show answer
With alpha = 0.5 the activation and weight maxima end up equal, which splits the quantization difficulty evenly between the two sides when both use the same kind of quantizer. If alpha is too small (below about 0.4), the activations keep most of their outliers and are hard to quantize. If alpha is too large (above about 0.6), the weights absorb too much and become hard to quantize. Models with stronger outliers, such as GLM-130B, use a larger alpha to move more difficulty to the weights.
QuestionApplied: a team wants to serve a 175 billion parameter model on GPUs with 80 GB each. They ask whether SmoothQuant alone lets them fit it on fewer GPUs. Explain using the paper's numbers.Show answer
Storing 175 billion parameters in 16 bits needs about 350 GB, so at least five 80 GB GPUs are needed. With 8-bit weights the storage halves to about 175 GB, which needs about three 80 GB GPUs, though the activations and the key-value cache also need memory. The paper reports about 2 times memory saving in its measurements, and on MT-NLG 530B it halves the number of GPUs at similar latency. The team should measure their own setup, since the paper's speedups depend on the GPU and framework.
Sources
- Xiao, Lin, Seznec, Wu, Demouth, Han. "SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models." arXiv:2211.10438 (2022). https://arxiv.org/abs/2211.10438
- https://doi.org/10.48550/arXiv.2211.10438