What is speculative decoding in LLMs?
Speculative decoding is a way to speed up text generation in which a small, fast model drafts several tokens ahead and the large model checks them all in one forward pass. The large model keeps every draft token that matches what it would have produced, replaces the first one that does not, and the cycle repeats. With the right acceptance rule the output follows the large model's distribution exactly, so speed improves without any change in quality.
Generating one token at a time is limited by memory bandwidth, not arithmetic: each step streams all the model's weights from GPU memory to produce a single token. Speculative decoding spends the idle compute on checking several guesses per weight read. It cuts per-token latency for chat assistants, coding tools, and any single-user setting, and it is built into serving systems such as vLLM, TensorRT-LLM, and llama.cpp. Its benefit shrinks at large batch sizes, where the GPU is already busy.
Key ideas
- Decoding one token per pass is memory-bound, so the GPU's compute units sit mostly idle.
- A cheap drafter proposes γ tokens, and the target model checks all of them in one parallel pass.
- Each round keeps the longest accepted prefix plus one token from the target, so it always makes progress.
- With acceptance rate α, a round yields (1 − α^(γ+1)) / (1 − α) tokens on average.
- The accept-with-min(1, p/q) rule and residual resampling keep the output distribution identical to the target's.
- The speedup is largest for single requests and shrinks as batch size makes decoding compute-bound.
Common questions
Does speculative decoding reduce total compute?
No. It usually increases the total floating-point work, since the draft model runs extra passes and the target scores drafts that end up rejected. It reduces the number of sequential target passes, trading spare compute for lower latency. On a busy server with no spare compute, that trade stops paying off.
Does speculative decoding work with temperature and top-p sampling?
Yes. The acceptance rule works for any pair of distributions, so temperature, top-k, or top-p is applied to both the target's p and the draft's q before the check. Greedy decoding is the special case where both distributions put all their mass on one token. Acceptance rates tend to fall at higher temperatures, because sampled tokens are harder to predict.
How do I choose a draft model?
Pick a model that is much cheaper than the target, often 10 to 20 times smaller. A model from the same family trained on similar data agrees with the target more often, which raises the acceptance rate. Some teams also distill the draft from the target to raise it further.
What is the difference between speculative decoding and speculative sampling?
They are two names for the same idea, published independently around the same time. Leviathan et al. (2022) called it speculative decoding and Chen et al. (2023) called it speculative sampling. Both borrow the term from speculative execution in CPUs, where a processor runs ahead on a guess and discards the work if the guess was wrong.
Related explainers
- Sampling: Temperature, Top-k & Top-p — How a language model picks its next token
- KV Cache — Why LLM generation caches keys and values, and what it costs
- Decoder-Only Transformers — The architecture behind GPT and modern LLMs
- Quantization — Shrinking model weights to 8 and 4 bits
- Mixture of Experts — Routing each token to a few experts in a much larger model
- Language Modeling — Predict the next token — the objective that powers GPT, BERT, and modern NLP
References
- Leviathan, Kalman & Matias (2022), "Fast Inference from Transformers via Speculative Decoding"
- Chen et al. (2023), "Accelerating Large Language Model Decoding with Speculative Sampling"
- Cai et al. (2024), "Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads"
- Li et al. (2024), "EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty"
Last updated