TAI BUI
Back to curriculum
BuildPython

Speculative Decoding and EAGLE-3

Phase 7 · Lesson 16 proved the math: the Leviathan rejection rule preserves the verifier's distribution exactly. This lesson covers the training side of 2026 production speculative decoding. EAGLE-3 turned the draft model from a cheap approximation into a tiny network trained on the verifier's own hidden states, then added a training-time test loop that aligns its train and inference distributions. The result is a 3× to 6.5× end-to-end speedup and per-token acceptance rates above 0.9 on chat, with no change to the output distribution. vLLM and SGLang default to it when a trained draft is available.

TIME: ~75 minutesPREREQUISITES: Phase 7 · 16 (speculative decoding math), Phase 10 · 12 (inference optimization)

Learning Objectives

  • State the Leviathan theorem in one sentence and explain why the rejection rule plus residual sampling produces samples distributed exactly as the verifier.
  • Walk the two-year progression from vanilla spec-decoding (Leviathan 2023) through EAGLE, EAGLE-2, and EAGLE-3 and name the exact limitation each step removed.
  • Compute expected speedup from acceptance rate `α` and draft-to-verifier cost ratio `c`, and choose the optimal draft length `N` for each regime.
  • Implement the full speculative loop from scratch: draft, verify, reject-sample from the residual, roll the KV cache back on rejection, emit the bonus token on full acceptance.

The Problem

Autoregressive decoding on a 70B model runs at maybe 35 tokens per second on an H100. The GPU is nowhere near saturated. Memory bandwidth is the ceiling: every token loads 70B of weights from HBM, does one step of arithmetic, and produces one float. The compute units sit mostly idle.

Speculative decoding turns that into a throughput problem you can actually solve. A cheap draft proposes N tokens in N small forward passes. The verifier runs once on the prefix plus all N drafts. If the verifier's distribution at position i agrees with the draft (in a statistical sense we will make precise), we accept; if not, we reject and sample a correction from the residual distribution. A single big-model forward produces up to N+1 accepted tokens instead of one.

The theorem that matters is Leviathan, Kalman, Matias (ICML 2023): the output distribution is identical to what sampling from the verifier directly would have produced. Not approximately, but exactly. That is why speculative decoding is acceptable in production: it is a pure latency optimization with no quality tradeoff.

Phase 7 · Lesson 16 gave you the math. This lesson gives you the training stack. A good draft is worth 2× more speedup than a cheap one, and EAGLE, EAGLE-2, and EAGLE-3 (Li et al., 2024-2025) turned "draft = smaller version of the same model" into a precise engineering discipline. In 2026, vLLM and SGLang default to EAGLE-3 when a trained draft exists.

Warm-up0/3
1. Why is decoding one sequence on a large model usually limited by memory bandwidth rather than compute?Warm-up
A large weights box on the left, described as billions of numbers read from memory, with an arrow into a small plus-shaped box labelled one step. A caption says producing the next token re-reads the weights and does one small step of math. A question asks which of the two usually sets the pace.
Setup only, from the stem; which resource is the bottleneck is the question.
2. Why does a transformer decoder keep a KV cache while generating text one token at a time?Warm-up
A row of early token boxes, tok 1, tok 2, tok 3, an ellipsis, with an arrow sweeping from a tok 50 box, being made now, back over the earlier range. A question asks, without saving anything from before, what would have to happen again for every new token.
Setup only, from the stem; what gets saved and reused is the question.
3. What does raising the sampling temperature do to a model's next-token distribution?Warm-up
Two identical small bar charts of five token probabilities side by side, with a question mark and the words turn the knob up in between. A line asks what shape raising the temperature knob gives the second distribution.
Setup only; the starting distribution is illustrative and the resulting shape is the question.
Check: The Problem0/1
1. Why does one verifier forward over the prefix plus N drafts cost little more than a single-token step?Explain
Two boxes: an ordinary decode step, loading the weights for 1 new position, and a verify step, loading the same weights for 1 plus N positions in one pass. A question asks why the verify step costs so little more despite the extra positions.
The 1-new-position versus 1-plus-N-position framing matches the stem; why the extra cost is small is the question.

The Concept

The invariant: Leviathan rejection sampling

Let p(t) be the draft's distribution for the next token given some prefix, and q(t) be the verifier's. Sample a draft token d ~ p. Accept with probability min(1, q(d) / p(d)). On reject, sample from the residual distribution (q - p)_+ / ||(q - p)_+||_1. The resulting samples are distributed according to q. This is true regardless of how bad p is. The worse it is, the more often you reject, but the output stays exact.

Stack N of these calls back to back using one verifier forward pass on prefix + d_1 + ... + d_N. The verifier returns q_1, q_2, ..., q_{N+1} simultaneously. Walk left to right. On the first rejection at position j, sample from residual(q_j, p_j) and stop. On full acceptance, sample one bonus token from q_{N+1}.

What determines speedup

Let α be the expected acceptance rate per drafted token. Let c = cost(draft) / cost(verifier) be the cost ratio. The expected number of accepted tokens per verifier forward is:

E[accepted] = (1 - α^(N+1)) / (1 - α)

The expected total wall time per accepted token is (N * c + 1) / E[accepted]. Minimize that with respect to N and you get the sweet spot. For α = 0.8, c = 0.05: optimal N is about 8, speedup is about 3.1×. For α = 0.95, c = 0.02 the curve is still climbing at N = 10 (7.2×) and only flattens near N = 30 (about 10×). This formula charges nothing for the verifier growing with N, so treat a large optimum as an upper bound.

The single biggest lever is α. Going from α = 0.6 (vanilla draft) to α = 0.9 (EAGLE-3) at fixed N = 5 takes you from 2.4 expected accepted tokens per verifier forward to 4.7. Nearly 2× more throughput from the same verifier.

The two-year progression

Vanilla speculative (Leviathan, 2023). Draft model is an independently trained smaller LLM from the same family. Easy to wire up, α ≈ 0.6, speedup around 2× at best.

EAGLE-1 (Li et al., 2024). Draft is a tiny transformer, typically one or two layers, that takes the verifier's last-layer hidden state as input and predicts the next token directly. Because the draft sees the verifier's feature representation, its distribution is much closer to the verifier's. α climbs to 0.7–0.8.

EAGLE-2 (Li et al., 2024). Adds a dynamic draft tree: instead of proposing a single sequence of N tokens, propose a small tree of candidates, score each with the verifier in one forward pass (tree attention), and walk the highest-probability path. Draft length becomes adaptive per step. α per accepted-path token climbs above 0.85.

EAGLE-3 (Li et al., 2025, NeurIPS). Two more changes. First, drop the feature-prediction loss entirely. EAGLE-1/2 trained the draft to match the verifier's hidden states, which caps how much data helps. EAGLE-3 trains directly on token prediction. Second, training-time test (TTT): during draft training, feed the draft's own previous predictions back as inputs over multiple steps, the same way it operates at inference. This aligns the train and test distributions and stops error accumulation. Measured speedup: up to 6.5× on chat, 38% throughput improvement at batch 64 in SGLang on H100.

KV cache rollback

Verification extends the verifier's KV cache by N entries in one pass. If rejection happens at position j, the cache contents past position j-1 are now wrong. Two common implementations: write to a scratch buffer and commit on acceptance (vLLM, TensorRT-LLM), or keep a physical KV cache plus a logical length and truncate on reject. Either way, the rollback cost is bytes per layer per head, which is negligible next to the forward-pass cost.

For EAGLE-2 tree search, the verifier runs attention with a non-causal mask that respects tree topology. The engineering is fiddly but the computation is a standard flash-attention call with a custom mask.

Draft architectures in 2026

StrategyDraft typeαSpeedupTraining cost
VanillaSeparate small LLM0.55-0.701.8-2.3×None (reuse existing small model)
MedusaExtra LM heads on verifier0.65-0.752-3×~1B SFT tokens
EAGLE-11-layer transformer on hidden states0.70-0.802.5-3×~60B tokens
EAGLE-2EAGLE-1 + dynamic draft tree0.80-0.883-4×~60B tokens
EAGLE-3Multi-layer feature fusion + TTT0.88-0.923.5-6.5×~60-200B tokens
LookaheadNo draft (Jacobi iteration)N/A1.3-1.6×None

In 2026 production: vLLM and SGLang default to EAGLE-3 when available, EAGLE-2 otherwise. TensorRT-LLM has the fastest Medusa path for Meta and NVIDIA public models. llama.cpp ships vanilla draft for CPU deployments.

Check: The Concept0/25
1. What is the Leviathan rule?Define
A term card reading The Leviathan rule, from the Concept section (the invariant), with a context note: Context: a draft token d has just been sampled from the draft's distribution p. A question asks: What test decides whether to accept d?
The term as the lesson names it; its mechanism is the question.
2. What is the residual distribution used when a drafted token is rejected?Define
A term card reading Residual distribution, from the Concept section (the invariant), with a context note: Context: a drafted token has just failed the accept test. A question asks: What distribution does the correction token get sampled from?
The term as the lesson names it; its mechanism is the question.
3. What does the acceptance rate α measure?Define
A term card reading Acceptance rate α, from the Concept section (What determines speedup), with a context note: Context: every drafted token either passes or fails the rejection rule. A question asks: What does α measure?
The term as the lesson names it; its mechanism is the question.
4. What is EAGLE-1?Define
A term card reading EAGLE-1, from the Concept section (the two-year progression), with a context note: Context: one of several ways to build the draft model. A question asks: What is it?
The term as the lesson names it; its mechanism is the question.
5. What does EAGLE-2 add on top of EAGLE-1?Define
A term card reading EAGLE-2, from the Concept section (the two-year progression), with a context note: Context: EAGLE-1 already conditions its draft on the verifier's hidden state. A question asks: What does EAGLE-2 add on top of that?
The term as the lesson names it; its mechanism is the question.
6. Which change separates EAGLE-3 from EAGLE-1 and EAGLE-2 in training?Define
A term card reading EAGLE-3, from the Concept section (the two-year progression), with a context note: Context: EAGLE-1 and EAGLE-2 both train their draft with a feature-prediction loss. A question asks: Which change to training separates EAGLE-3 from both?
The term as the lesson names it; its mechanism is the question.
7. What is training-time test (TTT)?Define
A term card reading Training-time test (TTT), from the Concept section (the two-year progression), with a context note: Context: a draft network is being trained to predict tokens. A question asks: What is TTT?
The term as the lesson names it; its mechanism is the question.
8. What is KV rollback?Define
A term card reading KV rollback, from the Concept section (KV cache rollback), with a context note: Context: a drafted token was just rejected, after the verifier already extended its cache by N entries. A question asks: What is KV rollback?
The term as the lesson names it; its mechanism is the question.
9. What is the bonus token?Define
A term card reading Bonus token, from the Concept section (the invariant), with a context note: Context: all N drafted tokens in one round were accepted. A question asks: What is the bonus token?
The term as the lesson names it; its mechanism is the question.
10. What is tree attention?Define
A term card reading Tree attention, from the Concept section (EAGLE-2), with a context note: Context: the draft has proposed a small tree of candidate continuations, not one chain. A question asks: What is tree attention?
The term as the lesson names it; its mechanism is the question.
11. Speculative decoding samples draft tokens from p and verifies them against the verifier's distribution q. What does it guarantee about the output distribution?Define
A draft box sampling a token from p, feeding into a verifier box that runs the rejection test against q. A question asks what the output token distribution ends up being after many rounds of this.
The draft-then-verify setup is the lesson's own description; what distribution results is the question.
12. What is the expected number of tokens produced per verifier forward pass with draft length N and acceptance rate α?Define
A verifier-forward box that sees N drafted positions, with N labelled as the draft length and alpha labelled as the acceptance rate. A question asks for the number of tokens emitted this forward, left as a question mark.
N and alpha are the lesson's own named quantities; the expression relating them is the question.
13. Which row of the Draft architectures table lists no draft and no training cost?Explain
A six-row table transcribed from the lesson's Draft architectures table, showing Draft type and Training cost for every strategy with the Strategy name column blanked out as a question mark in every row. A question asks which row's strategy name has no draft and no training cost.
Draft type and Training cost columns are transcribed verbatim from the lesson's own table; the Strategy name is masked in every row so the picture does not single one out.
14. Why does an EAGLE-1 draft reach a higher α than a vanilla draft?Explain
Two boxes: a vanilla draft, a separate small LLM using only its own weights, and an EAGLE-1 draft, a tiny transformer whose input is left as a question mark. A question asks what EAGLE-1's missing input gives it, given that it reaches a higher acceptance rate than vanilla.
The vanilla baseline is the lesson's own description; EAGLE-1's distinguishing input is the question.
15. Which limitation of EAGLE-1 does the EAGLE-2 draft tree remove?Explain
Two boxes: EAGLE-1, proposing one chain of N tokens, and EAGLE-2, with what it proposes left as a question mark. A question asks which limitation of the one-chain approach EAGLE-2's change removes.
EAGLE-1's one-chain draft is the lesson's own description; EAGLE-2's change is the question.
16. Why does feeding the draft its own predictions during training help at inference?Explain
Two boxes: plain training, fed ground-truth tokens as input, and inference, fed the draft's own earlier predictions as input. A question asks why also feeding the draft its own predictions during training is supposed to help.
The two different input diets are the lesson's own description of the train/inference mismatch; why fixing it helps is the question.
17. What does the cost ratio c = cost(draft) / cost(verifier) change in the speedup math?Explain
A formula panel reading wall time per token equals (1 plus N times c) divided by the expected number of accepted tokens. A question asks what making c smaller changes about this formula.
The formula is transcribed from the Concept section's What determines speedup; the effect of a smaller c is the question.
18. Why should a large optimal N from the formula be read as an upper bound?Explain
A formula panel reading cost per call equals N times c plus 1, with a note that the 1, representing the verifier pass, is modeled as fixed size. A question asks why a large optimal N from this formula should be treated as an upper bound rather than the real answer.
The cost-per-call formula and its fixed verifier term are transcribed from the Concept section; why that makes the optimum an upper bound is the question.
19. Why is the cost of KV rollback negligible in the speedup math?Explain
Two boxes: KV rollback, resetting a length or dropping a scratch buffer, and one verifier forward pass, touching every weight matrix in every layer. A question asks why rollback costs so little next to a forward pass, whether rejections are common or rare.
Both operations are the lesson's own description of what rollback and a forward pass each touch; why the cost gap is so large is the question.
20. For α = 0.8 and c = 0.05, what draft length N and speedup does the Concept section's formula give?Apply
A formula panel giving alpha = 0.8 and c = 0.05, with the best draft length N and the speedup at that N left as question marks.
alpha = 0.8 and c = 0.05 are the stem's own figures, matching the Concept section's worked example.
21. A team's vanilla draft has α = 0.6 and they run N = 5. They swap in an EAGLE-3 draft at α = 0.9 with the same N and verifier. Roughly how many tokens does each verifier forward now produce?Apply
Two boxes: a vanilla draft at alpha 0.6, N 5, and an EAGLE-3 draft at alpha 0.9, N 5, the same N and verifier in both cases. A question asks roughly how many tokens each verifier forward now produces, before versus after the swap.
Both alpha values and N = 5 are the stem's own figures.
22. With α = 0.5 and N = 3, what is E[accepted] per verifier forward?Apply
A formula panel giving alpha = 0.5 and N = 3, with E[accepted] left as a question mark.
alpha = 0.5 and N = 3 are the stem's own figures.
23. A teammate simplifies the rejection branch: on reject, the correction token is sampled from q instead of the residual (q - p)_+. What happens to the output?Analyze
Two boxes: an unchanged accept rule, min(1, q(d)/p(d)), and an edited reject branch that samples the correction from q instead of the residual (q-p)+. A note gives an illustrative example, q = (0.5, 0.5), p = (0.9, 0.1). A question asks what happens to the output distribution with this edit.
q = (0.5, 0.5) and p = (0.9, 0.1) are the worked example from this question's own explanation; the resulting distribution is left for the resolved view.
24. A draft is trained only on ground-truth inputs and looks good offline, but its acceptance falls over several drafted steps. Which change targets this?Analyze
Two boxes: evaluated offline, fed ground-truth tokens and looking good, and run over several steps, fed its own earlier predictions, where acceptance falls. A question asks which training change targets this specific gap between the two columns.
Both the offline evaluation and the multi-step production behavior are given directly in the stem.
25. You need a speedup but have no small same-family model and no budget to train a draft. Which strategy fits?Design
Two boxes, both labelled don't have: a small model from the same family, and budget to train a new draft network. A question asks which strategy still fits given both constraints at once.
Both constraints, no same-family model and no training budget, are given directly in the stem.

Build It

main.py is the full Leviathan speculative loop in stdlib Python: draft N tokens, verify them in one parallel pass, apply the rejection rule per position, sample from the residual on rejection, emit a bonus token on full acceptance, and track KV rollback. It then checks empirically that the output distribution matches direct sampling from q. The snippets below are illustrative. main.py inlines the rejection test inside spec_step.

Step 1: the rejection rule

python
def accept(q_prob, p_prob, u):
    if p_prob <= 0:
        return True
    return u < min(1.0, q_prob / p_prob)

Step 2: residual distribution

python
def residual(q, p):
    raw = [max(0.0, qi - pi) for qi, pi in zip(q, p)]
    s = sum(raw)
    if s == 0:
        return list(q)
    return [r / s for r in raw]

Step 3: a full speculative step

The spec_step function drafts N tokens from p, then checks each one against q. It applies the rejection rule left to right, and on the first rejection it samples the correction from the residual and stops. If everything accepts, it emits a bonus token from q. In the toy, q and p are fixed distributions shared across positions, so the "parallel verifier pass" is a lookup. The loop is the same one a real verifier would drive with position-dependent q_i and p_i.

Step 4: KV rollback bookkeeping

The simulator tracks a logical kv_length for the verifier. Each accepted draft adds one to it. On a rejection, the logical length is reset to the prefix length plus the tokens emitted so far, correction included. The physical cache is only notional here, so rollback is a single integer assignment.

Step 5: the Leviathan check

Run 50,000 speculative steps with N=1 and the EAGLE-1-like draft, and count the first emitted token each time. Compare against 50,000 direct samples from q. The script prints the chi-square statistic next to the 95% critical value for 7 degrees of freedom (about 14.07) and a PASS or CHECK verdict. Only the first token is counted because the bonus token is a second draw.

Step 6: speedup vs. α

The script builds three drafts by perturbing q with Gaussian noise at three amplitudes, standing in for a vanilla, an EAGLE-1-class, and an EAGLE-3-class draft, and measures α for each. It then prints two theory tables: expected tokens per verifier call, and wall time per token at c = 0.04, both over a grid of α and N. Read the tables down a column to see what a better α buys at fixed N.

Check: Build It0/10
1. Why does the Leviathan check count only the first emitted token of each step?Explain
Three boxes in a row: a first position, which is either the accepted draft or a correction, later positions, reached only if earlier ones accepted, and a bonus, reached only if all N accept. A question asks why the Leviathan distribution check, which counts only the first position's token, leaves the bonus out.
That the check counts only the first position is given directly in the stem; why the bonus is excluded is the question.
2. In Build It, Step 2, what does `residual(q, p)` return when q and p are identical, so every clamped difference is zero?Apply
An excerpt of the real residual function: it clamps each q minus p difference at zero into raw, sums raw, and when that sum is zero takes a branch whose return value is left as a question mark. A question asks what it returns when q and p are identical, so every raw difference is 0.
Code excerpted from the lesson's main.py, the same function residual() that the lesson calls.
3. After a rejection, what does `spec_step` in Build It, Step 4 set the logical KV length to?Apply
An excerpt of the real spec_step function: it records prefix_len at the start, drafts and checks positions, and on a rejection appends a correction to emitted, then calls kv.truncate_to with an expression left as a question mark. A question asks what expression fills in that call.
Code excerpted from the lesson's main.py, the same function spec_step() that the lesson calls.
4. In Build It, Step 1, what is the literal acceptance test for a draft token d?Apply
An excerpt of the accept function from Build It Step 1: it checks whether p_prob is at most 0 and returns a value left as a question mark, otherwise it returns a comparison of u against an expression also left as a question mark. A question asks what literally goes in each blank to make this the Leviathan rule.
Code transcribed from the lesson's own Build It Step 1 snippet.
5. What does accept(0.3, 0.6, 0.6) return, taking the arguments as q_prob, p_prob, u?Apply
An excerpt of the accept function noting that p_prob 0.6 is not at most 0, so the first branch does not fire, leaving the second return line. A question asks for the result of accept with q_prob 0.3, p_prob 0.6, and u 0.6, left as a question mark.
The accept function is the lesson's own Build It Step 1 snippet; the three argument values are the stem's own numbers.
6. What does accept(0.5, 0.0, 0.99) return?Apply
The same accept function excerpt as Build It Step 1. A question asks for the result of accept with q_prob 0.5, p_prob 0.0, and u 0.99, left as a question mark.
The accept function is the lesson's own Build It Step 1 snippet; the three argument values are the stem's own numbers.
7. What does residual([0.5, 0.3, 0.2], [0.2, 0.2, 0.6]) return?Apply
An excerpt of the real residual function, clamping each q minus p difference at zero into raw and dividing by its sum. A question asks for the result of residual on q = [0.5, 0.3, 0.2] and p = [0.2, 0.2, 0.6], left as a question mark.
Code excerpted from the lesson's main.py; the two vectors are the stem's own numbers.
8. The prefix has 100 tokens and N = 4. The first two drafts are accepted and the third is rejected and corrected. What logical kv_length does Step 4 give?Apply
Two boxes: accepted, covering draft 1 and draft 2, and rejected at position 3, with one correction token and then the round stops. A question asks what the logical kv_length is after this round, with a prefix of 100 and N of 4.
The prefix of 100, N of 4, and the 2-accepted-then-reject-and-correct pattern are the stem's own setup.
9. After an edit, the toy's chi-square on the Leviathan check jumps into the thousands. Which edit most likely caused it?Analyze
A panel reading: before the edit, chi-squared is 11.60 against a critical value of about 14.07, verdict PASS; after an edit, chi-squared jumps into the thousands, verdict CHECK. A question asks which edit to the code most likely caused that jump.
The before value, chi^2 = 11.60, is captured from a real 50,000-trial run of the lesson's distribution_check with the eagle-1-class draft. The after description, jumping into the thousands, is the Author's Note's own wording; no specific after-value is invented.
10. A reader sees the toy's EAGLE-3 stand-in print α = 0.98 and concludes that real EAGLE-3 reaches 0.98. What is the flawed assumption?Analyze
A panel listing the toy's three draft stand-ins, each q plus Gaussian noise at a chosen amplitude, with the eagle-3 stand-in's measured alpha of 0.98 picked out. A question asks about the flawed assumption behind concluding that real EAGLE-3 reaches 0.98.
The three noise amplitudes and the measured alpha of 0.98 for the eagle-3 stand-in are captured from a real run of the lesson's perturb and measure_alpha functions.

Use It

Production-level vllm serve with EAGLE-3:

bash
vllm serve meta-llama/Llama-3.3-70B-Instruct \
  --speculative-config '{
    "model": "yuhuili/EAGLE3-LLaMA3.3-Instruct-70B",
    "num_speculative_tokens": 5,
    "method": "eagle3"
  }'

SGLang with EAGLE-3 at batch 64 on H100: roughly 1.38× more throughput than batch-64 vanilla decoding, per the EAGLE-3 paper.

When to reach for speculative decoding:

  • Any interactive chat workload where p50 latency matters more than peak throughput.
  • Code generation and structured output (JSON, SQL). α is above 0.9 because the target distribution is highly predictable.
  • Long-form generation (thousands of tokens). The amortized speedup keeps paying.

When not to:

  • Very small models (< 3B). The draft is not that much cheaper than the verifier.
  • Tiny batch-1 CPU deployments. Memory overhead of the draft model may not be worth it.
  • Very-high-temperature creative sampling where α collapses.
Check: Use It0/5
1. In the vllm serve command, how many tokens does the draft propose per step, and which key sets it?Apply
An excerpt of the vllm serve speculative-config block showing the model key, the num_speculative_tokens key with its value left as a question mark, and the method key set to eagle3. A question asks how many tokens the draft proposes per step and which key sets it.
Transcribed from the lesson's own Use It section command, with the num_speculative_tokens value masked.
2. Speculative decoding speeds up a chat endpoint but gives almost nothing on a very-high-temperature creative endpoint with the same draft. Which quantity collapsed?Analyze
Two boxes: a chat endpoint, sped up by speculative decoding, and a very-high-temperature creative endpoint, with almost no speedup using the same draft. A question asks which quantity in the speedup math collapsed on the creative endpoint.
Both endpoint outcomes are given directly in the stem.
3. You serve a 2B model at batch 1 on a CPU box, and a draft would cost nearly as much per token as the verifier. What does the Use It section suggest?Design
Two boxes: a verifier, a 2B model, and a candidate draft, whose cost is about equal to the verifier's cost per token. A question asks what the Use It section suggests doing here.
The 2B verifier size and the near-equal draft cost are given directly in the stem.
4. You serve Llama-3.3-70B for interactive chat with latency as the priority, and a trained EAGLE-3 draft exists. Which setup fits?Design
Two boxes: a serving goal of interactive chat prioritizing latency over peak throughput, and already having a trained EAGLE-3 draft for the model. A question asks which setup fits this deployment.
Both the chat-latency goal and the already-trained EAGLE-3 draft are given directly in the stem.
5. You have time to enable speculative decoding on only one endpoint: low-temperature SQL generation or very-high-temperature story writing. Which first?Design
Two boxes: SQL generation at low temperature, and story writing at very high temperature. A question asks, with time for only one, which endpoint should get speculative decoding first.
Both endpoints and their temperature settings are given directly in the stem.

Ship It

This lesson produces outputs/skill-eagle3-tuner.md. Given an inference workload (model, batch size, target latency, task profile), it recommends a speculative-decoding strategy and tuning parameters (draft family, N, tree depth, temperature-aware switching).

Author's Note

I'd run main.py before touching the EAGLE material. The first block of output is the Leviathan check, and it is the part I'd trust least until I'd seen it pass. The spec-decoded counts and the direct counts differ by small amounts per token, and the chi-square statistic still lands under the critical value. The draft there is a noisy copy of q, so the rejection rule is doing real work.

The toy is narrower than the material around it, and I'd keep that in mind. It has no hidden states, no draft tree, and no training-time test. The three "drafts" are q plus Gaussian noise at different amplitudes, and p and q do not depend on position. What it does show is the rejection rule, the residual, the bonus token, and the KV length bookkeeping. The measured α for the vanilla stand-in comes out around 0.8, well above the 0.55-0.70 in the table, and the EAGLE-1 and EAGLE-3 stand-ins land at 0.93 and 0.98, above their table ranges too. Read those printed values as a function of the noise amplitude I picked, not as a benchmark.

If you reread one function, make it residual. Drop the max(0.0, ...) clamp or the renormalization and the chi-square statistic jumps into the thousands, because the correction token is what makes the output exactly q instead of something close to it.

Exercises

  1. Run main.py. Confirm the chi-square statistic on the Leviathan distribution check stays below the 95% critical value on 50,000 samples.

  2. Sweep N from 1 to 20 with α held at 0.9 and c held at 0.04. Plot expected tokens per verifier call and actual wall time per token. Find the N that minimizes wall time. Explain the shape of the curve.

  3. Modify the code to simulate EAGLE-2 tree search: at each step, the draft proposes a tree of shape [2, 2, 2] (eight candidate paths). The verifier runs once, and the highest-probability accepted path wins. Compute α per leaf and total tokens per verifier call. Compare to linear-chain spec-decoding at equivalent compute.

  4. Implement a batched KV rollback simulator for two concurrent sequences. Sequence A has all drafts accepted; sequence B rejects at position 2. Show that the correct kv_length is updated per sequence and that no work is wasted.

  5. Read the EAGLE-3 paper's Section 4 (Training-Time Test). Explain in two sentences why naive draft training without TTT suffers from exposure bias, and why feeding the draft its own predictions during training fixes it. Connect this to the scheduled-sampling literature in seq2seq.

Key Terms

TermWhat people sayWhat it actually means
Leviathan rule"min(1, q over p)"Bernoulli accept/reject with probability min(1, q(d)/p(d)), preserves the verifier distribution exactly when you sample from the residual on rejection
Residual distribution"(q minus p) plus, normalized"(q - p)_+ clamped at zero and renormalized. This is the correct distribution to sample from on rejection
Acceptance rate α"how often the draft is right"Expected per-token Bernoulli-success probability under the rejection rule; governs all speedup math
EAGLE-1"hidden-state draft"Tiny transformer draft conditioned on the verifier's last-layer hidden state (Li et al., 2024)
EAGLE-2"dynamic draft tree"EAGLE-1 plus a tree of candidate continuations scored with tree attention in one verifier pass
EAGLE-3"training-time test"Drops the feature-prediction loss, trains on direct token prediction with the draft fed its own outputs during training
Training-time test (TTT)"exposure bias fix"Run the draft autoregressively during training so train and test input distributions match. It is the direct analog of scheduled sampling
KV rollback"undo rejected drafts"Bookkeeping that resets the verifier's KV cache to the accepted-prefix length after a rejection
Bonus token"the free one"When all N drafts accept, sample one extra from q_{N+1} at no additional verifier cost
Tree attention"verify many candidates at once"Attention with a non-causal mask that respects the topology of a draft tree; computes q_i for every node in the tree in one forward pass

Further Reading

Code

Ships With