Skip to content
Generating text

Speculative decoding

A small model guesses a few tokens ahead and the big model checks them all in one pass: faster, with the same output distribution.

Deep dive · 6 steps

Read first:Prefill and decodeSampling and decoding

Step 1 of 6· Illustrative tokens, guesses and probabilities; the acceptance rule and speed-up formula are real

in one minute

A large model writes one token per full pass, and each pass is slow because it must read all of its weights. Speculative decoding adds a small, fast draft model that guesses the next few tokens. The large model then checks all the guesses together in a single pass, which takes about as long as producing one token. It keeps the guesses it agrees with, replaces the first one it disagrees with, and carries on from there. A careful accept-or-reject rule means the text follows exactly the distribution the large model would have produced alone. When the draft guesses well, several tokens arrive for the price of one pass.

Why it matters for your product

Speculative decoding cuts the time per output token without retraining the large model or changing its output distribution: the original paper measured 2 to 3 times faster generation on T5-XXL, and a DeepMind team reported 2 to 2.5 times on Chinchilla 70B. It suits latency-sensitive traffic such as chat and code completion. Gains depend on how predictable the text is, so measure acceptance rates on your own prompts, and expect less from busy servers where large batches already keep the arithmetic units occupied.

For engineersShow the maths

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

Each guess survives with probability α, the round stops at the first rejection, and the target always contributes one token of its own.

Worked example: α = 0.8, γ = 4: (1 − 0.8⁵) / 0.2 = (1 − 0.328) / 0.2 ≈ 3.36 tokens for every big pass.

Speed-up = (1 − α^(γ+1)) / ((1 − α)(γc + 1))

Tokens per round divided by the cost of a round: one target pass plus γ draft passes, each costing c of a target pass.

Worked example: α = 0.8, γ = 4, c = 0.05: 3.36 / 1.2 ≈ 2.8 times faster than plain decoding.

Keep x with probability min(1, p(x) / q(x)); otherwise sample from norm(max(0, p − q))

Guesses the target likes at least as much as the draft are always kept; over-confident guesses are thinned out, and the leftover probability is handed back through the replacement.

Worked example: In the visual's example, the target gives “1887” 5% and the draft 45%, so the guess survives 0.05 / 0.45 ≈ 11% of the time; otherwise the leftover mass sits entirely on “1889”, which is chosen.

where it stops working

It only helps when the draft often agrees with the target and the hardware has spare compute during decode: with low acceptance it is slower than plain decoding, large batches leave little idle compute to use, and it does more total arithmetic. In the standard method the draft and target share a vocabulary, and the draft is one more model to serve.

Key terms

The words you will hear

Draft model

A small, fast model that proposes several next tokens for the large model to check.
Where it came from

Primary sources

  1. 01Fast Inference from Transformers via Speculative DecodingLeviathan et al. · 2022
  2. 02Accelerating Large Language Model Decoding with Speculative SamplingChen et al. · 2023
  3. 03Blockwise Parallel Decoding for Deep Autoregressive ModelsStern et al. · 2018
  4. 04Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding HeadsCai et al. · 2024

Want this working on your data?

We design and build the systems these ideas power: retrieval, agents, voice and the models behind them. Start with a free discovery call.