AI Infra
0%
Part V · Chapter 33

Faster Decoding

AuthorChangkun Ou
Reading time~18 min

A frontier model running at batch size one spends most of its time waiting. To produce a single token it streams every weight from high-bandwidth memory into the accelerator's compute units, multiplies once, and discards them. The matrix multiplications are skinny, a vector against each weight matrix, so the chip finishes the math long before the next slab of weights arrives, then sits idle waiting on memory. Chapter 31 and Chapter 32 establish this wall from the serving side: decode is memory-bound, its arithmetic intensity far below what the hardware can sustain. Faster decoding uses that idle arithmetic to break the one-token-per-pass rule: a cheap process guesses several future tokens, and one target pass verifies several guesses at once. Decoding a token means sampling it from the probability distribution the model places over its vocabulary, so the target distribution is just those next-token probabilities the expensive model produces. speculative decoding is the exact version of that pattern: a draft model proposes tokens, the target model verifies them in parallel, and the target distribution stays unchanged. Medusa, Hydra, the EAGLE line, lookahead decoding, and multi-token prediction differ mainly in where the guess comes from. The speedup is not a property of the method alone. It holds in the small-batch memory-bound regime where spare FLOPs are real, and can disappear once serving becomes compute-bound.

The Common Move

Autoregressive generation has a sequential bottleneck that looks fundamental: decoding KK tokens takes KK forward passes, each waiting on the one before it. The bottleneck bites hardest exactly where latency is felt most. Reasoning models from Chapter 30 emit long chains of intermediate tokens before an answer, so wall-clock latency is dominated by the sheer count of sequential decode steps.

The single idea behind everything in this chapter is to trade extra parallel compute for fewer sequential steps. A cheap process guesses several future tokens, the expensive model checks all of them in one forward pass, and every guess that survives the check is a token produced without its own sequential step. Because a forward pass over γ\gamma candidate tokens costs almost the same as a pass over one, the spare compute is nearly free.

Two quantities govern the payoff. The acceptance rate α\alpha is the fraction of draft tokens the target keeps; the draft cost is how much cheaper the guesser is than the target. The expected number of tokens produced per target pass rises with α\alpha, so the whole game is to make the draft both cheap and well aligned with the target, and to verify many candidates at once. Two questions organize the rest of the chapter: where the guess comes from, and how the check stays correct.

Figure 33.1 makes the payoff concrete. With acceptance rate α\alpha and a draft of γ\gamma tokens checked in one pass, the expected tokens emitted per target pass is the geometric sum (1αγ+1)/(1α)(1 - \alpha^{\gamma+1}) / (1 - \alpha), rising from one when nothing is accepted toward γ+1\gamma + 1 when everything is. A longer draft helps only when α\alpha is high, because an early rejection wastes the whole tail.

2026-06-23T21:05:51.120330 image/svg+xml Matplotlib v3.11.0, https://matplotlib.org/ 0.0 0.2 0.4 0.6 0.8 1.0 acceptance rate alpha 0 2 4 6 8 expected tokens per target pass baseline: one token per pass draft length gamma = 2 draft length gamma = 4 draft length gamma = 8
Figure 33.1. Schematic of the speculative-decoding payoff: expected tokens emitted per target pass as a function of acceptance rate, for several draft lengths. A longer draft helps only when the acceptance rate is high. After Leviathan et al. (2023).

Try simulating the accept/reject loop directly and watch the Monte Carlo average converge to the closed-form geometric sum.

import numpy as np
rng = np.random.default_rng(0)
alpha, gamma, trials = 0.7, 4, 50000

def simulate():
    emitted = np.ones(trials)            # the corrected/bonus token
    alive = np.ones(trials, dtype=bool)  # runs not yet rejected
    for _ in range(gamma):
        accept = (rng.random(trials) < alpha) & alive
        emitted += accept                # count each accepted draft token
        alive &= accept                  # stop at first rejection
    return emitted.mean()

closed_form = (1 - alpha**(gamma + 1)) / (1 - alpha)
print(f"simulated mean tokens/pass: {simulate():.4f}")
print(f"closed-form  tokens/pass:   {closed_form:.4f}")

Keeping the check exact

The decisive design choice is how the verification preserves correctness, and the answer that made the method safe to deploy is that it can be made exact. speculative decoding, introduced independently by Leviathan et al. (Leviathan et al. 2023) and Chen et al. (Chen et al. 2023), guarantees this. A small draft model proposes a continuation of γ\gamma tokens. The target model scores all γ\gamma positions in one parallel pass, yielding its own distribution pp at each position alongside the draft's distribution qq. A modified rejection sampling rule then accepts or rejects each draft token left to right: token xx proposed from qq is accepted with probability min(1,p(x)/q(x))\min(1, p(x)/q(x)), and on the first rejection a corrected token is resampled from the residual distribution max(0,pq)\max(0, p - q), renormalized. That residual keeps only the probability mass the target wanted that the draft under-supplied, which is exactly what repairs the distribution at the rejected position. The theorem behind the rule is that the accepted stream is distributed exactly as if it had been sampled from pp token by token (Leviathan et al. 2023). The speedup is real and the output distribution is untouched. The method is not an approximation of the model, it is the same model sampled in a different order.

The cheap draft model guesses a run of γ tokens, sampling each from its own distribution q.
One target forward pass scores all γ positions at once, giving the true distribution p alongside q at each.
Move through the draft accepting token x while p(x)/q(x) ≥ r, a uniform draw in [0,1).
At the first token that fails the test, stop: everything before it is the longest valid prefix.
Replace the rejected token by drawing from the corrected residual max(0, p − q), renormalized.
When the whole draft is accepted, the target's own pass already gives one extra free token.
Figure 33.2. Step through the modified rejection rule: every accepted prefix, plus the resampled or bonus token, is distributed exactly as if it had been sampled from the target p.
A context D draft: propose gamma tokens A->D V target: score all positions in one pass D->V R accept under p over q? V->R O emit accepted tokens R->O accept run C resample from residual p minus q R->C first reject O->A C->O
Figure 33.3. The speculative decoding loop: a cheap draft proposes a run of tokens, one target pass scores them all, and a modified rejection rule keeps the longest valid prefix while preserving the target's distribution. After Leviathan et al. (2023) and Chen et al. (2023).

Figure 33.3 draws this loop. The line of accept/reject decisions it shows is the simplest case, a single linear continuation. The self-draft methods below replace that line with a tree.

The search for the guess

The lineage of these methods tracks where the guess comes from, moving from a separate model toward parts of the target itself, and finally into how the target is trained.

A second, smaller model

The first answer was a second, smaller model. Leviathan et al. and Chen et al. both used an off-the-shelf draft model from the same family as the target, for example a small Chinchilla drafting for a 70B Chinchilla (Chen et al. 2023). This needs no change to the target and is provably lossless, but it requires training, hosting, and aligning a second model, and a poorly matched draft has a low acceptance rate.

Heads on the target itself

Medusa (Cai et al. 2024) removed the separate model. Instead of a draft network it bolts several lightweight decoding heads onto the target's last hidden state, each head predicting one further future token in parallel. The candidates the heads produce form a tree, and a tree-structured attention mask lets the target verify many branches of that tree in a single pass rather than a single linear continuation. Medusa's heads predict each future token independently of the others, which caps how coherent a multi-token guess can be. It also offers a typical-acceptance scheme that relaxes exact sampling for more speed, so Medusa in that mode is deliberately not distribution-preserving, a different bargain from speculative decoding's exactness (Cai et al. 2024).

Hydra (Ankner et al. 2024) fixed the independence limitation. Its draft heads are sequentially dependent: the head predicting the third token sees what the second head proposed, so the multi-token guess is internally coherent and the acceptance rate rises. The EAGLE line pushed further on what the draft should predict. EAGLE (Li et al. 2024) observed that autoregression is more regular at the feature level, the second-to-top-layer hidden state, than at the token level, so it drafts by predicting the next feature and then mapping it to a token, resolving the uncertainty by feeding in the token already sampled one step ahead. Its successor, EAGLE-2 (Li et al. 2024), turned the verification tree dynamic: because a draft token's acceptance depends on context and not only on its position, it expands the draft tree where the draft is confident and prunes it where it is not. By EAGLE-3 (Li et al. 2025), feature prediction was gone, replaced by direct token prediction over a fusion of low, middle, and high layers, trained with a procedure the authors call training-time test, which lets the drafter keep improving as its training data grows.

The Draft-Free Route

A parallel branch removed the draft entirely. Lookahead decoding (Fu et al. 2024) reframes autoregressive generation as solving a nonlinear system by Jacobi iteration, a fixed-point sweep that updates a whole window of future positions at once and collects the n-grams the iteration produces along the way. A verification branch then checks those n-grams against the target in the same step. There is no draft model and no extra trained heads; the parallelism comes from the fixed-point structure of the problem, and the method is exact.

The guess can also be retrieved rather than computed. Prompt-lookup decoding matches the last few tokens of the generation against the prompt and proposes the n-gram that followed there, a drafter with no model at all (Saxena 2023). It ships as a standard speculative method in vLLM and TensorRT-LLM and is strongest where output copies input: retrieval-augmented answers, editing, and code.

Training the guess in

The last move folds the guess into training. Multi-token prediction (Gloeckle et al. 2024) trains the base model with several output heads on a shared trunk so that each position predicts the next nn tokens at once. The authors found this improves sample efficiency as an auxiliary objective, and crucially the extra heads double as a built-in drafter at inference time. DeepSeek-V3 (DeepSeek-AI 2024) carries this into a frontier system: its MTP module is trained alongside the main model and then reused for speculative decoding, reported to accept its second predicted token 80% to 90% of the time and to raise generation throughput by roughly 1.8 times.

S separate draft model Leviathan, Chen H self-draft heads Medusa, Hydra S->H J draft-free Jacobi iteration lookahead S->J E feature and token drafting EAGLE 1/2/3 H->E M train the draft in multi-token prediction, DeepSeek-V3 H->M E->M
Figure 33.4. Where the guess comes from: the lineage moves from a separate draft model, into parts of the target itself, and finally into how the target is trained, with a draft-free branch off to the side.

Figure 33.4 traces that search.

When the Speedup Holds

Every method here buys fewer sequential steps with more parallel compute and more memory traffic for verification. The boundaries are where that trade stops paying, and the sharpest of them is set by the serving regime rather than the method.

Figure 33.5 shows why the same method can help or hurt. At small batch the accelerator's compute units sit idle waiting on weights, so the FLOPs speculation spends to verify candidates were going to waste anyway, and they are free. At large batch the weights are amortized across many sequences and the compute units are already saturated, so verifying tokens that then get rejected competes with real work for FLOPs and can lower total throughput. The premise of the whole chapter, that decode is memory-bound, holds only in the small-batch regime.

cluster_L small batch: memory-bound cluster_R large batch: compute-bound L1 compute units idle, waiting on weights L2 spare FLOPs available L1->L2 L3 verify candidates for free L2->L3 L4 fewer sequential steps, speculation wins L3->L4 R1 weights amortized across many sequences R2 compute units saturated R1->R2 R3 rejected tokens still consume FLOPs R2->R3 R4 verification competes with real work, can lose R3->R4
Figure 33.5. Why a speedup is a property of the serving regime. At small batch the compute units idle on memory, so speculation's extra FLOPs are free. At large batch the units are saturated, so verifying rejected tokens competes for FLOPs and can cost throughput.

Three further trades sit underneath this one, and they are worth naming because they explain why the lineage moved the way it did.

  • Acceptance versus draft cost. A larger or better-trained drafter raises the acceptance rate but costs more per proposal. The optimal draft is the cheapest one whose acceptance is high enough that the saved target passes outweigh the draft's own cost. This is why self-draft heads and feature-level drafting won out: they are nearly free yet aligned with the target. Figure 33.6 shows the optimum this implies: as the draft grows longer the cost-adjusted speedup rises, peaks, then falls, because past some length the extra verification work outweighs the tokens it wins back, and a cheaper drafter pushes that peak to longer drafts.
  • Tree width versus waste. Verifying a wider tree of candidates accepts more tokens per pass but burns compute on branches that will be rejected. Dynamic trees, as in EAGLE-2, exist to spend that width only where the draft is confident.
2026-06-21T21:25:03.622180 image/svg+xml Matplotlib v3.11.0, https://matplotlib.org/
Figure 33.6. Schematic of the acceptance-versus-draft-cost trade-off: cost-adjusted speedup against draft length, at a fixed acceptance rate, for several draft-to-target cost ratios. Each curve peaks at an optimal draft length, and a cheaper drafter moves the peak rightward. After Leviathan et al. (2023) and Chen et al. (2023).
  • Lossless versus lossy. Speculative decoding, lookahead, and the EAGLE line preserve the target's output distribution exactly. Medusa's typical-acceptance mode trades that exactness for speed. Multi-token prediction changes training, not the sampling guarantee. Whether a lossy shortcut is acceptable is an application decision, not a property the serving system gets for free.
What's contested

The speedups quoted across this literature, the 2 to 3 times of the original speculative decoding, the 3 to 4 times of EAGLE-2 (Li et al. 2024), the larger figures of EAGLE-3 (Li et al. 2025), are measured at small batch sizes where serving is latency-bound and the accelerator's compute genuinely sits idle. They are not comparable across papers, because each uses different baselines, hardware, and tasks, and they do not transfer to every deployment. As batch size grows, a server becomes compute-bound rather than memory-bound: the spare FLOPs that speculation spends are no longer free, and verifying tokens that then get rejected can lower total throughput. Whether speculative decoding pays in high-throughput production serving now has an operational answer: for models that ship trained-in drafters it is a production default, SGLang reports up to 60% higher output throughput serving DeepSeek-V3 with MTP enabled (Eigen AI Team and SGLang Team 2025), and engines scale the draft length down with batch size, to zero at high concurrency, so the regime boundary has become a scheduler policy rather than an open question. Still live is where that cutoff should sit, and the choice among separate-draft, self-draft, and draft-free designs, which trade hosting cost, training cost, and acceptance differently with no settled winner. Treat any single speedup number as a property of a serving regime, not of the method.

Constraint arrow

This whole chapter is a lower layer reaching up to dictate an algorithm. The memory-bandwidth wall of Chapter 31 and Chapter 32, where single-stream decode reloads every weight per token and leaves the compute units idle, is what makes "spend parallel compute to save sequential steps" worthwhile in the first place. If decode were compute-bound there would be no idle FLOPs to spend and none of these methods would help. The shape of the decode algorithm is set by the bandwidth-to-compute ratio of the chip below it.

Inside the verification step

The verification step is the part worth seeing concretely, because it is where correctness lives. Given draft tokens x1,,xγx_1, \dots, x_\gamma from qq and the target's distributions p1,,pγp_1, \dots, p_{\gamma} from one parallel pass, the accept loop is short:

for i in range(gamma):
    r = uniform(0, 1)
    if r < min(1, p[i][x[i]] / q[i][x[i]]):
        emit(x[i])              # accepted, no extra target step
    else:
        emit(sample(normalize(relu(p[i] - q[i]))))  # corrected token
        break                   # stop at first rejection
# if all gamma accepted, sample one bonus token from p[gamma]

The two details that make it exact are the residual max(0,pq)\max(0, p - q) resampling on rejection and the bonus token after a full-accept run; together they are what the distribution-preservation theorem requires. For the self-draft and tree-based methods, the same accept logic runs over a tree rather than a line: a tree attention mask lets the single target pass score every branch, and the longest accepted path through the tree is emitted. Figure 33.7 shows why this beats a linear draft. A linear draft commits to one continuation, so a single early rejection wastes everything after it. A tree hedges across several continuations at each position, and the tree attention mask scores all of them in the one target pass for almost the cost of one. The target then emits the longest path whose every token was accepted.

ctx context a1 The ctx->a1 a2 A ctx->a2 b1 cat a1->b1 b2 dog a1->b2 b3 cat a2->b3 c1 sat b1->c1 c2 ran b1->c2 c3 barked b2->c3
Figure 33.7. Tree-structured drafting and verification. From the context, draft heads propose several candidate tokens per position rather than one. A tree attention mask scores every branch in a single target pass, and the longest fully accepted path (bold) is emitted. After Cai et al. (2024) and Li et al. (2024).

Operationally, serving stacks expose this as a drafter choice. A separate draft model is a second checkpoint to load and schedule. With EAGLE-style and Medusa-style drafters, the artifact shrinks to a small head module trained against a frozen target and loaded beside it. Multi-token-prediction drafting, as in DeepSeek-V3, needs no separate artifact at all because the heads were trained into the model. The practical failure mode is a drafter whose acceptance rate is too low for the workload, at which point speculation adds latency instead of removing it, which is why acceptance rate is the metric to watch in production rather than the headline speedup from a paper.

Further reading

  • Leviathan et al., “Fast Inference from Transformers via Speculative Decoding,” 2023. arXiv:2211.17192
    Speculative decoding uses a small draft model to propose tokens verified in parallel by the large target model, achieving 2X-3X speedup without changing the output distribution.
  • Chen et al., “Accelerating Large Language Model Decoding with Speculative Sampling,” 2023. arXiv:2302.01318
    Speculative sampling uses a small draft model to propose tokens that a large target model verifies in parallel, achieving 2–2.5x decoding speedup on Chinchilla without altering the output distribution.
  • Cai et al., “Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads,” 2024. arXiv:2401.10774
    MEDUSA accelerates LLM inference by adding multiple extra decoding heads plus tree-based attention to predict and verify several tokens per step, achieving 2.2-2.8x speedup without a separate draft model.
  • Ankner et al., “Hydra: Sequentially-Dependent Draft Heads for Medusa Decoding,” 2024. arXiv:2402.05109
    Hydra heads are sequentially-dependent draft heads for speculative decoding that condition each prediction on prior candidate tokens, improving throughput by up to 2.70x over autoregressive decoding.
  • Li et al., “EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty,” 2024. arXiv:2401.15077
    EAGLE is a speculative decoding framework that predicts second-to-top-layer features conditioned on a one-step-ahead token sequence, achieving 2.7x-3.5x latency speedup over autoregressive LLM decoding with lossless output distribution.
  • Li et al., “EAGLE-2: Faster Inference of Language Models with Dynamic Draft Trees,” 2024. arXiv:2406.16858
    EAGLE-2 improves speculative decoding by replacing static draft trees with context-aware dynamic draft trees, achieving 3.05x-4.26x lossless LLM inference speedup without additional training.
  • Li et al., “EAGLE-3: Scaling up Inference Acceleration of Large Language Models via Training-Time Test,” 2025. arXiv:2503.01840
    EAGLE-3 replaces feature prediction with direct token prediction and multi-layer feature fusion via training-time test, enabling a scaling law for speculative decoding that achieves up to 6.5x inference speedup.
  • Fu et al., “Break the Sequential Dependency of LLM Inference Using Lookahead Decoding,” 2024. arXiv:2402.02057
    Lookahead Decoding accelerates LLM autoregressive decoding without a draft model by generating and verifying n-grams in parallel via Jacobi iteration, achieving up to 4x speedup.
  • Gloeckle et al., “Better & Faster Large Language Models via Multi-token Prediction,” 2024. arXiv:2404.19737
    Training LLMs with n independent output heads to predict multiple future tokens simultaneously improves sample efficiency, boosts coding benchmarks by  15
  • DeepSeek-AI, “DeepSeek-V3 Technical Report” (multi-token prediction reused for speculative decoding), 2024. arXiv:2412.19437
  • Eigen AI Team and SGLang Team, “Accelerating SGLang with Multiple Token Prediction,” 2025. lmsys.org
    SGLang's multi-token-prediction speculative decoding for DeepSeek-V3 reports up to 60
  • Saxena, “Prompt Lookup Decoding,” 2023. github.com
    Prompt lookup decoding replaces the draft model in speculative decoding with simple n-gram matching against the prompt, yielding 2-4x speedups on input-grounded tasks with no change to output quality; it ships in transformers and vLLM.

Comments

Log in to comment