Chapter 29Down the Rabbit Hole: How Speculative Decoding Guesses Without Changing a Word
The claim sounded like a free lunch. Google says speculative decoding runs in Search's AI Overviews, faster "while maintaining the same quality of responses". Their original experiment got about 3x on an 11B T5-XXL, drafted by a 60M T5-small, with an identical output distribution. Not "close enough". A tiny, obviously worse model writes many of the tokens, and the result is statistically indistinguishable from the big model writing all of them.
The speed half I got fast. The exactness half took an afternoon and is the most elegant probability I've met in a while. This post is that half, and where the guarantee quietly stops holding.
Why decoding is slow#
One token per forward pass, each depending on the last, so passes are serial. At small batch each pass is memory-bound: a 70B model in bf16 reads about 140 GB of weights per token. DeepMind measured 14.1 ms per token on Chinchilla 70B across 16 TPU v4s, with most compute idle.
The asymmetry the trick rests on: generating k tokens is serial, but scoring k tokens you already have is parallel. One prefill-style pass gives the next-token distribution at every position, for about the cost of one decode step. So if something cheap guesses a few tokens, the big model checks them all at once. What "check" means when sampling is the question.
The editor and the intern#
An intern (draft model, distribution q) writes the next few words. An editor (target, p) reads the draft left to right, keeping each word with some probability. At the first struck word the editor writes their own and discards the rest. If everything survives, the editor adds one more word free.

Figure 1 from Leviathan, Kalman and Matias, "Fast Inference from Transformers via Speculative Decoding" (ICML 2023), arXiv:2211.17192, licensed CC BY 4.0. Cropped and recompressed.
Much of that sentence is green: "nikkei 22", "index rose 22", "percent , to 10 , 98". A tiny model predicts text that context basically forces; the big model steps in at the hard choices.
The rule#
def spec_step(prefix, Mp, Mq, gamma):
xs, qs = [], []
for _ in range(gamma): # serial, but cheap
q = Mq(prefix + xs); x = sample(q)
xs.append(x); qs.append(q)
ps = Mp.score(prefix, xs) # ONE pass -> gamma+1 dists
for i, x in enumerate(xs):
if rand() > min(1, ps[i][x] / qs[i][x]):
resid = clip(ps[i] - qs[i], 0); resid /= resid.sum()
return prefix + xs[:i] + [sample(resid)]
return prefix + xs + [sample(ps[gamma])] # all accepted: bonus tokenAccept x with probability min(1, p(x)/q(x)); on rejection sample from max(0, p - q), renormalized. The residual looked backwards to me: it's biased away from what the draft liked. A punishment, not a correction. Until the proof.
Why it comes out exactly p#
Split the probability of emitting x' into its two routes:
via acceptance: q(x') * min(1, p(x')/q(x')) = min(p(x'), q(x'))
P(reject) = 1 - sum_x min(p, q) = sum_x max(0, p - q) = Z
via rejection: Z * max(0, p(x') - q(x')) / Z = p(x') - min(p(x'), q(x'))
total: min(p, q) + (p - min(p, q)) = p(x')Acceptance hands out min(p, q) of each token's mass. Rejection hands out exactly the leftover. The residual's normalizer Z is the rejection probability itself: both are "the mass of p that q didn't cover", so Z cancels.
mass
p ████████████░░░░░░░░ █ covered by acceptance = min(p, q)
q ████████████ ░ topped up on rejection = max(0, p - q)
token x' where q > p: nothing extra (already enough)That's why the residual avoids the draft's favourites: tokens with q > p already got their full share, and more would double-count them.
Consequences:
- Any draft works. The proof never used anything about
q. A uniform random drafter gives exactlyp, just slowly. - Later drafts are discarded after a rejection: they were conditioned on a token you didn't emit.
- Greedy is a special case. At temperature zero both are one-hot, so acceptance is the argmax-match rule from Stern et al.'s 2018 blockwise parallel decoding.
Acceptance is a distance#
Total acceptance is sum_x min(p, q) = 1 - TV(p, q), one minus total variation distance. (Leviathan proves the 1 - sum min form; calling it TV is the dive's framing.) No coupling of samples from p and q can agree more often: this is a maximal coupling, and min(1, p/q) is the largest acceptance that leaves non-negative correction mass.
Against the obvious alternative, "sample from the target, keep the draft if they match", also exactly correct: it accepts with probability sum p * q. In the dive's toy simulation (8-token vocab, draft = target logits plus noise) that's 0.23 versus 0.83, about 3.6x fewer accepted tokens. It's llama.cpp's default verification because it works with any sampler chain including grammars, paying in acceptance rate.
The simulation drew 200k samples and matched p within noise (max deviation 0.0015 against noise around 0.0022), with acceptance 0.8258 against a theoretical 0.8256.
Where the speedup goes#
If each position accepts independently with probability α (the paper's simplifying assumption), tokens per iteration are (1 - α^(γ+1)) / (1 - α) for draft length γ. Each extra draft token is worth α^k; at α = 0.8 the tenth is worth about 0.11 tokens. Dividing by cost, γ draft passes at relative cost c plus one target pass:
speedup(α, γ, c) = (1 - α^(γ+1)) / ((1 - α)(γc + 1))With c = 0.1 and α = 0.8, best γ is 6 for about 2.47x. But the formula assumes scoring γ+1 tokens costs the same as one, true only while the target is memory-bound. Speculation spends arithmetic: at α = 0.8 and γ = 5, Leviathan's table shows 1.63x more total compute for 3.69x lower latency. It bets you have spare FLOPs.
At large batch you don't:
| Source | Low batch | High batch |
|---|---|---|
| EAGLE-3 in vLLM, RTX 3090, 8B model | 1.75x at batch 2 | 1.01x at batch 56 |
| Meta, stock vLLM EAGLE | 1.3x at batch 2 | 0.7x at batch 48 (slowdown) |
| vLLM 2024 blog | up to 2.8x (summarization, low rate) | 1.4 to 1.8x slowdowns at high request rates |
So it's a latency tool, not a throughput tool, except cases like very long contexts, where MagicDec showed KV loading dominates and speedup can grow with batch size.
"Identical" has fine print#
The proof holds in exact arithmetic. Verification runs the target on k+1 query tokens, a different kernel shape than one-token decode: reductions reorder, logits shift, near-tie argmaxes flip. vLLM's docs say lossless "up to the precision limits of hardware numerics", with no guarantee of stable log probabilities.
Batching bugs, timing leaks, drafter drift
- Ragged batches. Rows accept different token counts, so position IDs, masks and KV offsets go ragged. "Batch Speculative Decoding Done Right" (2025) claims existing batched implementations break output equivalence, and that fixing alignment cost up to 40% overhead. I haven't reproduced it; it's from the abstract. Single-row unit tests would pass it.
- Timing side channel. Tokens per iteration depend on how predictable the text is to the drafter, so they depend on content. Two 2024 papers showed this pattern, visible over encrypted streaming traffic, leaks information about the query or topic. Mitigations (padding, fixed-size bundles) give back some latency.
- Drafter drift. Modern drafters are heads reading the target's hidden states (EAGLE, DeepSeek-V3's multi-token prediction), tied to one checkpoint. Fine-tune or re-quantize the target and acceptance decays until you retrain. EAGLE-3 drafter training is reported at around 128 H200-hours for an 8B target.
The question I'm left with#
Is exactness even the right goal? Judge Decoding (ICLR 2025) notes the standard test rejects many good drafts: even human or GPT-4o text gets low acceptance, because a fine continuation isn't the same as being distributed like this model. With a learned judge accepting on quality, they report 9x on an 8B/405B pair.
But a 2026 lossy-verification study found the cost grows with difficulty, up to 6.67 points on AIME for truncation-style rules. And for reasoning models, SpecReason accepts whole steps by meaning rather than tokens by probability.
On one side, a three-line rule with a clean proof. On the other, faster heuristics that are sometimes quietly worse on the hardest problems. I don't think anyone has settled it, or that chat and reasoning share an answer.
Next on my list: multi-draft verification. The optimal rule is an optimal-transport problem with a closed form known only for two identical drafts. Same maximal-coupling idea, much harder.
Sources#
- Leviathan, Kalman, Matias. Fast Inference from Transformers via Speculative Decoding (ICML 2023)
- Chen et al. Accelerating Large Language Model Decoding with Speculative Sampling (DeepMind, 2023)
- Stern, Shazeer, Uszkoreit. Blockwise Parallel Decoding (NeurIPS 2018)
- Google Research. Looking back at speculative decoding
- EAGLE-3 and MagicDec
- Meta. Production speculative decoding
- vLLM. Speculative decoding blog post and docs
- llama.cpp. Speculative decoding docs
- Batch Speculative Decoding Done Right
- When Speculation Spills Secrets and Remote Timing Attacks on Efficient LM Inference
- Judge Decoding and Revisiting Lossy Verification
- SpecReason
- Multi-draft canonical decomposition