Speculative Decoding: How It Speeds Up LLM Inference
Large language models generate text one token at a time. Each new token requires a full pass through the model, so generating 500 tokens means running a multi-billion-parameter model 500 times in a row. That serial process is why LLM inference can feel slow and expensive. Speculative decoding attacks the problem directly: instead of asking the big model to produce one token per pass, it lets a smaller, cheaper model guess several tokens ahead, then asks the big model to check all those guesses in a single pass. When the guesses are right, you get multiple tokens for the price of one forward pass.
What Is Speculative Decoding?
Speculative decoding is an inference technique that speeds up autoregressive text generation without changing the output. A fast draft model proposes a sequence of candidate tokens, and the large target model verifies them all at once in parallel. Every token the target model accepts is kept; the first rejected token is replaced with a corrected token sampled from the target model’s own distribution. Because the verification step provably preserves the target model’s output distribution, the final text is statistically identical to what the large model would have generated alone.
The idea was introduced for modern transformers by Chen and colleagues in 2023 (“Fast Inference from Transformers via Speculative Decoding”) and draws on earlier work by Stern and colleagues in 2018 on blockwise parallel decoding.
How It Works, Step by Step
Imagine the target model is a huge model like a 70B-parameter LLM, and the draft model is a small 1B-parameter model trained on similar data.
- Draft. The draft model generates a block of γ (gamma) tokens autoregressively, exactly as it normally would. If γ is 4, it produces four candidate tokens: t₁, t₂, t₃, t₄.
- Verify in parallel. The target model receives the prompt plus the four draft tokens and scores all of them in one forward pass. Because the target model can process a whole sequence in parallel, checking four tokens costs roughly the same time as generating one token.
- Accept or reject. Starting from t₁, the algorithm compares the draft token against the target model’s probability distribution at each position. Each token is accepted with a probability that guarantees the final distribution matches the target model exactly. As soon as one token is rejected, the remaining drafts are discarded, and a replacement token is sampled from the corrected distribution.
- Advance. The accepted tokens (plus the corrected token) are appended to the sequence, and the loop repeats.
A large model’s per-token latency is dominated by moving weights from memory, not by computation, so scoring four tokens in one pass takes barely longer than scoring one: the expensive memory transfer happens once either way.
Why LLM Inference Is Memory-Bound
To understand why this works, you need to know where the time actually goes. During training, a GPU crunches huge batches and stays busy doing math. During decoding, batch sizes are often tiny (one user, one token at a time), so the GPU finishes its arithmetic quickly and spends most of its time waiting on memory: loading billions of parameters for every single token.
This is called the memory bandwidth bottleneck. The fix is to do more useful work per memory load. Speculative decoding does exactly that by having the target model evaluate several tokens per pass instead of one. A draft model is cheap because it has far fewer parameters, so its own memory traffic is negligible next to the target model’s. The target model only loads its weights once per iteration but now produces several tokens.
Where Do the Draft Tokens Come From?
The draft does not have to come from a trained small model. Three families of approaches exist:
- Smaller companion models. A tiny model from the same family (for example, a 1B model drafting for a 70B model) produces the most accurate guesses, which means a higher acceptance rate. The cost is running a second model, but it is small enough that the overhead stays low.
- Lookup and retrieval drafts. Some methods skip the neural draft model entirely and pull candidate tokens from an n-gram table, the prompt itself, or previously generated text. This is nearly free and works well when outputs repeat phrases.
- Self-drafting. The target model can draft for itself by skipping some of its own layers for the draft pass, or by using extra prediction heads attached to its output. This removes the need for a separate model altogether.
The acceptance rate — the fraction of draft tokens the target model keeps — is the metric that decides how much you gain. High acceptance means most guesses survive, and each iteration yields several tokens. Low acceptance means most guesses are discarded, and the overhead of drafting eats into the gains.
Notable Variants
Medusa (2024) adds multiple decoding heads to a single model, each head predicting a token further into the future. Verification then uses a tree-structured attention pattern, so the model checks several alternative futures at once instead of one linear draft.
EAGLE drafts at the feature level rather than the token level: a lightweight head predicts the target model’s internal hidden states, which the main model then uses to generate candidate tokens. Predicting features is easier than predicting tokens directly, which raises acceptance rates.
Self-speculative decoding selects a subset of the target model’s own layers to act as the draft model, skipping the rest. Since both draft and target live in the same weights, there is no second model to load or maintain.
Assisted generation is the name Hugging Face’s transformers library uses for its implementation, which pairs a large assistant model with a smaller candidate generator. Inference engines such as vLLM have added speculative decoding support too, so production deployments can enable it with a configuration flag.
When It Helps, and When It Doesn’t
Speculative decoding helps most when draft quality is high relative to the task. If the output is predictable (code completion, templated answers, repetitive structured text), a small draft model guesses correctly most of the time, and throughput jumps.
It helps less when the target model is being creative or uncertain. If the draft model keeps guessing wrong, every iteration accepts only one or two tokens and the drafting overhead adds latency instead of removing it. γ needs care too. Too small, and you leave speed on the table; too large, and you waste time drafting tokens that will never be accepted. Some inference engines tune it automatically.
One more practical note: speculative decoding reduces latency per token, but the draft step adds some overhead, so it shines on hardware where the target model is strongly memory-bound. On heavily compute-bound setups the win shrinks.
Frequently Asked Questions
Does speculative decoding change the output quality?
No. The acceptance rule is designed so that the final token sequence is distributed exactly as if the target model had generated it alone. You get the quality of the large model with the speed of the small one.
Does it need extra training?
Not necessarily. Draft models can be off-the-shelf small models, n-gram tables, or the target model’s own skipped layers. Methods like Medusa and EAGLE do fine-tune extra heads, but the core algorithm works with no training.
Is speculative decoding the same as quantization?
No, and they stack well together. Quantization shrinks the model so each memory load is cheaper; speculative decoding gets more tokens out of each load. Many deployments use both.