Lab 01 — AWQ Quantization
Phase: 10 — GenAI on Edge | Difficulty: ⭐⭐⭐⭐⭐ | Time: 3–4 hours
AWQ (Activation-aware Weight Quantization, Lin et al., 2023) is state-of-the-art INT4 quantization for LLMs deployed on edge devices.
What you build
compute_per_channel_scale— max|W[i,:]| / 7 for INT4 symmetric quantizationquantize_weight_int4— clamp[-7,7] → round → dequantizeawq_scale_search— grid search over α∈[0,1]: s = x_max^α, minimize ‖W@X - Q(W·s)/s@X‖²awq_quantize_linear— full AWQ quantization of a single linear layerevaluate_quantization_error— relative error + cosine similarity
Key concepts
| Concept | What to understand |
|---|---|
| Channel scaling | Multiply salient weight channels by s before quantization (reduces error) |
| Activation-aware | s = x_max^α — scale determined by activation magnitude, not just weights |
| INT4 vs INT8 | INT4 = 2× more layers fit in NPU SRAM — critical for 7B+ edge LLMs |
| AWQ vs GPTQ | AWQ: activation scaling; GPTQ: Hessian-based correction — both SOTA |
Files
| File | Purpose |
|---|---|
lab.py | Stubs with TODO markers |
solution.py | Complete working implementation |
test_lab.py | pytest suite |
requirements.txt | Dependencies |
Run
pip install -r requirements.txt
python lab.py
pytest test_lab.py -v