Unit 10 of 12 · about 3 hours · explain
N-gram, tree and learned drafters, multi-token heads and structured outputs
The drafter is a cost and acceptance choice, not a leaderboard. Repetitive traffic and open prose want different drafters, and the wrong one is slower than none.
You'll be able to
- Compare n-gram, tree and learned drafters by extra parameters, training cost and typical strength.
- Explain how Medusa heads, EAGLE feature drafting and tree attention differ in what the draft conditions on.
- State the constraint-matching rule for combining structured decoding with speculation.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Module 08: self-speculation surveyLLM Inference: From scratch, one token at a time - Module 08
Concept 04 Self-speculation: the method table (draft model, Medusa, EAGLE, n-gram lookup) with extra parameters, training and strength, and the tree-verification attention-mask sketch
- Choosing and tuning draftersHands-On LLM Serving and Optimization - Quantization (Chapter 6) and Speculative Decoding (Chapter 7)
Chapter 7, Tuning and Usage (printed pp. 235 to 239): Choose an existing small model, Use self-drafting with Medusa heads and EAGLE variants, the N-gram subsection with the n equals 3 example, and Tune the number of draft tokens
Read the n-gram-first recommendation as a cost argument, not a quality ranking.
- Draft-based, self-speculative and multi-token decodingAI Systems Performance Engineering - Chapters 15 and 16, speculation and quantization
Chapter 15: Two-Model, Draft-Based Speculative Decoding and EAGLE; Single-Model Self-Speculative Decoding; Multitoken Decoding with Medusa's Multiple Heads; and Constrained Decoding Performance Implications (printed p. 943 on) for the grammar-masking cost that speculation must also pay
- vLLM speculation methods at a glancevLLM Speculative Decoding and Quantization (v0.31.0)
vLLM Speculation Methods list and Method Selection at a Glance table: which methods gain at low versus high QPS and which need a separate draft model
Focus on
- N-gram lookup costs nothing and wins on repetitive text such as code edits, quoted retrieval and fixed schemas. On novel prose it rarely proposes anything usable.
- Medusa attaches independent heads that predict several positions ahead without a second model, verified as a tree. Independence caps accuracy at distance.
- EAGLE autoregresses over the target hidden features with a one-step token shift, so drafts condition on richer state than tokens alone. Later versions add dynamic trees.
- Structured decoding masks the target at every verified position, so output stays exact whatever the draft proposes. Drafts outside the grammar are never accepted (vLLM v0.31.0 trims them to the longest grammar-valid prefix), so mask the draft too or acceptance falls.
Common mistakes · 3
- Deploying a same-size draft. The draft must be an order of magnitude cheaper or its cost ratio erases the yield; a near-target draft is a second target.
- Expecting Medusa heads to condition on each other. They predict independently from one hidden state, which is exactly the gap EAGLE feature autoregression fills.
- Constraining only the target under structured decoding. Output stays exact, but drafts outside the grammar are always rejected, so acceptance collapses; mask the draft with the same grammar.
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.Which drafter do you try first on a retrieval-heavy workload, and why?Answer
N-gram lookup. Answers quote retrieved text, so suffix matches propose well at zero parameter and training cost; measure before buying a trained drafter.
2.What information does an EAGLE draft condition on that a Medusa head does not?Answer
The target hidden-feature sequence with the token sequence shifted one step, autoregressively. Medusa heads predict each future position independently from one hidden state.
3.How does tree attention verify many candidates in one pass?Answer
Each tree node attends only to its ancestors under a masked pass, so one forward pass scores every candidate path and the best accepted path is kept.
4.A grammar constrains the target but the draft proposes freely. What breaks?Answer
Exactness survives, because verification samples from the masked target. Acceptance suffers: drafts outside the grammar are always rejected, so speculation wastes work. Mask the draft with the same grammar.
Practice
- 100 Days of LLM Inference Day 15: n-gram proposer
N-gram Speculation cells: rewrite
ngram_proposefrom its docstring, runsimulate_ngram_speedupon a repetitive prompt and a novel prompt, and report where the free drafter beats a model drafterYour two prompts are the workload model; state which traffic each represents before comparing.
You're done when
You fill the four-row drafter table without notes and can pick the drafter for a stated workload with a cost and acceptance argument.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 9 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.
- 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.
- 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.
- 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 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.