PaperLeet

AWQ Activation-Aware Scaling Calibration

AWQ · MLSys 2024 · Hard · 40 minutes

Implement groupwise fake quantization and select activation-aware scale exponents by calibration output error.

Single-linear-layer AWQ grid search and asymmetric group quantization using mean absolute activation statistics; clipping search and TinyChat kernels are excluded.

Functions to implement

AWQ Activation-Aware Scaling Calibration

1. Problem

Implement groupwise fake quantization and select activation-aware scale exponents by calibration output error.

Single-linear-layer AWQ grid search and asymmetric group quantization using mean absolute activation statistics; clipping search and TinyChat kernels are excluded.

Source: AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration · Section 3.2: activation-aware scaling search; official auto_scale.py _search_module_scale.

2. Core equations

$$ a_j=\operatorname{mean}i|X{ij}|,\quad s_j=\frac{\max(a_j^\alpha,10^{-4})}{\sqrt{\max_j s^{raw}_j\min_j s^{raw}j}},\quad \widehat W=Q(Ws)/s,\quad \alpha^*=\arg\min{\alpha\in G}\operatorname{mean}(X\widehat W^T-XW^T)^2. $$

3. From equations to code

  • group_quantize(weight: Tensor, bits: int, group_size: int) -> Tensor — Detached dequantized weights under asymmetric groupwise quantization.
  • awq_search(x: Tensor, weight: Tensor, bits: int, group_size: int, alphas: list[float]) -> tuple[Tensor, Tensor, float, float] — Best input-channel scales, dequantized weights, exponent and output MSE.

Each exponent starts from the same original weights: multiply by channel scales, quantize groups, then divide by those scales. Select by calibrated linear-output MSE, not weight-space MSE.

4. Conventions

x:(N,D), weight:(O,D); D is divisible by group_size. bits is an integer 2..8, and alphas is nonempty within [0,1]. Groups contain consecutive input channels of each output row. Quantizer step=max((max-min)/(2^bits-1),1e-5), zero=clip(round(-min/step),0,2^bits-1), with ties-to-even rounding. Clamp raw scales to 1e-4, then normalize by sqrt(max*min). Break equal-error ties by supplied alpha order. Return (scales,dequantized_weight,alpha,float MSE); offline calibration is detached.

5. Experiment view

Use 16 deterministic calibration samples with one channel amplified eightfold and 3×4 weights under three-bit group quantization. Sweep eleven alpha values from zero to one and compare the selected candidate with alpha zero.

The chart is generated by the actual submitted kernel during T3 and by the reference during export. Values are synthetic teaching measurements, not GPU throughput or full-model quality claims.

6. Run your implementation

Complete the functions in the Python editor on the right, then click Run tests. Inspect each failed check, update your implementation, and run again. Passing every required check marks the problem as solved and unlocks the notes.

7. Further study

Read the cited section and explain which dimensions or scheduling constraints the kernel preserves. Then extend the experiment beyond the stated fixture while retaining the existing contract. Larger models, real devices, and communication costs require separate measurement.

Read paper · arXiv:2306.00978

Related exercises