Unit 5 of 12 · about 4 hours · explain, measure
Post-training and quantization-aware methods, and quality checks by slice
A smaller model that fails the quality contract can never ship. Methods differ in what they cost to apply; checks differ in what they can catch.
You'll be able to
- Contrast post-training quantization with quantization-aware training by data, pipeline access and accuracy cost.
- Check a quantized model with perplexity, a task benchmark and a workload slice, and state what each check can hide.
- Rank weights, activations, KV cache and attention by quantization sensitivity and defend a mixed-precision sketch.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Approaches and quality measurementInference Engineering - Section 5.1, Quantization
Section 5.1.2, Quantization Approaches: PTQ versus QAT definitions, the two decisions (what parts, what format), and the least-to-most sensitivity ordering from weights to attention; Section 5.1.3, Measuring Quality Impact: perplexity, intelligence benchmarks and custom evals
- Accuracy trade-offs and evaluation toolingHands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)
Chapter 6: Accuracy trade-offs with the GPTQ, AWQ and FP8 minimal-loss results, Quantization-aware training versus PTQ with the comparison table, and the LM Eval code snippet for gsm8k_cot
Treat the book accuracy figures as the authors result on their models, not as your expected result.
- Day 14: comparing GPTQ, AWQ and SmoothQuant100 Days of LLM Inference - Days 13, 14 and 15
Notebook
day14/quantization-gptq-awq-smoothquant.ipynb: Comparing Quantization Methods and Experiments: Try These, comparing output error ofgptq_quantize_layer,awq_quantizeandsmoothquant_calibrateagainst naive round-to-nearest
Focus on
- PTQ converts finished weights with calibration data only; QAT trains or fine-tunes with fake quantization so weights adapt to the rounding. PTQ is the only option for weights you did not train.
- Perplexity is the cheapest check but the weakest: it scores likelihood on reference text, not task success. Add one task benchmark and one product slice before any ship claim.
- Sensitivity runs weights, then activations, then KV cache, then attention with softmax last. Early and late layers often stay in high precision inside an otherwise quantized model.
- GPTQ compensates rounding with Hessian structure, AWQ protects salient channels, SmoothQuant migrates outlier difficulty. All three report near-FP16 quality at W4A16 or W8A8 on the authors workloads; yours needs its own numbers.
Common mistakes · 3
- Reporting pooled perplexity only. Averages hide slice regressions; long context, code and other languages can degrade while prose perplexity barely moves.
- Quoting paper quality as your quality. Published minimal-loss results are the authors models on their evals; calibration and slice differences move them.
- Treating QAT as strictly better. It costs pipeline access and retraining; for many deployments calibrated PTQ meets the bar and ships sooner.
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.When is QAT unavailable no matter how attractive its accuracy looks?Answer
When you hold only finished weights without training-pipeline access. PTQ with calibration is then the only route; QAT needs fake quantization during training or fine-tuning.
2.Quantized perplexity rises minimally but the product slice fails. What did the check miss?Answer
Perplexity measures likelihood on reference sequences, not task behavior. The slice exercises distributions the reference set underweights; add task and slice evals.
3.Rank weights, activations, KV cache and attention by quantization sensitivity, least first.Answer
Linear-layer weights, then activations, then KV cache, then attention with softmax. Errors in attention compound token to token, and KV errors persist across positions.
4.Why might input and output layers stay in high precision?Answer
They are more sensitive than middle layers: the input layer shapes every downstream representation and the output layer directly sets token probabilities.
Practice
- 100 Days of LLM Inference Day 14: method comparison
Comparing Quantization Methods and Experiments: Try These: benchmark naive round-to-nearest against
gptq_quantize_layer,awq_quantizeandsmoothquant_calibrateon one layer, reporting error per methodUse a fixed held-out input batch for all four; the calibration inputs must not be the scoring inputs.
You're done when
You rank the four components by sensitivity without notes and can say for a stated workload which two quality checks gate the ship decision and why perplexity alone does not.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 10 more in the 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.
- 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.
- 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.
Also in this 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.
- 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.