AI
Speculative Decoding: How LLMs Generate Text Faster
Speculative decoding explained: how a draft model speeds up LLMs 2-3x with identical output, the maths, EAGLE, MTP, local setup and when it fails.
Speculative decoding is a technique that makes large language models generate text faster without changing what they output. A small, fast "draft" model guesses the next several tokens, and the large "target" model checks all of those guesses in a single pass, keeping every token it agrees with. Because checking many tokens at once costs about the same as generating one, the big model produces several tokens per step instead of one. Typical speedups are 2 to 3 times, with mathematically identical output to running the large model alone.
This guide explains what speculative decoding is, why it works, the maths behind the speedup, the main variants (draft models, Medusa, EAGLE, n-gram lookup and multi-token prediction), speculative decoding vs MTP, how to try it in llama.cpp, vLLM, LM Studio and Hugging Face, and when it doesn't help.
What Is Speculative Decoding?
What is speculative decoding, in one line? It's "guess and check" for text generation. LLMs normally generate one token at a time: run the whole model, pick a token, append it, run the whole model again. For a 70-billion-parameter model, each of those steps reads tens of gigabytes of weights from memory to produce a single token.
Speculative decoding splits the work:
- Draft. A small model (or a cheap method) quickly proposes the next few tokens, say five.
- Verify. The large model processes the prompt plus all five guesses in one forward pass, which tells it what it would have generated at each position.
- Accept. Starting from the first guess, keep each token the large model agrees with. At the first disagreement, discard the rest and use the large model's own token instead.
- Repeat from the new position.
If the draft guessed three tokens right, that single pass of the large model produced four tokens (three accepted plus the correction). If it guessed nothing right, you still get one token, the same as normal decoding, minus the small cost of drafting.
The method was published independently in late 2022 and early 2023 by Google researchers (Leviathan, Kalman and Matias, "Fast Inference from Transformers via Speculative Decoding", ICML 2023) and by DeepMind (Chen and colleagues, who called it speculative sampling). The two names refer to the same idea.
Why Speculative Decoding Works
The trick exploits how LLM inference uses hardware. Generating tokens one at a time for a single user is memory-bandwidth bound: the GPU spends most of its time reading model weights from memory, not doing arithmetic. Its compute units sit partly idle.
Verifying five tokens in one pass reads the weights once and uses some of that idle compute to evaluate five positions in parallel. So the large model's cost per pass barely changes, while the number of tokens per pass can rise several-fold. Our guide to LLM memory bandwidth explains why token speed is usually limited by memory rather than raw compute, which is exactly the slack speculative decoding uses.
The draft model has to be much cheaper than the target, but it doesn't have to be good at everything. It only needs to predict the easy tokens the large model would also choose: common words, the end of a phrase, closing brackets in code, repeated text. Those are a large share of most outputs.
Why the Output Is Identical
With greedy decoding (always picking the most likely token), the rule is simple: a guessed token is kept only if it's exactly what the large model would have picked, so the final text is the same as running the large model alone.
With sampling (temperature above zero), the original papers use a modified acceptance rule. Each guessed token is accepted with probability min(1, p/q), where p is the large model's probability for that token and q is the draft model's. When a token is rejected, a replacement is sampled from an adjusted distribution. The papers prove that the resulting tokens follow exactly the large model's distribution. That's why speculative decoding is called lossless: it changes speed, not quality.
The Maths: How Much Faster?
Two numbers drive the speedup:
- α (acceptance rate): the probability that the large model accepts a drafted token. It depends on how well the draft model matches the target and on the kind of text.
- γ (draft length): how many tokens the draft proposes per step.
The Leviathan paper shows the expected number of tokens produced per large-model pass is (1 − α^(γ+1)) ÷ (1 − α). The real speedup is a bit lower, because drafting itself costs time; the paper models that with c, the draft model's cost relative to the target, and reports c below 0.05 in its experiments.
Here's the expected tokens per pass and the resulting speedup, assuming c = 0.05:
| Acceptance rate α | Tokens per pass, γ = 3 | Speedup, γ = 3 | Tokens per pass, γ = 5 | Speedup, γ = 5 |
|---|---|---|---|---|
| 0.6 | 2.18 | about 1.9× | 2.38 | about 1.9× |
| 0.7 | 2.53 | about 2.2× | 2.94 | about 2.4× |
| 0.8 | 2.95 | about 2.6× | 3.69 | about 3.0× |
| 0.9 | 3.44 | about 3.0× | 4.69 | about 3.8× |
Two lessons. First, acceptance rate matters more than anything: a poorly matched draft wastes work. Second, longer drafts help only when acceptance is high; at low α, extra guesses are mostly thrown away. In the original paper, applying the method to T5-XXL gave a 2X–3X speedup over a strong baseline, with identical outputs.
Speculative Decoding Methods Compared
Since 2023, many variants have appeared. They differ mainly in where the guesses come from.
| Method | Where drafts come from | Needs a separate model? | Training needed | Notes |
|---|---|---|---|---|
| Classic draft model | A smaller model from the same family (for example a 1B model drafting for a 70B one) | Yes | No, if a compatible small model exists | Draft and target must share a tokenizer |
| Speculative sampling | Same as above, with the sampling-preserving acceptance rule | Yes | No | DeepMind's name for the same idea |
| Prompt or n-gram lookup | Copies likely continuations from the prompt or earlier output | No | No | Great for summarising, editing and code where output repeats input |
| Medusa | Extra prediction heads on the target model guess several future tokens | No | Yes, train the heads | Avoids running a second model |
| EAGLE family | A lightweight head predicts future tokens from the target's internal features | No | Yes | Among the highest reported acceptance rates |
| Self-speculative or layer skipping | The target model with some layers skipped acts as its own draft | No | Sometimes | Saves the memory of a second model |
| Multi-token prediction (MTP) | The model is trained to predict several future tokens natively | No | Built into pretraining | Used by DeepSeek-V3 to speed up decoding |
Speculative Decoding vs MTP
Speculative decoding vs MTP is a common confusion because the two now work together. Multi-token prediction is a training technique: the model learns to predict not just the next token but the one after it as well, using extra prediction modules. That can improve the model itself, and the extra predictions can serve as built-in drafts.
DeepSeek-V3's technical report gives a concrete example: its MTP module predicts one additional token, the acceptance rate for that second token ranged between 85% and 90% across topics, and using it for speculative decoding delivered 1.8 times the tokens per second.
So MTP is one way to produce drafts; speculative decoding is the verification framework that turns any draft into guaranteed-correct output. A model trained with MTP doesn't need a separate draft model, while any model without MTP can still use a draft model, n-gram lookup or an added head such as EAGLE.
Choosing a Draft Model
For the classic approach, the draft model has to meet three conditions:
- Same tokenizer and vocabulary as the target, so token IDs line up. In practice that means the same model family, such as a small and a large model from one release.
- Much faster than the target, typically 10 to 100 times smaller in parameters.
- Similar behaviour, so it guesses the same easy tokens. A small model from the same family, trained on similar data, usually aligns best; fine-tuned targets benefit from drafts fine-tuned the same way.
The draft model also uses memory. On a single consumer GPU, fitting both a large target and a draft can be the real constraint, which is one reason methods that need no separate model (n-gram lookup, MTP, EAGLE heads) are popular. Budget memory for the draft's weights and its KV cache before assuming it will fit.
How to Use Speculative Decoding
Most major inference engines support it:
- llama.cpp: the server accepts a draft model alongside the main model (the
--model-draftoption) and settings for the maximum number of drafted tokens. - LM Studio: its documentation describes speculative decoding with a larger "main" model and a smaller, faster "draft" model, selectable in the app for compatible model pairs.
- vLLM: supports draft models, n-gram lookup, EAGLE-style heads and MTP through its speculative decoding configuration. Our vLLM vs Ollama comparison explains where vLLM fits.
- TensorRT-LLM and SGLang: both support several speculative methods for production serving.
- Hugging Face Transformers: calls it assisted generation.
In Transformers, you pass the draft model as assistant_model, or use prompt lookup without a second model:
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("big-model-id")
target = AutoModelForCausalLM.from_pretrained("big-model-id")
draft = AutoModelForCausalLM.from_pretrained("small-model-id-same-tokenizer")
inputs = tok("Summarise this report:", return_tensors="pt")
out = target.generate(**inputs, assistant_model=draft, max_new_tokens=200) # draft-and-verify
out2 = target.generate(**inputs, prompt_lookup_num_tokens=10, max_new_tokens=200) # n-gram lookup, no draft model
print(tok.decode(out[0], skip_special_tokens=True))Replace the placeholder model IDs with a real large and small model from the same family. Measure tokens per second with and without speculation on your own prompts; the gain varies a lot by task.
Where Speculative Decoding Is Used
Speculative decoding has moved from research into products. Google's research team wrote in December 2024 that speculative decoding enables AI Overviews in Google Search to produce results faster while maintaining the same quality, and that it remains a significant part of the optimisations for such large-scale products. Inference providers and open-source serving engines enable it by default or as a standard option, and local-model apps expose it to individual users. It's especially valuable for chat and coding assistants, where users watch text appear and latency is the main complaint.
When Speculative Decoding Doesn't Help
- Low acceptance rates. Creative writing at high temperature, unusual languages, or a draft model from a different family can push acceptance so low that drafting slows things down.
- Large batch serving. When a server already batches many users together, the GPU's compute is busy, so the "free" compute that verification relies on shrinks. Gains fall and can turn negative at high load; many engines adjust or disable speculation automatically.
- Memory pressure. A draft model needs VRAM and its own KV cache. If that forces a smaller batch or a more aggressive quantization of the target, the trade may not pay off.
- Very short outputs. Classification or one-word answers finish before speculation helps.
- Mismatched setup. Different tokenizers, chat templates or sampling settings between draft and target ruin alignment.
It also doesn't make the first token appear sooner: time to first token is dominated by processing the prompt. Speculative decoding speeds up the generation that follows. It's one of several inference optimisations; our guide on AI inference vs training covers the wider picture of what makes inference fast and cheap.
Common Mistakes
- Picking a draft model by size alone, without checking it shares the target's tokenizer and behaviour.
- Setting the draft length too high for the acceptance rate, wasting work on guesses that get thrown away.
- Benchmarking on easy prompts only, such as repeated text, and expecting the same speedup on varied traffic.
- Ignoring batch size when moving from a single-user test to a busy server.
- Assuming it lowers quality, and avoiding it. Correctly implemented speculative decoding preserves the target model's output distribution.
FAQ
Does speculative decoding change the model's output?
No. With greedy decoding the output is identical, and with sampling the acceptance rule guarantees tokens follow the large model's distribution. Only the speed changes.
What is a draft model?
A draft model is a smaller, faster model, usually from the same family as the main model, that proposes several next tokens for the main model to verify. It must share the main model's tokenizer.
How much faster is speculative decoding?
Commonly 2 to 3 times for single-user generation with a well-matched draft, and more on repetitive tasks such as code editing. The gain depends on the acceptance rate, draft length, hardware and batch size, and can disappear under heavy batched load.
What is the difference between speculative decoding and speculative sampling?
They're the same idea published by two groups at about the same time. "Speculative sampling" (DeepMind) emphasised the rule that preserves the sampling distribution; "speculative decoding" (Google) is the more common name today.
Can I use speculative decoding with Ollama or LM Studio?
LM Studio documents speculative decoding with a main and draft model. Support in other local tools varies by version, and llama.cpp, which many local apps build on, supports draft models directly. Check your tool's current documentation.