Quantization and Speculative Decoding
Low precision and speculative execution change memory, kernels, quality and request state. Both need a correctness contract and measured crossover region, not a nominal bit width or acceptance-rate headline.
Section 6 of 9 · 12 units · about 48 hours
By the end you can Show numerical or task-quality correctness for one quantized path and distributional correctness for exact speculation, then identify a measured win and loss region for each mechanism with safe fallback.
Units
- Inference number formats and what gets quantized4h
- Symmetric and asymmetric quantization, scales, zero points and granularity4h
- Calibration, observers, outliers and activation smoothing4h
- Packing overhead, accumulator precision and fused dequantization kernels4h
- Post-training and quantization-aware methods, and quality checks by slice4h
- Measuring quantized memory, latency and throughput, including KV quantization3h
- Draft and target roles, exact acceptance and the correction distribution5h
- Cache advance, rollback, stop handling and tokenizer compatibility4h
- Draft cost, verification cost, accepted tokens and the speedup crossover4h
- N-gram, tree and learned drafters, multi-token heads and structured outputs3h
- A deterministic distribution simulator and distributional equivalence tests4h
- Engine integration, versioned fallback, and benefit and loss regions5h
Build it
Mini project · about 12 to 18 hours
Quantized and speculative paths with measured win regions
Build blank-file quantization with calibration and method comparisons, plus a seeded speculative simulator with exactness, rollback and drafter evidence. Integrate one path into engine/ behind a versioned config and map measured benefit and loss regions with quality held.
- 1Implement symmetric and asymmetric quantize and dequantize maps with per-tensor, per-channel and grouped scales from a blank file, derive served bits per weight with scale overhead, and run the Day 13 number-format and symmetric-pipeline experiments on outlier tensors.
- 2Calibrate static ranges on sample data, apply the SmoothQuant migration and activation-aware scaling on a layer with a planted outlier channel, and compare naive rounding against GPTQ, AWQ and SmoothQuant on held-out inputs with Day 14 cells.
- 3Derive served bits for your packing layout with alignment and the accumulator contract, then measure a quantized path against its baseline on your GPU for memory, TTFT, TPOT and throughput beside slice quality, with the Chapter 19 cache pair as a second check.
- 4Prove the acceptance rule preserves the target distribution, build a seeded speculative simulator with separate draft, accept and residual steps, match the Day 15 acceptance rows, which omit the bonus token, within noise, fail the naive rule visibly, and pass the TensorTonic speculative-sampling cases.
- 5Add KV advance with truncate-to-prefix rollback, stop handling and tokenizer checks to the simulator; build yield and speedup tables with the Module 08 lab to pick draft length and the stop regime; and compare the n-gram proposer on repetitive against novel prompts.
- 6Integrate one quantized or speculative path into
engine/behind a versioned configuration with a tested fallback, then map benefit and loss regions across batch size and sequence length with quality held, attributing each region to acceptance, cost, kernel coverage or scheduler interaction.
What you hand in
- Blank-file quantizers with scale proofs, calibration evidence and the method comparison on held-out inputs.
- The speculative simulator with exactness, rollback, stop and TensorTonic evidence plus yield and drafter tables.
- The integrated path with versioned config, fallback drill and the benefit and loss map with quality held.
How to check it
- Self-grade with the rubric below
- TensorTonic: Perform Exact Speculative Sampling
Pass the public sampling cases and state the bonus-token contract difference first.
How it's graded
Quantization maps
Pass: Blank-file symmetric and asymmetric maps round-trip on outlier tensors, and served-bits math includes scale overhead.
Great: Grouped scales rescue small values in a shown collapse, and block-size error tables defend the layout choice.
Method comparison
Pass: Calibration, smoothing and scaled methods beat naive rounding on held-out inputs with static against dynamic ranges named.
Great: A stale-calibration case shows the drift symptom and the recalibration or dynamic-range fix.
Speculative exactness
Pass: The simulator matches the target within noise, fails the naive control, and rollback leaves entries only for accepted tokens.
Great: Target-only processing and grammar-masked targets stay exact with measured acceptance drops explained.
Measured regions
Pass: Baseline and integrated paths share prompts, sampling and cache state, and benefit and loss regions carry quality evidence.
Great: Each region names its mechanism and bottleneck shift, and fallback flips under load with baseline outputs restored.
Resources
- Hands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)Chi Wang and Peiheng Hu (O'Reilly)
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
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
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
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
Derive acceptance and correction probabilities and implement the exact categorical simulator. Prove distributional equality on tiny distributions before adding a model or engine.
- vLLM Speculative Decoding and Quantization (v0.31.0)vLLM Project
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
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.
- AI Systems Performance Engineering - Chapters 15 and 16, speculation and quantizationChris Fregly (O'Reilly)
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.
- 100 Days of LLM Inference - Days 13, 14 and 15Elizabeth Thomas
Use the numeric-format, quantization-algorithm and speculative-decoding notebooks as compact preparation. Keep their synthetic demos separate from production-engine and hardware evidence.
- TensorTonic Language Modeling from Scratch - Perform Exact Speculative SamplingTensorTonic
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
Work the Speculative Decoding module's acceptance arithmetic and checkpoint before the speedup-model unit.
- Inference Engineering - Section 5.1, QuantizationPhilip Kiely (Baseten Books)
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.
- AI Performance Engineering - Quantization and Speculative DecodingWafer
A curated index. Use Section 4 only to find a quantization or speculation paper the other entries lack.