Unit 1 of 12 · about 4 hours · explain, derive
Inference number formats and what gets quantized
Precision sets the memory floor for every later decision. A plan that confuses nominal bits with served bytes mispredicts capacity by gigabytes.
You'll be able to
- Explain how INT8, INT4, FP8 and microscaled FP4 trade dynamic range against storage, and where each sits in a serving path.
- Derive weight memory for a dense model under FP16, INT8 and INT4, and state which tensors the count covers.
- Distinguish weight-only, weight-activation and KV quantization by what gets smaller, what gets faster and what still needs high precision.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Quantization: formats and where they helpHands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)
Chapter 6, Model Compression: Quantization (printed pp. 206 to 213): Storing numbers with Table 6-1, How does quantization help in model serving with Table 6-2, and Weight-only versus weight-and-activation quantization strategies with the Marlin and Machete kernels
Skip the hands-on quantization commands and the Qwen walkthrough here; they belong to the measurement unit. Table 6-2 lists the H100 SXM Tensor Core peaks with sparsity (dense rates are half), and its line that 4-bit weights double FLOPS again does not hold for weight-only formats, which compute in 16-bit.
- Number formats, range and granularityInference Engineering - Section 5.1, Quantization
Section 5.1.1, Number Formats: the format table with first architecture, then Precision, Type and Scale factor, then Dynamic range and Granularity
- Day 13: number formats from scratch100 Days of LLM Inference - Days 13, 14 and 15
Notebook
day13/quantization-number-formats.ipynb: Part 1 Quantization Math (scale and zero point), Part 2 Memory Savings and Throughput Impact, Part 3 FP8, Part 4 NVFP4
Focus on
- INT formats spread levels evenly while FP formats spend bits on exponent range. Activations with outliers therefore usually lose less in FP8 E4M3 than in INT8 under one per-tensor scale.
- W4A16 means 4-bit weights with 16-bit activations. Weight-only quantization shrinks storage and weight traffic but still computes in high precision after dequantization.
- Weight-activation quantization can raise compute throughput, but only where a kernel for the exact pair exists on your GPU. A format without kernel support is storage only.
- KV quantization targets capacity and decode traffic, not prefill FLOPs. Without a quantized attention kernel the values are dequantized back before the dot product.
Common mistakes · 3
- Reading H100 FP8 throughput as a portable speedup. FP8 Tensor Cores need compute capability 8.9 or higher (Ada, Hopper and later); on Ampere, vLLM runs FP8 checkpoints as weight-only Marlin, so the W8A8 speedup does not exist there.
- Counting 4 bits per weight. Group scales, zero points and alignment push the served rate above nominal; NVFP4 lands near 4.5 effective bits per weight (an 8-bit scale per 16 values) before its per-tensor global scale.
- Expecting KV quantization to cut prefill time. It cuts capacity and decode traffic; a latency win needs a quantized attention kernel alongside it.
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.A 7B model needs 14 GB for weights in FP16. What do INT8 and INT4 need, and what is missing from both numbers?Answer
7 GB and 3.5 GB. Both omit scale and zero-point storage, alignment padding, and the KV cache and activations.
2.Why does FP8 E4M3 suit spiky activations better than INT8 at the same width?Answer
Its exponent bits give wide dynamic range for outlier magnitudes. INT8 spreads levels evenly, so one scale either saturates on the outlier or crushes small values.
3.A weight-only INT4 model shows slower first-token latency than the FP16 baseline at high concurrency. What mechanism explains it?Answer
Weights are dequantized to 16-bit before compute, so prefill arithmetic does not shrink while dequantization overhead is added. Weight-only quantization buys memory and decode bandwidth, not compute.
4.The KV cache is quantized but attention still runs in FP16. What happens each step?Answer
Values are dequantized back before the dot product. Capacity falls but arithmetic cost does not; keep this separate from a quantized-attention speedup.
Practice
- 100 Days of LLM Inference Day 13: number-format experiments
Try These Experiments in
day13/quantization-number-formats.ipynb: run the FP8, INT8, INT4 and NVFP4 cells and record error per format with the memory model from ReproduceTreat the notebook numbers as implementation checks on tiny tensors, not as serving evidence.
You're done when
You derive the three weight-memory numbers without notes and can say for each of W4A16, W8A8 and FP8 KV which traffic shrinks and which kernel the speedup needs.
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.