↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

What SmoothQuant is

Weight-only methods such as GPTQ and AWQ keep the activations in 16 bits, so every matrix product still runs in floating point. W8A8 quantizes both the weights and the activations to 8-bit integers, so the product can run on integer units: int8 times int8, summed in int32, rescaled once at the end. Weights are easy to put in 8 bits; activations are not, because a few channels are far larger than the rest. SmoothQuant moves part of that range from the activations into the weights with a per-channel scale that leaves the layer's output unchanged, and then quantizes both.

This page applies it to Qwen2.5-0.5B-Instruct, featuring the activations that reach layer 12's q_proj, k_proj and v_proj (896 channels), and runs the whole model in naive and smoothed W8A8, with the integer arithmetic simulated in PyTorch.

A few huge channels

An 8-bit quantizer with one scale for a whole activation tensor uses and stores . The A few huge channels panel plots each channel's maximum over the calibration text on a log scale: channel 62 and a handful of others are many times the median channel, so the step is set by them and most channels round to only a few of the 255 levels. The weight columns that meet those channels, drawn below, are not unusual. LLM.int8() found such outlier features in large transformers and kept them in 16 bits; Sun et al. later described a few massive activations, up to 100,000 times larger than the rest.

With one scale per token instead of per tensor, each row of the activation gets its own . That helps when a whole token is loud, but an outlier channel is large in every token, so per-token scales still share each row's range with it. The toolbar switches between the two.

Smoothing

For a linear layer , divide input channel by and multiply weight column by the same :

The two scalings cancel in every term , so before rounding the output is the same: the page measures a largest difference of for outputs up to 25.37, float32 rounding. The migration strength decides how much of the range moves: leaves the outliers in the activations, moves all of it into the weights. No division happens at run time: the RMSNorm before , and has its weight divided by , so it already outputs , and the three matrices' columns are multiplied by .

The Smoothing panel shows the maxima after smoothing for any and the int8 codes of and of , whose rows are quantized one scale per output channel.

Choosing α

The sweep in the Smoothing panel measures q_proj's W8A8 output error on 4,096 held-out tokens for from 0 to 1. With one activation scale per tensor the error is 2.48 % without smoothing and 0.86 % at , the paper's default and the value the whole-model runs use; the curve is lowest at . With one scale per token it is 0.89 % without smoothing and 0.51 % at , lowest at . Too large an makes the weights the hard part, and the error rises again.

The Every block strip repeats the measurement for every layer's attention and MLP inputs, and for o_proj and down_proj, which this recipe, like SmoothQuant's for Llama-like models, quantizes without smoothing. The worst tensor is down_proj at layer 5, with a naive W8A8 error of 57 %: its input channels reach 869 times their median.

What the model says

With one scale per tensor the whole model breaks even after smoothing: WikiText-2 perplexity is 91.03 naive and 88.13 smoothed, against 19.93 for the original, because the unsmoothed o_proj and down_proj inputs still hold their outliers. Keeping just those two in 16 bits gives 20.17. With one scale per token, naive W8A8 gives 20.28 and smoothed W8A8 20.21, with a next-token KL of 0.00354 nats from the original.

The One output in integers panel computes one real output, q_proj row 32 at the last prompt token, the way an integer unit would: int8 inputs and weights, an int32 sum, then one multiplication by the two scales. Unsmoothed, 125 of the 896 int8 inputs are 0; smoothed, 28 are. The float output is 21.9854; the integer path gives 21.9701 naive and 21.9736 smoothed.

Where it came from

Integer-only inference with int8 weights, int8 activations and int32 accumulation was worked out for mobile vision networks (Jacob et al., 2017). ZeroQuant (2022) applied group-wise weights and per-token activations to transformers, and LLM.int8() (2022) showed that outlier features made plain 8-bit activations fail beyond a few billion parameters. SmoothQuant (2022) made W8A8 work across OPT, BLOOM and later Llama-family models; its paper reports up to 1.56 times speed-up and 2 times less memory. The same per-channel scaling, used to protect weights instead, is AWQ (the AWQ tab).

Papers

  1. SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models Guangxuan Xiao, Ji Lin, Mickael Seznec, Hao Wu, Julien Demouth, Song Han · ICML 2023 The method: per-channel smoothing scales with migration strength α, folded into the preceding layer, for W8A8.
  2. LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale Tim Dettmers, Mike Lewis, Younes Belkada, Luke Zettlemoyer · NeurIPS 2022 Finds the outlier feature dimensions that break 8-bit activations, and keeps them in 16 bits with a mixed-precision product.
  3. Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference Benoit Jacob et al. · CVPR 2018 The integer scheme the One output in integers panel follows: 8-bit codes, an int32 accumulator and a rescale by the scales.
  4. ZeroQuant: Efficient and Affordable Post-Training Quantization for Large-Scale Transformers Zhewei Yao, Reza Yazdani Aminabadi, Minjia Zhang, Xiaoxia Wu, Conglong Li, Yuxiong He · NeurIPS 2022 Per-token dynamic activation quantization for transformers, the toolbar's per-token option.
  5. Massive Activations in Large Language Models Mingjie Sun, Xinlei Chen, J. Zico Kolter, Zhuang Liu · COLM 2024 A few activations up to 100,000 times larger than the others, nearly constant across inputs, which no single 8-bit scale can share with the rest.
  6. Qwen2.5 Technical Report An Yang et al. (Qwen Team) · arXiv 2024 The Qwen2.5 models, including the 0.5B instruct model this page quantizes.

See also