Pidoku

Speculative Decoding (2022–2023)

Module 30 Lesson 30.l 40 min Difficulty 3/5

Prerequisites 12.d, 12.o, 30.a


Before you start: words you need#

WordPlain meaning
Target modelThe big model whose output you actually want.
Draft modelA small, fast model that guesses the next few tokens. The papers call it the approximation model (Leviathan) or draft model (Chen).
γ (gamma) / KHow many tokens the draft guesses before the target checks them.
Acceptance rate (α)The expected chance that the target accepts a draft token. Higher means bigger speed-ups.
Rejection samplingAccepting a proposed sample with some probability, and drawing a corrected sample when you reject, so the final samples follow the distribution you want.
LosslessThe output distribution is exactly the target model’s, not an approximation.
Greedy / argmax samplingAlways picking the most likely token (temperature 0).
WalltimeReal elapsed time, as opposed to number of operations.

1. The paper#

Two groups found the same algorithm independently, a few months apart:

  • Leviathan, Kalman, Matias (Google Research), “Fast Inference from Transformers via Speculative Decoding”, ICML 2023 (arXiv November 2022). arXiv:2211.17192
  • Chen, Borgeaud, Irving, Lespiau, Sifre, Jumper (DeepMind), “Accelerating Large Language Model Decoding with Speculative Sampling”, arXiv February 2023. arXiv:2302.01318

Leviathan et al. call it speculative decoding and its sampling rule speculative sampling; Chen et al. call the whole thing speculative sampling. Both names are used today.


2. The problem#

At small batch, decode is memory-bound (30.a): each step reads every weight to produce one token per sequence, and the maths units sit mostly idle. Checking 5 tokens costs about the same as producing 1, because the weights are read once either way. Generation is still sequential, though: you cannot compute token 5 before you know tokens 1 to 4.

Earlier ways to go faster — smaller models, distillation, early exit, non-autoregressive decoding — all changed the outputs. Both papers wanted a speed-up with identical output distributions and no retraining of the big model.


3. The idea#

Let a cheap model guess, and let the big model check all the guesses in one parallel forward pass.

  1. The draft model generates γ tokens autoregressively (cheap).
  2. The target model runs once on the prefix plus all γ guesses, which gives its own probabilities at every position (the cost of about one decode step, since decode is memory-bound).
  3. Walk the guesses left to right. Accept guess x with probability min(1, p(x)/q(x)), where p is the target’s probability and q the draft’s.
  4. At the first rejection, sample a replacement from the adjusted distribution norm(max(0, p − q)) and stop. If all γ were accepted, sample one bonus token from p.

Every run of the target therefore produces between 1 and γ + 1 tokens.

flowchart LR
  D["Draft: guess γ tokens"] --> T["Target: one forward pass over all γ positions"]
  T --> V{"Accept each guess with prob min(1, p/q)"}
  V -- "all accepted" --> B["Sample bonus token from p"]
  V -- "first rejection" --> R["Sample from norm(max(0, p − q)), drop the rest"]
  B --> D
  R --> D
  class D,T compute
  class V neutral
  class B,R io

The rejection rule is the clever part. Both papers prove that the tokens produced this way are distributed exactly as if sampled from the target alone, at any temperature. For greedy decoding it reduces to: accept the guess if it equals the target’s argmax.


4. How it works#

Expected tokens per target run. If each guess is accepted independently with probability α, a run yields on average

E[tokens] = (1 − α^(γ+1)) / (1 − α)

With α = 0.8 and γ = 4: (1 − 0.8⁵) / 0.2 ≈ 3.4 tokens per target pass instead of 1.

What α is. Leviathan et al. show α = E[Σ min(p, q)], one minus the total variation distance between the two models’ next-token distributions. A draft that agrees with the target more often gives a higher α.

When it pays. Let c be the draft’s cost relative to one target step. Walltime improves by (1 − α^(γ+1)) / ((1 − α)(γc + 1)). A cheap draft (small c) and high α favour larger γ; a draft that is too slow or too wrong makes it a loss. Total arithmetic always goes up — rejected guesses are wasted work — so speculative decoding spends spare compute to save time.

Choosing the draft. Leviathan et al. used smaller T5 models, and even a bigram model and “copy from the context” heuristics (which later became prompt-lookup and n-gram drafting). Chen et al. trained a dedicated 4 B draft with only 8 layers so it would run fast on the same 16 TPU v4 chips that serve Chinchilla: 1.8 ms/token versus 14.1 ms/token for the target. Their point: in a distributed setup, the draft’s latency matters more than its parameter count.

The step-by-step algorithm and its batch-size behaviour are taught in 12.n and 13.n.


5. Results#

Leviathan et al. (T5-XXL, 11 B, batch 1 on one TPU v4; Table 2):

TaskDraftTemperatureγαWalltime speed-up
English→GermanT5-small (77 M)070.753.4×
English→GermanT5-small170.622.6×
CNN/DM summarisationT5-small050.653.1×
CNN/DM summarisationT5-large (800 M)130.561.7×

They also measured α for a 137 B LaMDA dialog model with smaller LaMDA drafts (Table 3).

Chen et al. (Chinchilla 70 B, batch 1, K = 4, 16 TPU v4; Table 1):

BenchmarkSamplingPlain decodingSpeculativeSpeed-upQuality
XSum (ROUGE-2)nucleus14.1 ms/token7.52 ms/token1.92×0.112 → 0.114
XSum (ROUGE-2)greedy14.1 ms/token7.00 ms/token2.01×0.157 → 0.156
HumanEvalnucleus14.1 ms/token5.73 ms/token2.46×45.1% → 47.0%

Quality differences are sampling noise; the method is lossless by proof.


6. What held up and what did not#

Held up

  • The algorithm. Every speculative method in production — EAGLE (30.s), MTP drafting, n-gram lookup, parallel drafters — uses this draft-then-verify loop and, for lossless sampling, this rejection rule. (Medusa’s optional “typical acceptance” is the lossy exception, 30.s.)
  • Lossless speed-up at low batch. It is standard in latency-sensitive serving in 2026, built into vLLM, SGLang and TensorRT-LLM.
  • Draft latency matters more than size. The lesson Chen et al. drew led directly to shallow drafts that reuse the target’s features (EAGLE, 30.s) and to multi-token-prediction heads trained with the model (DeepSeek-V3, 30.v).

Did not, or changed

  • A separate small model is rarely the best draft. It needs the same tokenizer, its own KV cache and memory, and often has low α. Feature-level drafters (EAGLE-3), MTP heads and suffix/n-gram methods replaced it for most deployments.
  • Gains shrink at large batch. When the batch is big, decode becomes compute-bound and the “free” verification is no longer free. Engines now adapt γ to load or turn speculation off (13.n).
  • Trees beat chains. Verifying a tree of alternatives in one pass (SpecInfer, Medusa, EAGLE-2) accepts more tokens per target pass than a single chain (13.o).
  • Floating-point caveat. “Exactly the target distribution” holds in exact arithmetic; batched verification kernels can differ numerically from step-by-step decode (28.c).

7. Where it lives in 2026#

  • Taught in depth: the algorithm in 12.n, practice and tuning in 13.n, variants in 13.o, vLLM’s implementation in 18.f.
  • vLLM v0.32.0 supports draft models, n-gram, suffix decoding, EAGLE/EAGLE-3, MTP and parallel drafters (P-EAGLE, DFlash, DSpark, since July 2026).
  • Hosted APIs use it widely behind the scenes; some expose it as “predicted outputs” for edits where most of the output is known in advance.

Checked on 13 November 2026.


8. Questions#

  1. Why does checking γ guesses cost about the same as generating one token at batch 1?
  2. Write the acceptance rule and the adjusted distribution used after a rejection.
  3. Why is the output distribution exactly the target’s? Sketch the argument for one token.
  4. With α = 0.6 and γ = 3, how many tokens does each target pass produce on average?
  5. Why can speculative decoding make throughput worse at large batch?
  6. Chen et al. trained an 8-layer 4 B draft rather than using a smaller 4 B model with more layers. Why?
  7. What do you need to check before running a draft model from a different model family?

9. Further reading#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in