VerifiedarXiv:2211.1043823 min
Quantization · LLM inference

SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models

A few huge activation channels break 8-bit quantization of large language models. An exact rescale moves that range into the weights, which quantize cleanly.

SmoothQuant divides each input channel of a linear layer's activations by a factor and multiplies the matching weight row by the same factor. The layer computes the same output, both tensors now fit 8 bits, and every matmul runs on INT8 hardware, with no retraining.

Explaining the paperSmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language ModelsXiao, Lin, Seznec, Wu, Demouth, Han · MIT · NVIDIA · ICML 2023 · arXiv:2211.10438 ↗

Naive INT8 drops OPT-175B from 66.9% to 35.5% average zero-shot accuracy. After SmoothQuant's rescale it scores 66.8%, runs on half the GPUs, and the 530-billion-parameter MT-NLG fits in one 8-GPU server.

GPT-3 has 175 billion parameters. Stored in FP16 (16-bit floating point, the usual serving format) that is at least 350 GB, which takes eight 48 GB A6000 GPUs or five 80 GB A100s for inference alone. The paper starts from that memory cost: holding the weights, and moving them from memory to the compute units for every token.

Quantization stores numbers in fewer bits. Going from FP16 to 8-bit integers (INT8) halves the bytes, so the same GPU holds twice the parameters and reads each one in half the time. An NVIDIA A100 also multiplies INT8 matrices at twice the FP16 rate: 624 trillion INT8 operations per second against 312 trillion FP16, both dense, with no sparsity. That 2× is a hardware peak; the speedups SmoothQuant measures end to end are 1.51× and 1.56×.

SmoothQuant, by Guangxuan Xiao, Ji Lin, Mickael Seznec, Hao Wu, Julien Demouth and Song Han (MIT and NVIDIA, posted November 2022, ICML 2023), gets INT8 working for both the weights and the activations of models up to 530 billion parameters. It is post-training quantization: no fine-tuning and no gradient steps, only one calibration pass and an offline rewrite of the weights. The page builds it in order: what the integer matmul requires, how the INT8 quantizer works, why a few activation channels break it, why the obvious per-channel fix cannot run on the hardware, the rescale that gets around this, how much to rescale, and why the rescale costs nothing at runtime.

Why INT8 needs both weights and activations

A linear layer, the operation that holds most of the parameters and compute in a Transformer block, multiplies an activation matrix by a weight matrix:

Y=XW,X∈RT×Ci,  W∈RCi×Co\mathbf{Y} = \mathbf{X}\mathbf{W}, \quad \mathbf{X}\in\mathbb{R}^{T\times C_i},\ \ \mathbf{W}\in\mathbb{R}^{C_i\times C_o}Y=XW,X∈RT×Ci,  W∈RCi×Co\begin{gathered}\mathbf{Y} = \mathbf{X}\mathbf{W}, \\ \mathbf{X}\in\mathbb{R}^{T\times C_i},\ \ \mathbf{W}\in\mathbb{R}^{C_i\times C_o}\end{gathered}

TT is the number of tokens, CiC_i the number of input channels (the width of each token's vector) and CoC_o the number of output channels, so Y\mathbf{Y} is T×CoT\times C_o. For a 12,288-wide model like OPT-175B, the query projection of 4 tokens is a 4×122884\times 12288 activation times a 12288×1228812288\times 12288 weight. Each output entry is a sum over the shared input-channel axis:

Yt,o=∑j=1CiXt,j Wj,oY_{t,o} = \sum_{j=1}^{C_i} X_{t,j}\,W_{j,o}

That summation axis CiC_i decides which quantization schemes the hardware can run, as the section on per-channel scales shows.

There are two ways to quantize this layer. W8A16 stores the weights in INT8 and keeps the activations in FP16. It halves weight memory, which speeds up generating one token at a time, where the GPU spends most of its time reading weights. The multiply itself does not change: the INT8 weights are converted back to FP16 and the product runs on the FP16 units at the FP16 rate. W8A8 puts both operands in INT8, so the product runs as an INT8 GEMM (general matrix multiply) on the integer units. Only W8A8 gets both the memory saving and the faster matmul, and it requires the activations to survive 8 bits. In models above a few billion parameters, the weights survive and the activations do not.

How INT8 quantization works

A quantizer maps each real number to the nearest point on an evenly spaced grid. For symmetric INT8 the grid is the integers from −127-127 to +127+127, multiplied by a step size Δ\Delta. The paper uses this restricted range (it drops −128-128 so the codes are symmetric about zero) and sets the step from the largest magnitude in the tensor:

XˉINT8=⌈XFP16Δ⌋,Δ=max⁡(∣X∣)2N−1−1\bar{\mathbf{X}}^{\text{INT8}} = \left\lceil \frac{\mathbf{X}^{\text{FP16}}}{\Delta} \right\rfloor, \qquad \Delta = \frac{\max(|\mathbf{X}|)}{2^{N-1}-1}XˉINT8=⌈XFP16Δ⌋,Δ=max⁡(∣X∣)2N−1−1\begin{gathered}\bar{\mathbf{X}}^{\text{INT8}} = \left\lceil \frac{\mathbf{X}^{\text{FP16}}}{\Delta} \right\rfloor, \\ \Delta = \frac{\max(|\mathbf{X}|)}{2^{N-1}-1}\end{gathered}
(1)

With N=8N=8 bits the denominator is 127. The bracket ⌈⋅⌋\lceil\cdot\rfloor means round to the nearest integer. Dividing by Δ\Delta and rounding gives the integer code; multiplying the code by Δ\Delta gives back an approximation of the original value. Here is one token with four channels, the last of them large:

x     = [0.31, -1.20, 0.84, 63.5]       # one token's activations, FP16
delta = max(abs(x)) / 127                # 63.5 / 127 = 0.5
q     = round(x / delta)                 # [1, -2, 2, 127]   int8 codes
x_rec = q * delta                        # [0.5, -1.0, 1.0, 63.5]

The largest value, 63.5, lands exactly on code 127, as the formula intends. The small values each lose a lot: 0.31 comes back as 0.5 (a 61% error), 0.84 as 1.0, and every value between 0.25 and 0.75 becomes 0.5. Without the 63.5, the step would be 1.20/127≈0.00941.20/127 \approx 0.0094 and 0.31 would come back as 0.312.

The step can be measured once, offline, from a few calibration batches (static quantization, cheapest at runtime) or recomputed from each incoming tensor (dynamic, more accurate, slower). And one step can cover the whole matrix (per-tensor), or each token row can get its own (per-token), or each channel (per-channel). Finer grain fits the values better and stores more scale factors. For one axis of the activation matrix, the integer matmul cannot apply the scale at all.

Clipping is the other way to shrink the step: pick a maximum below the outlier and let the outlier saturate at code 127. The paper keeps the absolute maximum, because the outlier values matter for the model's accuracy (it cites Dettmers et al. for this).

Activation outliers in large language models

Plot the input of a linear layer in a large model next to its weight. The weight is flat: every channel has about the same range. The activation has a few channels whose values are far larger than the rest, and they are the same channels in every token.

Figure 1 · the outlier field
hover a channel
A layer's input activation X (tokens × input channels) over its weight W. Three fixed channels are bright in every token row and stand about 70× above the rest on the log-scaled bars. Toggle to W: flat and uniform, no outliers. Hover a channel to read its max.

The paper lists three properties of these activation outliers, which the figure reproduces. They are about 100× larger than most activation values (the paper's Figure 4 shows channels above 70 in OPT-13B). They occur in a small fraction of the channels. And they persist: a channel that has an outlier has it in every token, and the values within one channel vary little from token to token. The weights have none of this; their distribution is flat, and earlier work had already quantized LLM weights to INT8 and even INT4 without losing accuracy.

The outliers appear with scale. Dettmers and colleagues, in the LLM.int8() paper, measured a phase shift at about 6.7 billion parameters, past which every transformer layer has them. On OPT-175B, naive W8A8 quantization lowers average zero-shot accuracy across seven tasks from 66.9% to 35.5% and raises WikiText perplexity from 10.99 to 93,080, which is a model producing noise.

The "100×" and LLM.int8()'s "up to 20×" describe the same outliers against different baselines. SmoothQuant compares an outlier to the typical activation; LLM.int8() compares it to the largest value in the other dimensions, where non-outlier values usually sit in [−3.5,3.5][-3.5, 3.5].

How one outlier wastes the INT8 levels

Per-tensor quantization takes its step from the tensor's maximum, and the maximum is the outlier. Take an ordinary channel ii whose largest magnitude is mim_i, in a tensor whose maximum is mm. The step is m/127m/127, so the channel's values span about 2mi/(m/127)2m_i/(m/127) steps, which the paper writes as a count of usable levels:

effective levels(i)=28⋅mim\text{effective levels}(i) = 2^{8}\cdot\frac{m_i}{m}

With an outlier 100× the channel's range, mi/m=1/100m_i/m = 1/100 and the channel gets 256/100≈2.6256/100 \approx 2.6 levels; the paper says 2 to 3. These are levels, not bits. Three distinguishable levels carry log⁡23≈1.6\log_2 3 \approx 1.6 bits, so most channels of an INT8 tensor are stored at well under 2 bits of precision. Figure 2 shows an ordinary channel's values under that step: drag the outlier from 1× to 100× and watch them collapse onto two or three grid lines.

Figure 2 · effective levels
outlieroutlier ×60
Per-tensor INT8 spreads 256 levels across [−m,m][-m, m], with mm set by the outlier. Top: the full range, with ordinary values packed near zero. Bottom: a zoom on the ordinary range, its few remaining levels, and each value rounding to the nearest one. At 100× the count reaches the paper's 2 to 3 of 256.

Nearly all 256 levels sit in the empty range between the ordinary values and the outlier. Giving each channel its own step would put them back where the values are.

Why per-channel activation scales cannot run on an INT8 GEMM

The paper tests this directly in its Table 1, with simulated quantization on OPT models. On OPT-175B, averaged over four tasks (WinoGrande, HellaSwag, PIQA, LAMBADA): FP16 scores 71.6%, per-tensor INT8 activations 32.3%, per-token 31.7%, and per-channel 71.4%. Per-token does not help, because the outlier channels are large in every token, so every row has a maximum near the tensor's maximum. Per-channel recovers FP16 accuracy. Figure 3 runs the same four schemes on a small matrix with real rounding.

Figure 3 · four ways to quantize one activation
An 8 × 12 activation with outlier channels 4 and 9, quantized to INT8 for real. Top: the values, with outlines marking which cells share one step. Bottom: each cell's rounding error relative to its value; a 0 marks an ordinary value that rounded to zero. Switch schemes and hover a cell to read its true and rounded value.

On per-tensor, the step is 66.78/127≈0.5366.78/127 \approx 0.53, 11 of the 80 ordinary values round to zero, and the ordinary channels carry a 21.8% error. Per-token gets 18.7%: each row still has a 46-to-67 outlier in it. Per-channel gets 0.3%. The last button previews SmoothQuant's answer, explained in the next two sections, at 3.2%. The per-channel button is pink because no INT8 kernel can run it.

To see why, follow the dequantization. An INT8 GEMM multiplies integer codes and accumulates the products into a 32-bit integer; the step sizes have to be multiplied back in afterwards to get real numbers. A factor that does not depend on the summation index jj can be pulled out of the sum and applied once at the end. A per-token activation step ΔX[t]\Delta_{\mathbf{X}}[t] depends only on the row, and a per-output-channel weight step ΔW[o]\Delta_{\mathbf{W}}[o] only on the column, so both come out, one on each side:

Y=diag⁡(ΔXFP16) (XˉINT8 WˉINT8) diag⁡(ΔWFP16)\mathbf{Y} = \operatorname{diag}(\boldsymbol{\Delta}_{\mathbf{X}}^{\text{FP16}})\,\big(\bar{\mathbf{X}}^{\text{INT8}}\,\bar{\mathbf{W}}^{\text{INT8}}\big)\,\operatorname{diag}(\boldsymbol{\Delta}_{\mathbf{W}}^{\text{FP16}})Y=diag⁡(ΔXFP16)(XˉINT8 WˉINT8)diag⁡(ΔWFP16)\begin{aligned}\mathbf{Y} &= \operatorname{diag}(\boldsymbol{\Delta}_{\mathbf{X}}^{\text{FP16}}) \\ &\quad\big(\bar{\mathbf{X}}^{\text{INT8}}\,\bar{\mathbf{W}}^{\text{INT8}}\big) \\ &\quad\operatorname{diag}(\boldsymbol{\Delta}_{\mathbf{W}}^{\text{FP16}})\end{aligned}
(2)

A per-input-channel activation step Δ[j]\Delta[j] depends on the summation index itself. Each term of the sum needs a different factor, ∑jΔ[j] Xˉt,j Wˉj,o\sum_j \Delta[j]\,\bar{X}_{t,j}\,\bar{W}_{j,o}, so the factor would have to be applied inside the accumulation, before each add. Tensor Core kernels run a fixed sequence of integer multiply-adds at high throughput and, as the paper puts it, do not tolerate inserting slower instructions such as conversions or floating-point multiplies into that sequence. Per-channel scaling of the weights is just as fine-grained and runs without trouble, because it varies along CoC_o and comes out of the sum on the right.

Figure 4 · which scales survive the sum
Y=XW\mathbf{Y} = \mathbf{X}\mathbf{W} sums over the inner axis CiC_i. Pick a scheme: a scale constant along that sum (per-tensor, per-token rows of X, per-output-channel columns of W) moves outside it. A per-input-channel activation scale changes with the summation index and stays inside the sum.

Before SmoothQuant, a method could have per-channel accuracy or INT8 speed. LLM.int8() chose accuracy. At runtime it finds the activation channels with outliers, splits them off into a separate FP16 matmul, runs the remaining channels in INT8, and adds the two results. OPT-175B keeps 66.7% accuracy that way. The outlier columns are scattered, and the extra matmul plus the gather and scatter around it cost time: in SmoothQuant's PyTorch benchmark (batch of 4, prompt processing) LLM.int8() takes 237.1 ms on OPT-13B at sequence length 256 against FP16's 152.6 ms, and the paper finds it slower than FP16 in almost every setting it measured. Per-token schemes such as ZeroQuant stay in INT8 and lose the accuracy.

How SmoothQuant works: moving the difficulty into the weights

The activation is hard to quantize, the weight is easy, and the two are multiplied along CiC_i. SmoothQuant picks a positive factor sjs_j for every input channel, collected into s∈RCi\mathbf{s}\in\mathbb{R}^{C_i}, divides activation column jj by it and multiplies weight row jj by it:

Y=(X diag⁡(s)−1)⋅(diag⁡(s) W)=X^W^\mathbf{Y} = \big(\mathbf{X}\,\operatorname{diag}(\mathbf{s})^{-1}\big)\cdot\big(\operatorname{diag}(\mathbf{s})\,\mathbf{W}\big) = \hat{\mathbf{X}}\hat{\mathbf{W}}Y=(X diag⁡(s)−1)⋅(diag⁡(s) W)=X^W^\begin{aligned}\mathbf{Y} &= \big(\mathbf{X}\,\operatorname{diag}(\mathbf{s})^{-1}\big)\cdot\big(\operatorname{diag}(\mathbf{s})\,\mathbf{W}\big) \\ &= \hat{\mathbf{X}}\hat{\mathbf{W}}\end{aligned}
(3)

In components, X^t,j=Xt,j/sj\hat{X}_{t,j} = X_{t,j}/s_j and W^j,o=sjWj,o\hat{W}_{j,o} = s_j W_{j,o}. Every term of the sum is (Xt,j/sj)(sjWj,o)(X_{t,j}/s_j)(s_j W_{j,o}), the same product as before, so Y\mathbf{Y} is unchanged. The middle factor diag⁡(s)−1diag⁡(s)\operatorname{diag}(\mathbf{s})^{-1}\operatorname{diag}(\mathbf{s}) is the identity. The rescale is exact in floating point and loses nothing on its own; the only error in SmoothQuant is the INT8 rounding of X^\hat{\mathbf{X}} and W^\hat{\mathbf{W}} that comes after it.

A large sjs_j on an outlier channel shrinks that activation column and grows the matching weight row. The weight had range to spare (its values are small and even), so it can take on part of the spread. The paper calls this migrating the quantization difficulty from activations to weights: two tensors that are each easy to quantize, in place of one easy and one very hard.

The factor is legal where a per-channel quantization step was not, because the division by sjs_j happens before quantization, in floating point, and is folded into the previous layer (the LayerNorm section shows how). The INT8 GEMM then sees ordinary per-tensor or per-token codes and applies its scales outside the sum, as in (2). The same kind of exact per-channel rescale was used before by Nagel et al. (2019) to equalize weight ranges between two consecutive layers; SmoothQuant applies it across the two operands of one matmul, aimed at activation outliers.

How much to migrate: the migration strength α

The paper starts from the two extremes. Setting sj=max⁡(∣Xj∣)s_j = \max(|\mathbf{X}_j|) divides every activation channel by its own maximum, so all activation channels end with maximum 1, the easiest activation possible. It also multiplies each weight row by that maximum, so the outlier now sits in the weight, and the paper reports a large accuracy drop. Setting sj=1/max⁡(∣Wj∣)s_j = 1/\max(|\mathbf{W}_j|) does the opposite: every weight row ends with maximum 1 and the activation keeps its outliers. SmoothQuant interpolates between the two with one exponent, the migration strength α\alpha:

sj=max⁡(∣Xj∣)αmax⁡(∣Wj∣)1−α,j=1,…,Cis_j = \frac{\max(|\mathbf{X}_j|)^{\alpha}}{\max(|\mathbf{W}_j|)^{1-\alpha}}, \qquad j = 1,\dots,C_i
(4)

Here Xj\mathbf{X}_j is activation column jj (measured on calibration data) and Wj\mathbf{W}_j is weight row jj. α=1\alpha = 1 gives the first extreme and α=0\alpha = 0 the second. Write aj=max⁡∣Xj∣a_j = \max|\mathbf{X}_j| and bj=max⁡∣Wj∣b_j = \max|\mathbf{W}_j|. Dividing aja_j by sjs_j and multiplying bjb_j by it gives the channel's maxima after smoothing:

max⁡∣X^j∣=(ajbj)1−α,max⁡∣W^j∣=(ajbj)α\max|\hat{\mathbf{X}}_j| = (a_j b_j)^{1-\alpha}, \qquad \max|\hat{\mathbf{W}}_j| = (a_j b_j)^{\alpha}max⁡∣X^j∣=(ajbj)1−α,max⁡∣W^j∣=(ajbj)α\begin{gathered}\max|\hat{\mathbf{X}}_j| = (a_j b_j)^{1-\alpha}, \\ \max|\hat{\mathbf{W}}_j| = (a_j b_j)^{\alpha}\end{gathered}

The product ajbja_j b_j is fixed by the model; α\alpha decides how it splits between the two tensors. At α=0.5\alpha = 0.5 the two maxima are equal, both ajbj\sqrt{a_j b_j}, the geometric mean of the original maxima. That geometric mean is the value of the smoothed maxima, not of the factor: sjs_j at α=0.5\alpha = 0.5 is aj/bj\sqrt{a_j/b_j}.

A worked channel, with the numbers Figure 5 uses: activation maximum aj=70a_j = 70, weight maximum bj=0.34b_j = 0.34. At α=0.5\alpha = 0.5:

sj=70/0.34≈14.35,7014.35≈4.88,0.34×14.35≈4.88s_j = \sqrt{70/0.34} \approx 14.35, \qquad \frac{70}{14.35} \approx 4.88, \qquad 0.34 \times 14.35 \approx 4.88sj=70/0.34≈14.35,7014.35≈4.88,0.34×14.35≈4.88\begin{gathered}s_j = \sqrt{70/0.34} \approx 14.35, \\ \frac{70}{14.35} \approx 4.88, \qquad 0.34 \times 14.35 \approx 4.88\end{gathered}

The activation's largest value drops from 70 to 4.88, so its per-tensor step drops by the same factor. Before smoothing, the median ordinary channel in the figure (maximum 2.6) got 256⋅2.6/70≈10256\cdot 2.6/70 \approx 10 levels; after, with its own weight maximum of 0.45, its smoothed maximum is 2.6⋅0.45≈1.08\sqrt{2.6\cdot 0.45} \approx 1.08 and it gets 256⋅1.08/4.88≈57256\cdot 1.08/4.88 \approx 57. The weight goes from a flat tensor to one whose ordinary rows also get about 57 levels. Drag α\alpha in Figure 5 and the activation and weight readouts trade off: 13 and 256 at α=0\alpha = 0, 57 and 57 at 0.5, 256 and 13 at 1. The 13 at α=0\alpha = 0 differs from the unsmoothed 10 because sj=1/bjs_j = 1/b_j still divides each activation channel by its weight maximum: the outlier channel's maximum becomes 70×0.34=23.870 \times 0.34 = 23.8, the median channel's 2.6×0.45≈1.172.6 \times 0.45 \approx 1.17, and 256⋅1.17/23.8≈13256\cdot 1.17/23.8 \approx 13.

Figure 5 · migrating the difficulty
migrateα = 0.50
Per-channel maxima of the smoothed activation X̂ (up) and weight Ŵ (down). Drag the migration strength α\alpha. At α=0\alpha{=}0 the activation keeps the spike, at α=1\alpha{=}1 the weight takes it, and at α=0.5\alpha{=}0.5 both maxima are equal. The product X^W^=XW\hat{\mathbf{X}}\hat{\mathbf{W}} = \mathbf{X}\mathbf{W} never changes.

Under the max-only count in Figure 5, the worse of the two tensors is best at exactly 0.5, because the two readouts are mirror images. Real accuracy depends on more than the maxima (how values spread inside each channel, how activations vary from one input to the next), so the paper picks α\alpha by a quick grid search on a subset of the Pile validation set. On OPT-175B (LAMBADA, the paper's Figure 10) the sweet spot is 0.4 to 0.6: below 0.4 the activations are too hard to quantize, above 0.6 the weights are, and the model fails at both ends.

α=0.5\alpha = 0.5 is the setting for every OPT and BLOOM model. GLM-130B has about 30% outlier channels, its activations are harder, and it uses α=0.75\alpha = 0.75 to put more of the range on the weights. The later results in the paper's Table 7 use 0.85 for Llama-2-7B and 13B, 0.9 for Llama-2-70B, 0.6 and 0.7 for Falcon-7B and 40B, and 0.8 for Mistral-7B and Mixtral-8x7B, all with per-token activation and per-channel weight quantization. The factors and the static step sizes are calibrated once, on 512 random sentences from the Pile, and reused for every downstream task.

Folding s into LayerNorm: no runtime cost

Dividing the activations by s\mathbf{s} before every matmul would be an extra per-channel operation at runtime. SmoothQuant never runs it as a separate step. The input of a linear layer is the output of the previous operation, usually a LayerNorm, which ends by multiplying each channel by a learned gain γj\gamma_j and adding a bias βj\beta_j. Replacing them offline with γj/sj\gamma_j/s_j and βj/sj\beta_j/s_j makes the LayerNorm emit X^\hat{\mathbf{X}} directly, with the same number of operations. The weight side is a one-time multiply: store W^=diag⁡(s)W\hat{\mathbf{W}} = \operatorname{diag}(\mathbf{s})\mathbf{W} in place of W\mathbf{W}.

Figure 6 shows where this happens in one OPT decoder block, following the paper's precision map (its Figure 6) and the official code. The linear layers and the two batched matmuls of attention (BMM) take INT8 inputs; LayerNorm, softmax and ReLU stay in FP16. Smoothing sits at the two places where a LayerNorm feeds linear layers: the Q, K and V projections, and the first MLP layer.

Figure 6 · where INT8 and the smoothing factor sit in a block
One OPT decoder block. Teal boxes take INT8 inputs; grey boxes stay FP16. ÷ s marks a LayerNorm whose gain and bias absorb the division, and × s the weights that absorb the multiplication. Click a box or a button for details.

Q, K and V read the same LayerNorm output, so they must share one s\mathbf{s}. The official code builds it from each input channel's maximum over all three weight matrices, then multiplies all three by it. The output projection and the second MLP layer are quantized to W8A8 without smoothing, and the attention BMMs multiply two activations, so there is no weight to move range into. The whole procedure:

# One calibration pass, then an offline rewrite (after smoothquant/smooth.py).
# X: [tokens, C_i] input of a linear layer.  W: [C_i, C_o].  alpha in [0, 1].

act_max = zeros(C_i)                    # per-input-channel max |X_j|
for x in calibration_batches:           # 512 random sentences from the Pile
    act_max = maximum(act_max, x.abs().amax(dim=0))

# Q, K and V all read the same LayerNorm output, so they share one s:
# take each input channel's max |W_j| over all three weight matrices.
wgt_max = max(Wq.abs().amax(dim=1), Wk.abs().amax(dim=1), Wv.abs().amax(dim=1))

s = act_max**alpha / wgt_max**(1 - alpha)    # eq (4): a vector of length C_i

ln.weight /= s        # LayerNorm gain and bias divided by s: the LayerNorm
ln.bias   /= s        # now emits X / s, with no extra op at runtime
for W in (Wq, Wk, Wv):
    W *= s[:, None]   # row j of each weight multiplied by s_j: diag(s) W

# Same for the MLP: LayerNorm before FC1, and FC1's weight.
# Then quantize every linear layer (and the attention BMMs) to INT8.

When a linear layer's input comes from a residual add instead of a LayerNorm, there is no gain to fold the division into. For that case the paper adds an explicit scale on the residual branch, as Wei et al. do in Outlier Suppression (which calls its version Gamma Migration).

On top of the smoothing, the paper offers three quantization schemes, all with per-tensor weights: O1 quantizes activations per-token and dynamically, O2 per-tensor and dynamically, and O3 per-tensor and statically, with steps fixed at calibration. Each is faster than the last, because coarser and static steps skip work at runtime. On OPT-13B at sequence length 256, latency goes from 124.5 ms (O1) to 120.5 ms (O2) to 112.1 ms (O3), against 152.6 ms for FP16.

Results: accuracy and speed

Table 3 of the paper lines up the methods on OPT-175B. The three that quantize activations without handling the outliers (naive W8A8, ZeroQuant, Outlier Suppression) all land at 35.5% to 36.0% average accuracy, with perplexities from 84,648 to 96,151. LLM.int8() keeps 66.7%. SmoothQuant scores 66.5%, 66.4% and 66.8% for O1, O2 and O3, against 66.9% for FP16, with WikiText perplexity 11.11 to 11.17 against 10.99.

Figure 7 · accuracy recovered
SQ-O3
OPT-175B under INT8, from the paper's Table 3. Pink: accuracy collapses. Amber: LLM.int8(), accurate but slower than FP16 in SmoothQuant's own benchmarks. Teal: SmoothQuant, near FP16 in pure INT8. Toggle to perplexity (log scale); click a bar or use the slider for its numbers and its measured latency.

The other large models behave differently. BLOOM-176B is easier: naive W8A8 loses only 4 points (68.2% to 64.2%), SmoothQuant O1 and O2 match FP16, and O3 loses 0.8 points, which the authors attribute to the static steps not matching the evaluation data. GLM-130B is harder: naive W8A8 falls from 73.8% to 26.9%, O1 scores 73.7%, and O3 loses 1 point. The paper reports that LLaMA models have milder outliers; SmoothQuant keeps their WikiText perplexity within 0.05 of FP16 (11.51 to 11.56 at 7B). MT-NLG 530B averages 73.1% on four tasks in both FP16 and INT8.

The speed numbers come from the paper's own INT8 kernels (CUTLASS) on A100-80GB GPUs, timing prompt processing for a batch of 4 sentences. In the PyTorch implementation, SmoothQuant-O3 is up to 1.51× faster than FP16 (OPT-30B at sequence length 256) and uses up to 1.96× less memory. In FasterTransformer, NVIDIA's production inference library, it is up to 1.56× faster on OPT-13B and OPT-30B on one GPU, with memory almost halved. For token-by-token generation the speedup is up to 1.42× (OPT-30B, batch 16).

The memory saving changes how many GPUs a model needs. OPT-66B runs on one GPU instead of two and OPT-175B on four instead of eight, at similar or lower latency. MT-NLG 530B needs 16 A100s in FP16 (1,068 GB at sequence length 512) and 8 in INT8 (545 GB), at 838 ms against 839 ms, so it is served from a single 8-GPU node. Megatron-LM tensor parallelism fits a large model on one node by splitting each layer's matrices across its GPUs; SmoothQuant reduces how many GPUs the split needs by halving the bytes per parameter, and its FasterTransformer runs use both.

Three limits of the results. The measured speedups top out at 1.56×, below the 2× INT8 peak; part of every block (LayerNorm, softmax, ReLU, and the quantize and dequantize steps) still runs in FP16. The value of α\alpha has to be searched per model family, from 0.5 for OPT to 0.9 for Llama-2-70B. And the paper evaluates only W8A8, 8 bits for both operands. The later models in the paper's final version, LLaMA, Llama-2, Falcon, Mistral and Mixtral, all stay within 0.06 WikiText perplexity of FP16 under W8A8 SmoothQuant.

Provenance Verified against primary literatureHow we verify
Jacob et al. (2018)Integer-arithmetic quantization; Eq. (1) is its symmetric case. SmoothQuant uses the restricted range [-127, 127] (Delta = max|X| / (2^(N-1) - 1)), which the official fake_quant.py implements as q_max = 2 ** (n_bits - 1) - 1.
Dettmers et al. (2022), LLM.int8()Emergent activation outliers, with all layers affected from about 6.7B parameters; the mixed INT8/FP16 decomposition that SmoothQuant compares against. Its "up to 20x" outlier figure is measured against other dimensions, not against typical values.
Bondarenko et al. (2021)Per-channel activation quantization as an accuracy fix for transformers. SmoothQuant's Table 1 simulates it on OPT and finds it recovers FP16 accuracy, but it cannot run on an INT8 GEMM.
Wei et al. (2022), Outlier SuppressionMigrates the LayerNorm gain into later layers and scales the residual branch to match (its "Gamma Migration"). SmoothQuant borrows the residual-branch scaling and uses Outlier Suppression as a W8A8 baseline that fails on OPT-175B.
Nagel et al. (2019)Weight equalization: a per-channel rescale between two consecutive layers that flattens WEIGHT outliers. SmoothQuant applies the same kind of exact rescale to activation outliers, across a single matmul.
mit-han-lab/smoothquantsmooth.py, smooth_ln_fcs (lines 18-45): s = act_scales^alpha / weight_scales^(1-alpha), with weight_scales the max over all linear layers fed by one LayerNorm; LayerNorm weight and bias divided by s; each linear weight multiplied by s along its input dimension. smooth_lm (lines 74-90): smoothed inputs are Q/K/V and FC1 only.
CUTLASS / FasterTransformerThe INT8 GEMM kernels and the production serving library behind the speed numbers (A100-80GB).
correctionTwo points that summaries of SmoothQuant get wrong. (1) Only per-INPUT-channel scaling of ACTIVATIONS is infeasible for an INT8 GEMM, because that scale varies along the contraction axis C_i and would have to be applied inside the integer accumulation. Per-channel scaling of WEIGHTS is standard and fine: it runs along the output axis C_o and is applied after the matmul (LLM.int8() uses it, and so does SmoothQuant's own Table 7 setup). The barrier is the axis, not the granularity. (2) The rescale in Eq. (3) is exactly identity-preserving in floating point, since diag(s)^-1 diag(s) = I. Smoothing loses nothing on its own; the only error is the INT8 rounding that follows, which smoothing makes easier.

Questions you might still have

?

Why not quantize only the weights and leave the activations in FP16?
Weight-only INT8 (W8A16) halves weight memory, which speeds up memory-bound token-by-token decoding, but the INT8 weights are converted back to FP16 before the multiply, so the matmul runs on the FP16 units at the FP16 rate. Only W8A8, with both operands in INT8, can use an INT8 GEMM and the A100's 624 INT8 TOPS against 312 FP16 TFLOPS. The QLoRA explainer covers a weight-only 4-bit format that computes in 16 bits.

?

If the rescale is exactly equivalent, where does any accuracy loss come from?
From INT8 rounding of the smoothed activation and of the scaled weight. In floating point the two diagonal factors cancel and the layer output is unchanged. After smoothing, both tensors have per-channel maxima of comparable size, so the per-tensor step is small enough that ordinary values keep tens of levels instead of two or three.

?

Does SmoothQuant remove the outliers?
No, it splits them. At alpha = 0.5 a channel whose activation max is 70 and weight max is 0.34 ends with both maxima at about 4.9. The product per channel is unchanged; what changes is that neither tensor contains one value far above the rest.

?

Why does per-token quantization not help?
The outlier channels are large in every token, so every token row contains a value near the tensor maximum, and each per-token step is about as coarse as the per-tensor step. The paper measures this on OPT-175B: per-token 31.7% against per-tensor 32.3% average accuracy, while simulated per-channel quantization reaches 71.4% against FP16's 71.6%.

?

How is alpha chosen, and is 0.5 always right?
By a quick grid search on a subset of the Pile validation set; no training. 0.5 is the setting for OPT and BLOOM, with a sweet spot of about 0.4 to 0.6. GLM-130B, with about 30% outlier channels, uses 0.75, and the later results on Llama-2, Falcon, Mistral and Mixtral use 0.6 to 0.9 with per-token activation and per-channel weight quantization.

?

How is this different from LLM.int8(), GPTQ or AWQ?
LLM.int8() finds the outlier channels at runtime and runs them as a separate FP16 matmul next to an INT8 one: accurate, but slower than FP16 in SmoothQuant's measurements. SmoothQuant keeps every matmul in INT8 with no runtime detection. GPTQ and AWQ quantize weights only, so they save memory but leave the matmul in 16-bit arithmetic.

Footnotes & further reading

  1. The paper: Xiao, Lin, Seznec, Wu, Demouth, Han, SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models (MIT / NVIDIA, ICML 2023; arXiv v7, March 2024, adds the Llama-2, Falcon, Mistral and Mixtral results). Code.
  2. Emergent activation outliers and the mixed-precision baseline: Dettmers et al., LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale (2022).
  3. The residual-branch scaling SmoothQuant reuses: Wei et al., Outlier Suppression (2022). Per-channel activation quantization for transformers: Bondarenko et al., Understanding and Overcoming the Challenges of Efficient Transformer Quantization (2021).
  4. Integer-arithmetic quantization: Jacob et al., Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference (2018); the symmetric conventions are surveyed in Gholami et al., A Survey of Quantization Methods (2021). Weight equalization: Nagel et al., Data-Free Quantization Through Weight Equalization and Bias Correction (2019).
  5. The A100's dense peak rates (312 FP16 TFLOPS, 624 INT8 TOPS) are from NVIDIA's A100 specifications.
  6. Other compression explainers in the library: QLoRA stores weights in 4 bits and computes in 16, and TurboQuant compresses individual vectors to a few bits, a different problem from SmoothQuant's per-channel rebalancing.