AI State of the Art
SOTA/Inference & Optimization/23 min
Section 119

AWQ (Activation-aware Weight Quantization)

Listen as a podcast →

The Key Observation: Not All Weights Are Equal

AWQ stands for Activation-aware Weight Quantization. The whole name is the method, provided you keep this module's basic distinction in mind: weights are the model's learned parameters, frozen since the end of training; activations are the computed values flowing through the model when you feed it text. AWQ quantizes the former by looking at the latter.

Like GPTQ, this is a post-training method (PTQ): it applies to an already trained, frozen model and never retrains it. So it costs a calibration, not a training run, compare with QAT, on the other side of the dividing line.

Most quantization methods treat all model weights the same way: round everything to 4 bits and cross your fingers. AWQ is smarter. Its founding idea is simple: look at what flows through the layers (the activations) to identify which weights are truly critical. Then protect them.

AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration (Lin et al., 2023)

The idea in one sentence: If an activation channel consistently carries large values, the corresponding weights play an important role. They need to be quantized with care.

The number the method rests on

The paper reports that protecting only 1% of the weights (the ones the activation distribution flags as important) greatly reduces quantization error. The demonstration is on OPT-6.7B quantized to 3 bits with groups of 128, measured as perplexity on WikiText: plain rounding gives 43.2, and keeping that 1% of weights in FP16 brings it back to 13.0. One percent of the weights accounts for most of the damage.

Figure from the AWQ paper, in three panels. Panel a, RTN quantization: an FP16 weight matrix is rounded wholesale to INT3, perplexity 43.2. Panel b: the activations X are used to spot the salient channels, whose weight row is left in FP16, perplexity 13.0, annotated bad hardware efficiency. Panel c: the average magnitude of the activations yields a factor alpha that scales the weights before everything is quantized to INT3, perplexity 13.0 as well.
AWQ's full reasoning in one image. Rounding every weight the same way blows perplexity up from 13 to 43 (a). Keeping the 1 percent of salient weights, identified from the activations, in FP16 restores quality, but mixing two precisions inside one matrix is bad for the GPU (b). Hence the actual trick: scale those weights up before quantizing everything to the same format, which recovers the quality without the hardware penalty (c).Source : AWQ paper (Lin et al., figure 2), arXiv
The intuition with an analogy

Imagine a building. To know which pillars are structural, look at the load they bear. A pillar carrying 50 tons is critical: you're not going to replace it with a cardboard pillar. A decorative pillar carrying 5 kilograms? You can afford to simplify it. AWQ does exactly this with the model's weights.

How It Works, Concretely

Step 1: Measure Channel Salience

A channel's salience is its relative importance, measured by the average magnitude of its activations: the larger the activations, the more the channel matters to the model.

You pass a few text excerpts through the model (the calibration set) and observe the activations. For each input channel, you measure the average magnitude of the activations flowing through it:

salience(channelj)=mean(∣activationj∣)\text{salience}(\text{channel}_j) = \text{mean}(|\text{activation}_j|)

Reading the formula: the index jj is the input channel number, ∣⋅∣|\cdot| is absolute value (sign discarded, only size counts), and the mean runs over every token of the calibration texts. A salient channel is one that carries large values on average.

Channels with high average activations are the important ones: they carry the model's critical information. Channels with low activations are barely used, so they can be quantized more coarsely.

Step 2: Protect Important Channels by Scaling Them Up

Here's the central trick. Before quantizing, you multiply the important weights by a scale factor ss greater than 1.

Protected weight=Original weight×s\text{Protected weight} = \text{Original weight} \times s

Where ss is a number above 1, chosen channel by channel from the salience measured in step 1.

Why this protects anything is the subtle part. The absolute rounding error does not depend on the weight itself: it is at most half the quantization step, that fixed gap between two available levels. And that step is set by the largest value in the group of 128 weights. Scaling one isolated weight up almost never changes the group's maximum, so the step stays the same, the absolute error stays the same, but the weight is now twice as large: its relative error has been halved. You have handed that weight free precision, taken from nowhere.

Nothing is free indefinitely, though. Scale too far and the group maximum eventually moves, the quantization step widens, and every other weight in the group sees its error grow. The authors measure that turning point: on OPT-6.7B the best result lands around s=2s = 2, and beyond that the damage to the non-salient channels outweighs the gain.

Then you quantize normally. And when you run the model, you divide the input activations by the same factor ss to compensate. The result of the weight × activation product is mathematically unchanged, a factor has simply moved from one side to the other. Better still: that division costs nothing at run time, because it is folded into the preceding layer, typically into the normalization coefficients.

It's as if you "zoomed in" on the important weights before taking the low-resolution photo (quantization), then "zoomed out" afterward.

Diagram of the AWQ scaling factor computation. Bottom left, the activation matrix X, with columns shaded by intensity. An arrow labelled average magnitude points up to a single-row vector alpha carrying the same shades. A curved arrow labelled scale before quantization leads to the quantized weight matrix Q of W on the right, in which two rows stand out in bright green.
The per-channel scaling factor, visualized. The average magnitude of the activations X gives a vector alpha, one coefficient per input channel. Weights are multiplied by that coefficient before rounding, so the rows matching the busiest channels (bright green) end up preserved far more precisely than the rest.Source : NVIDIA Developer Blog (post-training quantization)

Step 3: Find the Optimal Scaling Factor

The last step is a simple grid sweep: you try around twenty values over an interval and keep the one that minimizes quantization error. No heavy matrix algebra, no Hessian inversion as in GPTQ. Just try and measure.

Why it's faster than GPTQ

GPTQ has to invert a Hessian matrix (the matrix of second derivatives of the error) for each layer, which is expensive. AWQ needs neither backpropagation nor reconstruction: it measures activation averages and sweeps about twenty scale factors. That is what the authors emphasize, with a useful consequence, the method barely depends on the calibration set, since all it extracts is one average magnitude per channel, not a fine-grained fit that could latch onto those particular texts.

The Concrete Advantages

1. Better Quality

At 4 bits, AWQ reaches better perplexity than GPTQ on the LLaMA and Llama-2 models measured in the paper, at every size tested. The numbers are in the table below.

2. Fast Calibration

Minutes instead of hours: there is no backpropagation and no matrix inversion, only averages and a sweep.

3. Little Dependence on the Calibration Set

AWQ is not very sensitive to the choice of calibration examples. Activation magnitudes are a relatively stable property of the model, not an artifact of one particular corpus.

4. Dedicated GPU Programs

The AWQ team wrote kernels (programs written specifically for the GPU, in CUDA, NVIDIA's GPU programming language) that expand the 4-bit weights on the fly without giving back the time saved on transport. They ship inside vLLM, TGI and other inference servers.

What It Weighs

A word on memory cost, since that is this module's running thread. A model quantized by AWQ to 4 bits with groups of 128 costs 4.16 bits per weight once you count each group's scale factor and zero point (the arithmetic is spelled out on the GPTQ page). That is 4.16 ÷ 8 = 0.52 bytes per parameter, so for a 7 billion parameter model: 7 × 0.52 ≈ 3.6 GB, against 14 GB at 16 bits.

One important point: AWQ's scale factor costs nothing extra. That is in fact the method's central argument. The natural alternative (keeping the important 1% of weights in FP16 inside an otherwise 4-bit matrix) would give the same quality but would mix two precisions within one matrix, which GPUs handle badly. By turning the protection into a plain rescaling, AWQ gets the benefit without the mixture: the whole matrix stays in a single format.

Comparative Results

The protocol, without which the numbers mean nothing: model LLaMA-7B, perplexity measured on WikiText-2, weights in 4 bits with groups of 128. Perplexity is the effective number of words the model is torn between when predicting the next one, lower is better; definition in quantization concepts. Figures from table 4 of the paper.

MethodPerplexityGap to FP16
FP16 (reference)5.68–
Plain rounding (RTN)5.96+4.9%
GPTQ6.22+9.5%
GPTQ with reordering5.83+2.6%
AWQ5.78+1.8%

AWQ does come out ahead, but the margins are tight: 0.05 of a perplexity point separates reordered GPTQ from AWQ. On this model family the paper reports that lead at every size tested, from 7 to 65 billion parameters.

A real lead, but a modest one

Don't over-read these gaps: a few hundredths of perplexity on WikiText-2 tells you almost nothing about what you will see on your own task. AWQ's real argument in production is not this quality edge, it is the calibration time (minutes against hours) and the availability of the matching GPU programs.

Practical Usage

Quantizing a Model

from awq import AutoAWQForCausalLM

model = AutoAWQForCausalLM.from_pretrained("mistralai/Mistral-7B")
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B")

model.quantize(tokenizer, quant_config={
    "w_bit": 4,
    "q_group_size": 128,
})
model.save_quantized("./mistral-awq")

Inference with vLLM

from vllm import LLM
model = LLM("./mistral-awq", quantization="awq")
outputs = model.generate(["Hello"])

AWQ in the Deployment Ecosystem

  • vLLM: native support with optimized kernels, the most common combination in production
  • TGI (Text Generation Inference, Hugging Face's inference server): direct support
  • TensorRT-LLM: support via conversion, for optimized NVIDIA deployments
  • Transformers HF: support via the autoawq library

AWQ has become the preferred quantization format for production deployment on NVIDIA GPUs, thanks to its excellent quality/calibration speed/inference performance ratio.

NVIDIA GPUs only

AWQ's inference kernels are only optimized for NVIDIA GPUs. If you're targeting an ordinary processor (CPU), a Mac or an AMD card, you'll need to turn to GGUF. The two formats target different use cases: AWQ for production GPU servers, GGUF for local multi-platform inference.

Recent Developments

Combining with FP8 on H100

H100 GPUs can compute directly in FP8 (8-bit floating point). So you can consider keeping the weights at 4 bits under AWQ while also bringing the activations down to FP8, which lightens the second source of memory traffic. Inference frameworks offer variants along these lines; the gains depend too much on the model and the load for a general figure to mean anything here.

A Very Common Format in Production

AWQ is one of the most common quantization formats for deployment on NVIDIA GPUs, thanks to a favourable balance of quality, calibration speed and availability of optimized inference programs. It coexists with GPTQ, thousands of whose models are still in circulation, and with FP8 where the hardware allows.

Check your understanding0 / 4

1. To decide which weights to protect, what does AWQ measure during its calibration phase?

2. Before quantizing, AWQ multiplies the weights of important channels by a factor s of around 2. How does that protect them?

3. The paper shows that keeping 1 percent of the weights in FP16 is enough to preserve quality. Why does AWQ not simply do that?

4. In production, what is AWQ's real argument over GPTQ, according to this page?