Unit 9 of 12 · about 4 hours · derive
Draft cost, verification cost, accepted tokens and the speedup crossover
Acceptance without cost is a headline. The speedup equation decides the draft length, the draft model and whether to speculate at all under load.
You'll be able to
- Derive expected tokens per verification from acceptance rate and draft length, including the bonus token.
- Predict speedup from draft cost, verification cost and accepted tokens, and find the break-even boundary.
- Explain why batch size moves the crossover, and where speculation stops paying.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Walltime improvement and choosing draft lengthFast Inference from Transformers via Speculative Decoding
Sections 3.3 to 3.5 (walltime improvement, operation counts, choosing ) with the expected-token equation, the draft-cost ratio and the improvement theorem
Treat the paper tables as worked examples on the authors hardware, not as your targets.
- Module 08: acceptance economics and batchingLLM Inference: From scratch, one token at a time - Module 08
Concept 03 Acceptance rate with the yield table and the worked speedup cases at , Concept 05 Why speculation stops working at high batch with the batch table, and Math by hand Parts 2 to 4
- Tuning, limits and the concurrency crossoverHands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)
Chapter 7: Tuning and Usage (printed pp. 235 to 239: draft-token count between 4 and 8, the falling-acceptance example) and Limitations (printed p. 239: decode-only help, large-batch and long-prefill losses)
Focus on
- Expected tokens per verification are . The counts the bonus token; the ceiling as grows is .
- Speedup divides yield by round cost: with draft cost ratio . A bigger draft that raises can still lose if it raises more.
- Acceptance dominates length: at and , , while pushing to 10 gains little. Tune the draft, not the length.
- Batching consumes the same idle arithmetic verification rides on. Past the ridge point the extra positions cost real time and rejected drafts steal compute from real tokens.
Common mistakes · 3
- Maximizing acceptance alone. A 7B draft for a 13B target at , and lands near 1.17x; the ratio is the metric.
- Importing a published . Acceptance moves with domain, temperature and position; measure it on your workload before sizing .
- Enabling speculation at high batch. The free-arithmetic argument assumes memory-bound decode; compute-bound batches turn drafts into a tax.
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.Why does the yield formula use instead of ?Answer
A fully accepted round also emits the bonus token from the verification pass final position, so the maximum per round is drafts plus one.
2.With , and , what is the speedup?Answer
tokens per verification divided by cost, about 2.80x.
3.With and at , speculate or not?Answer
Not: against cost 2.20 gives about 0.75x, slower than baseline with identical output.
4.Why does the optimal draft length grow with the acceptance rate?Answer
Higher keeps later positions alive, so extra drafts still convert. At low late drafts are usually discarded, adding cost without yield.
Practice
- Tushar Module 08 code lab: speedup surface
Code lab Parts B and C: build the yield and speedup tables, find the optimal per row, and locate the batch size where your ridge calculation crosses
Use your own arithmetic-intensity numbers from the prefill-decode units, not the module H100 example.
You're done when
You derive yield and speedup for a new triple without notes and can name the batch regime where your deployment stops speculating and why.
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.
- 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.
- 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.
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.
- 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.
- 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.
- 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.
- 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.