AWQ (Activation-aware Weight Quantization) keeps accuracy even with 4-bit and 3-bit weights by using activations to find the important weights and scaling those weights up before quantization. It was proposed by Lin et al. in 2023 and presented at MLSys 2024 (Best Paper Award).
When a large language model (LLM) runs on local hardware such as a PC or smartphone, the stage that generates text one token at a time is especially slow. The paper's analysis shows that this stage is bound not by computation but by how fast weights can be read from memory, and that the weights are orders of magnitude larger than the activations. Weight-only 4-bit quantization (W4A16) is therefore effective.
AWQ starts from the observation that not all weights are equally important.
Keeping just 0.1β1% of the weights in 16 bits recovers much of the accuracy lost by 3-bit quantization.
However, this works only when the kept weights belong to input channels with large activations; selecting by the magnitude of the weights themselves is barely better than selecting at random.
Keeping only some weights in 16 bits is awkward for hardware. AWQ instead obtains the same effect with an equivalent transformation: it multiplies the weights of important channels by s before quantization and multiplies the input by 1/s. All weights stay in the same 4-bit format, so computation remains efficient.
Theory (Scale Up Important Channels, Then Round)
Consider quantization that rounds a group of weights w onto a grid with spacing Ξ (Eq. (1) in the paper).
Q(w)=Ξβ Round(Ξwβ)
Ξ is the maximum absolute value in the group, max(β£wβ£), divided by the number of grid levels determined by the bit width N.
If a weight w is multiplied by s>1 before quantization and the input x is multiplied by 1/s, the result equals the original wx, but the error changes as follows (Eq. (3) in the paper).
The rounding error RoundErr is unchanged on average (about 0.25), and scaling up a single weight usually does not change the group maximum, so Ξβ²βΞ. As a result, the error of the scaled weight shrinks by roughly a factor of 1/s. As an analogy, it is like writing only the important digits in large print before making a reduced copy: the copy is equally coarse, but the digits written larger are misread less often.
If s is too large, however, the group maximum changes, Ξβ² grows, and the error of the other weights in the same group increases. In the paper's OPT-6.7B experiment, scaling the 1% of channels with the largest activations by s=2 gave the best perplexity (23.54 β 11.92), while s=4 degraded it to 12.36.
AWQ therefore chooses a per-input-channel scale s that minimizes the deviation of the layer output after quantization (Eqs. (4) and (5) in the paper).
Run a small amount of calibration data through the model and collect the input X of each layer. To avoid bias toward a particular application, the paper takes general text of the kind used for pretraining (the Pile).
For each input channel, compute the mean absolute activation sXβ.
Try 20 values of Ξ± in the range 0β1 and pick the s=sXΞ±β that gives the smallest output deviation after quantization. Ξ±=0 means no scaling, and Ξ±=1 means the strongest scaling.
Also tune the weight clipping range so that the mean squared quantization error becomes small.
Quantize Wβ diag(s) to INT4 (or INT3) in groups of 128.
Fold diag(s)β1 into the coefficients of the preceding operation (such as a normalization layer). No extra computation is added at inference time.
AWQ uses neither backpropagation nor the error-compensating regression of methods like GPTQ. The only quantity measured from data is the average activation magnitude per channel, so it needs little data and is less prone to overfitting the calibration set.
Experimental Results
Table 1 of the paper compares which weights to keep in 16 bits for 3-bit OPT-6.7B with group size 128 (WikiText perplexity; lower is better).
Selection
0.1%
1%
3%
By activation magnitude
11.58
11.39
11.36
By weight magnitude
23.41
22.37
22.45
Random
23.54
24.23
24.22
The 16-bit model scores 10.86, and simple round-to-nearest (RTN) on all weights scores 23.54. Selecting by activation gives a large improvement while keeping only 0.1%.
The main results (Table 4: Llama 2 WikiText2 perplexity, group size 128) are as follows.
It needs little data. On 3-bit OPT-6.7B, AWQ with 16 sequences achieved better perplexity than GPTQ with 192.
It also works for instruction-tuned and vision-language models. The paper evaluates Vicuna, OpenFlamingo-9B, and LLaVA-13B and reports good quantization results.
Combined with a dedicated inference framework (TinyChat), it is faster. With 4-bit weights, it ran more than 3Γ faster than the 16-bit Hugging Face implementation on both desktop and mobile GPUs.
Practical Considerations
Only the weights are quantized (W4A16). Activations stay in 16 bits, so the amount of computation does not decrease. The speedup comes from reading fewer weight bytes from memory, and it requires dedicated kernels for low-bit weights.
It assumes an architecture where the scale 1/s can be folded into the preceding operation. The paper absorbs the input-side scale into the operation just before, such as a normalization layer. For layers with nothing to fold into, computation increases accordingly.
Choose the group size and bit width to balance accuracy against memory. The paper uses a group size of 128 in almost all experiments.
Scaling too aggressively actually hurts accuracy. The error of the important channels decreases, but the grid for the other channels in the same group becomes coarser. This is why AWQ searches for Ξ±; a fixed large factor can degrade results, as in the paper's s=4 example.
Comparison with Other Methods
The table compares methods for reducing LLM weights to low bit widths along the same dimensions.
Migrates the magnitude of activation outliers into the weights (goal: 8-bit activations as well)
Scales set by a formula
Small
AWQ and SmoothQuant both use the equivalent transformation of "scaling up the weights and scaling down the input per input channel." They differ in purpose: SmoothQuant flattens activation outliers to make 8-bit activations feasible, while AWQ reduces the error of important weights when quantizing weights to 4 bits.
To run an LLM on local hardware with 4-bit weights, AWQ is a good fit. It needs little data and tends to preserve accuracy across models for many applications.
To push to 3 bits or below, or when a GPTQ pipeline is already in place, GPTQ is also a candidate. The paper shows that combining AWQ and GPTQ improves results further.
To speed up computation by making both weights and activations 8-bit, choose SmoothQuant.
PyTorch example
βΆShow code
python
import torch
# AWQ scale search for a single linear layer (small implementation for illustration)
# W: weights of shape (out, in); X: layer input of shape (tokens, in), collected from calibration data
# y = X @ W.T. A scale s is applied per input channel (column of W)
def quantize_groupwise(W, bits=4, group_size=128):
"""Group-wise symmetric quantization (the form of Eq. (1) in the paper; Delta is set from the group's max absolute value)"""
out_f, in_f = W.shape
Wg = W.reshape(out_f, in_f // group_size, group_size)
delta = Wg.abs().amax(dim=-1, keepdim=True).clamp(min=1e-8) / (2 ** (bits - 1) - 1)
q = torch.clamp(torch.round(Wg / delta), -(2 ** (bits - 1)) + 1, 2 ** (bits - 1) - 1)
return (q * delta).reshape(out_f, in_f) # dequantized values
@torch.no_grad()
def awq_search_scale(W, X, bits=4, group_size=128, n_grid=20):
s_x = X.abs().mean(dim=0) # mean activation magnitude per input channel
ref = X @ W.T # output before quantization
best = (float("inf"), None, None)
for i in range(n_grid): # search alpha over 20 points in [0, 1)
alpha = i / n_grid
s = s_x.pow(alpha).clamp(min=1e-4)
W_q = quantize_groupwise(W * s, bits, group_size) # Q(W Β· diag(s))
out = (X / s) @ W_q.T # (diag(s)^-1 Β· X)
loss = (out - ref).pow(2).mean().item()
if loss < best[0]:
best = (loss, alpha, s)
return best
torch.manual_seed(0)
in_f, out_f, tokens = 256, 128, 512
W = torch.randn(out_f, in_f) * 0.02
X = torch.randn(tokens, in_f)
X[:, :3] *= 20 # only a few input channels have large activations
ref = X @ W.T
rtn = X @ quantize_groupwise(W, bits=3).T # simple rounding (same as alpha = 0)
loss, alpha, s = awq_search_scale(W, X, bits=3)
print("RTN error:", (rtn - ref).pow(2).mean().item())
print("AWQ error:", loss, " chosen alpha:", alpha)
# At inference, store the quantized W * s and fold 1/s into the coefficients of the previous layer (e.g., normalization)
FAQ
Q. Why are important weights selected by activation magnitude rather than weight magnitude?
A.
Because the effect on the output is determined by the product of the weight and the input. For channels with large inputs (activations), even a small deviation in the weight changes the output a lot. In the paper's experiments on 3-bit OPT-6.7B, keeping the 1% of channels with the largest activations in 16 bits improved perplexity from 23.54 to 11.39, whereas keeping the 1% selected by weight magnitude only reached 22.37.
Q. Should I use AWQ or GPTQ?
A.
Both can bring weights to 4 bits without training, and in the paper's comparison AWQ gave slightly better perplexity on LLaMA and Llama 2. AWQ uses neither backpropagation nor regression and needs less data, so it suits situations where the calibration data and the application are likely to differ, such as instruction-tuned models. The paper also shows that combining the two improves results further.
Q. Does multiplying by the scale s add computation at inference?
A.
Hardly any. The s applied to the weights is folded into the weights before quantization. The 1/s applied to the input can be folded into the coefficients of the preceding operation (such as a normalization layer), so it does not need to be computed separately at inference.