Unit 3 of 12 · about 4 hours · derive, implement
Calibration, observers, outliers and activation smoothing
Outliers decide whether activation quantization survives. Calibration picks the range, and smoothing or salient scaling decides which side absorbs the difficulty.
You'll be able to
- Run static and dynamic calibration on one linear layer and explain when each range goes stale.
- Derive the SmoothQuant migration and the per-channel factor from activation and weight maxima.
- Contrast activation smoothing with salient-weight scaling on an outlier channel, with error numbers.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Outliers, smoothing and the O1 to O3 ladderSmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models
SmoothQuant arXiv:2211.10438v7, Section 3 Review of Quantization Difficulty (outliers near 100x, fixed channels), Section 4 SmoothQuant with the migration equation and the and settings, and Section 5.1 setups (512 Pile sentences, grid search, O1 per-token dynamic versus O2/O3 per-tensor)
Read the O1, O2 and O3 rows as a cost ladder, not as three methods to deploy. Stop before the distributed results.
- Salient weights and activation-aware scalingAWQ: Activation-Aware Weight Quantization for LLM Compression and Acceleration
AWQ arXiv:2306.00978v6, Section 3.1 (protecting 1 percent of salient weights, perplexity 43.2 to 13.0) and Section 3.2 (activation-aware scaling search), plus Figure 8 on smaller calibration sets and calibration distribution robustness
- Day 14: GPTQ, AWQ and SmoothQuant cells100 Days of LLM Inference - Days 13, 14 and 15
Notebook
day14/quantization-gptq-awq-smoothquant.ipynb: AWQ Activation-Aware Weight Quantization (awq_get_scales,awq_quantize) and SmoothQuant Migration Transform (smoothquant_calibrate) - MIT 6.5940 Lecture 13: SmoothQuant and AWQ in lecture formMIT 6.5940 TinyML and Efficient Deep Learning Computing - Quantization Lectures
Lecture 13 Efficient LLM Deployment slides and video, Quantization part: Weight-Activation Quantization: SmoothQuant, then Weight-Only Quantization: AWQ and TinyChat. Lectures 5 and 6, Quantization Part I and II, cover the fundamentals if you need them
Focus on
- Static calibration fixes ranges from sample data and goes stale when the workload shifts; dynamic calibration reads ranges at runtime and costs compute per step. Name which one each scale uses.
- SmoothQuant moves difficulty from activations to weights with a per-channel factor , fused offline into neighboring layers so inference sees ordinary INT8.
- AWQ scales every weight input channel by , with the mean activation magnitude and grid-searched, so salient channels get the largest factors; the inverse folds into the previous operator. Same form as SmoothQuant, aimed at weight error at W4A16.
- Calibration distribution matters: matched calibration and evaluation data wins, and AWQ reaches good perplexity with a much smaller set than GPTQ-style Hessian methods.
Common mistakes · 3
- Calibrating on the evaluation set and reporting the error there. Calibration data is fitted state; score quality on held-out prompts.
- Treating smoothing as free accuracy. It shifts quantization difficulty into the weights, so weight error rises; the win is that INT8 weights tolerate it better than INT8 activations tolerate outliers.
- Assuming one fits all models. The paper grid-searches per model family, 0.5 for OPT and BLOOM and 0.75 for GLM-130B, because outlier strength differs.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.An activation channel peaks at 100 while most peak near 1. What breaks under per-tensor INT8 activation quantization?Answer
The single scale stretches to the outlier, so the bulk rounds to a few codes near zero. Per-channel smoothing or per-token dynamic ranges contain the damage.
2.Why is the SmoothQuant transform mathematically equivalent before rounding?Answer
It inserts between activation and weight. The product is unchanged; only the rounding that follows sees friendlier ranges.
3.Static activation scales calibrated on chat prompts now serve code. What symptom appears?Answer
Clipping or coarse steps on unseen magnitude patterns, hence quality drift. Recalibrate on the serving distribution or switch that tensor to dynamic ranges.
4.How do AWQ and SmoothQuant differ in what they protect?Answer
AWQ scales all weight input channels by factors derived from activation magnitudes, largest on the salient ones, protecting weight rounding. SmoothQuant scales down outlier activation channels, protecting activations at some cost to weight error.
Practice
- 100 Days of LLM Inference Day 14: SmoothQuant and AWQ cells
Experiments: Try These in
day14/quantization-gptq-awq-smoothquant.ipynb: runsmoothquant_calibrateandawq_get_scaleson a layer with a planted outlier channel and compare output error against naive round-to-nearestReport error per method on held-out inputs, and state which scales are static and which would need runtime statistics.
You're done when
You derive the migration factor from channel maxima, show the unchanged product on one layer, and can say for each scale in your pipeline whether it is static or dynamic and what data fixed it.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 9 more in the section
- MIT 6.5940 TinyML and Efficient Deep Learning Computing - Quantization LecturesMIT Han Lab · required
Use Lectures 5 and 6 for quantization fundamentals and Lecture 13, Efficient LLM Deployment, for SmoothQuant and AWQ with TinyChat. Implement a small affine quantizer and an outlier experiment before using a pre-quantized checkpoint.
- SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language ModelsMIT and NVIDIA · required
Study activation outliers and the offline smoothing transformation. Reproduce the algebra on one linear layer and compare calibration-sensitive quality with an unmodified reference.
- AWQ: Activation-Aware Weight Quantization for LLM Compression and AccelerationMIT Han Lab · required
Focus on salient-weight protection, group scaling and the distinction between simulated quality and real kernel speed. Compare one supported AWQ path with the same unquantized workload.
- 100 Days of LLM Inference - Days 13, 14 and 15Elizabeth Thomas · support
Use the numeric-format, quantization-algorithm and speculative-decoding notebooks as compact preparation. Keep their synthetic demos separate from production-engine and hardware evidence.
Also in this section
- Hands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)Chi Wang and Peiheng Hu (O'Reilly) · primary
Read "Model Compression" in Chapter 6 for quantization and "Speculative Decoding" in Chapter 7, with its hands-on example. For each method write its correctness contract, the engine support it needs and a predicted winning and losing workload before running it.
- Fast Inference from Transformers via Speculative DecodingDeepMind · required
Derive acceptance and correction probabilities and implement the exact categorical simulator. Prove distributional equality on tiny distributions before adding a model or engine.
- AI Systems Performance Engineering - Chapters 15 and 16, speculation and quantizationChris Fregly (O'Reilly) · support
Read "Speculative Decoding and Parallel Token Generation Techniques" in Chapter 15 (draft models, EAGLE, self-speculation, Medusa) and "Quantization Approaches for Real-Time Inference" in Chapter 16.
- vLLM Speculative Decoding and Quantization (v0.31.0)vLLM Project · required
Use the speculative decoding page for the supported proposers (draft model, n-gram, EAGLE, MTP) and its losslessness notes, and the quantization page for the hardware support table. Check every method against your GPU's compute capability before planning a run.
- AI Systems Performance Engineering companion code - Chapters 16, 18 and 19 labsChris Fregly · required
Use Chapter 16 AWQ, GPTQ and SmoothQuant pairs, Chapter 18 speculation sweeps and Chapter 19 dynamic quantized cache. Run one family at a time, require quality or numerical parity, and regenerate results on available hardware.
- TensorTonic Language Modeling from Scratch - Perform Exact Speculative SamplingTensorTonic · support
Solve after the acceptance-rule unit, then check your implementation's output distribution against the target by exact enumeration on a tiny vocabulary.
- LLM Inference: From scratch, one token at a time - Module 08Tushar Amrit · support
Work the Speculative Decoding module's acceptance arithmetic and checkpoint before the speedup-model unit.
- AI Performance Engineering - Quantization and Speculative DecodingWafer · reference
A curated index. Use Section 4 only to find a quantization or speculation paper the other entries lack.
- Inference Engineering - Section 5.1, QuantizationPhilip Kiely (Baseten Books) · support
Read 5.1.1 Number Formats for the format table and Precision/Type/Scale-factor with Dynamic range/Granularity, 5.1.2 for PTQ versus QAT and the what-to-quantize decisions, and 5.1.3 for the perplexity, benchmark and custom-eval quality checks.