What matters in AI.

Subscribe

Learn / AI basics

Definition · AI basics

Speculative decoding

Speculative decoding is a method that makes a large language model write text faster with no change to its output. A small, fast draft model guesses the next tokens. The large target model checks all the guesses in one parallel step. It keeps the correct guesses and gives its own token at the first incorrect guess.

Last reviewed

Key points

  • A small draft model guesses some tokens. The large target model checks them all in one step.
  • The output of the target model does not change. The check rule keeps its probability distribution, to the limits of hardware numerics.
  • Leviathan and colleagues showed 2 to 3 times more speed on T5-XXL (2022). DeepMind showed 2 to 2.5 times on Chinchilla 70B (2023).
  • The method helps most at low traffic, where the hardware waits on memory. vLLM recommends it for "medium-to-low QPS" workloads.
  • The pattern of correct guesses can leak data. Wei and colleagues used token counts for each step to identify user queries.

How it works

A language model writes one token at a time. For K tokens, the model must operate K times in series. Speculative decoding adds a fast guess before each slow step.

The steps of one cycle:

  1. Draft. A small draft model guesses the next K tokens.
  2. Check. The large target model scores all K guesses in one parallel step.
  3. Accept. From the left, the target model keeps each guess that its check rule accepts.
  4. Correct. At the first rejected guess, the target model gives its own token. A new cycle starts.
One cycle of speculative decoding: the draft model guesses, and the target model checks all guesses in one step.
One cycle of speculative decoding: the draft model guesses, and the target model checks all guesses in one step.

DeepMind (2023) says each cycle gives one token minimum and K+1 tokens maximum.

Why it matters

Speculative decoding makes a model faster and keeps the output of the large model. Leviathan and colleagues say that the target model needs no new training.

Study Target model Draft Speed increase
Leviathan et al., 2022 T5-XXL (11B) T5-small (60M) 2 to 3 times
Chen et al. (DeepMind), 2023 Chinchilla 70B 4B draft model 1.92 to 2.46 times
Li et al. (EAGLE), 2024 LLaMA2-Chat 70B EAGLE head 2.7 to 3.5 times

In the DeepMind tests, code got more speed (2.46 times, HumanEval) than summaries (1.92 times, XSum).

In practice

The vLLM serving software has speculative decoding as a feature. Its documentation puts the methods in two groups:

Group Methods in vLLM vLLM result
Model based draft model, EAGLE, Multi-Token Prediction (MTP) “the best latency reduction”
Simple n-gram, suffix decoding “modest speedups”

Other designs put the draft in the target model:

  • EAGLE (Li et al., 2024) guesses from the internal features of the target model.
  • Medusa (Cai et al., 2024) adds more decoding heads to the target model. Medusa-1 keeps the output of the target model.

Google says speculative decoding lets AI Overviews in Google Search give results faster. This is a vendor claim.

Trade-offs

Know these four limits before you use speculative decoding:

  • Traffic. vLLM recommends it for “medium-to-low QPS (queries per second), memory-bound workloads.”
  • Draft length. DeepMind found that a larger K can stop the speed increase. It also makes the time for each answer less stable.
  • Numerics. vLLM says the method is “theoretically lossless up to the precision limits of hardware numerics.” FLy, a vLLM variant, “is not distribution preserving”.
  • Side channel. Wei and colleagues (arXiv, first version November 2024) showed that the count of tokens for each step leaks which guesses were correct.

Questions and answers

Does speculative decoding change what the model says?

No, not in the standard method. Leviathan and colleagues and DeepMind show that the check rule keeps the output distribution of the large model. The vLLM documentation gives a limit: floating point errors can cause small changes. Some variants, such as FLy in vLLM, relax the check and do not keep the distribution.

Is speculative decoding the same as speculative sampling?

Yes, for most uses. Google researchers used the name speculative decoding in November 2022. DeepMind researchers used the name speculative sampling in February 2023. The two papers give the same draft and check method with the same guarantee.

Is speculative decoding a security risk?

It can be. Wei and colleagues showed in 2024 that the number of tokens in each step shows which guesses were correct. A network observer used this to identify user queries from a set of 50 prompts. Packet padding and token aggregation make the leak smaller.

Sources

  1. Fast Inference from Transformers via Speculative DecodingPMLR (ICML 2023), Leviathan et al., 1 Jan 2023
  2. Fast Inference from Transformers via Speculative Decoding (arXiv)arXiv (Leviathan et al.), 30 Nov 2022
  3. Looking back at speculative decodingGoogle Research, 6 Dec 2024
  4. Accelerating Large Language Model Decoding with Speculative SamplingarXiv (Chen et al., DeepMind), 2 Feb 2023
  5. Accelerating Large Language Model Decoding with Speculative SamplingarXiv (Chen et al., DeepMind), 2 Feb 2023
  6. Speculative Decoding (vLLM documentation)vLLM project
  7. Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding HeadsarXiv (Cai et al.), 19 Jan 2024
  8. EAGLE: Speculative Sampling Requires Rethinking Feature UncertaintyarXiv (Li et al.), 26 Jan 2024
  9. When Speculation Spills Secrets: Side Channels via Speculative Decoding In LLMsarXiv (Wei et al.), 11 Feb 2026

In the news