Unit 2 of 12 · about 4 hours · derive, implement
Symmetric and asymmetric quantization, scales, zero points and granularity
Every quantized serving path is this map plus metadata. If you cannot predict what a scale does to small values, calibration and method comparisons stay mysterious.
You'll be able to
- Derive symmetric and asymmetric quantize and dequantize maps, with scale, zero point and clipping.
- Compute representable range and worst-case rounding error for a stated width and granularity.
- Implement per-tensor, per-channel and grouped affine quantization on a small tensor and report error per choice.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Day 13 Part 1: scale and zero point100 Days of LLM Inference - Days 13, 14 and 15
Notebook
day13/quantization-number-formats.ipynb, Part 1 Quantization Math:quantize_symmetric,dequantize_symmetricand the error|x - xhat|cells, with the outliers exercise - Quantization preliminaries: symmetry, static versus dynamic, granularitySmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models
SmoothQuant arXiv:2211.10438v7, Section 2 Preliminaries: symmetric versus asymmetric cases with zero point, static versus dynamic quantization, and per-tensor, per-token, per-channel and group-wise granularity
- Granularity: tensor, channel and block scalesInference Engineering - Section 5.1, Quantization
Section 5.1.1, Number Formats: the Granularity paragraphs (tensor single scale, channel per-vector, block of N values) and the MXFP8, MXFP4 and NVFP4 block sizes
Focus on
- Symmetric maps with and zero point 0. Asymmetric maps use with , rounded and clamped to range.
- One outlier stretches and crushes the bulk: every value below rounds to zero. Clipping the range trades saturation error against rounding error.
- Finer granularity lowers error but adds scale storage. Group-128 INT4 with FP16 scale and zero point adds bits per weight.
- Weights normally take per-channel or grouped scales while activations take per-tensor static or per-token dynamic scales, because activation ranges move with the input.
Common mistakes · 3
- Leaving the zero point unrounded or unclamped. It must be an integer code in range, not a float; otherwise dequantization shifts every value.
- Quoting nominal width as served width. Scales, zero points and alignment padding are real bytes; state effective bits per value.
- Copying per-channel scales to activations. Activation ranges depend on the input, so static per-channel activation scales go stale while per-token dynamic scales track them.
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.What are the symmetric INT8 scale and codes for ?Answer
Scale . Then 100 maps to 127 and dequantizes to 100.0, and any value below about 0.39 maps to 0.
2.For range in asymmetric INT8, what are the scale and zero point?Answer
Scale and zero point . Real zero maps exactly to code 7. The symmetric map also represents zero exactly, at code 0; the asymmetric gain is using the full code range on a skewed interval.
3.Why does one outlier destroy small values under a per-tensor scale?Answer
The outlier sets , so the step dwarfs small magnitudes. Splitting the range into groups or channels gives the bulk its own smaller step.
4.Group-128 INT4 stores an FP16 scale and an FP16 zero point per group. What is the overhead?Answer
bits per weight, so the served rate is about 4.25 bits per weight before alignment.
Practice
- 100 Days of LLM Inference Day 13: symmetric pipeline and error
Part 1 cells: extend
quantize_symmetricto an asymmetric variant and to grouped scales, and plot error against groups of 128, 32 and 8 on an outlier tensorScore error on held-out random tensors, not the tensor you used to pick the range.
You're done when
Your blank-file quantizer reproduces the 0.1-to-0 collapse and its grouped fix, and you can state scale, zero point and overhead for any width and group size.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 10 more in the section
- 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.
- 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
- 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.
- 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.
- 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.