Speculative decoding lets a cheap draft guess several tokens and the big model verify them in one pass, often cutting latency 2-3x with identical output. Here is the acceptance math, the main variants, and when it slows you down.
Speculative decoding makes a large language model generate text two to three times faster at small batch sizes without changing a single output token, because it turns a memory-bound sequential loop into a cheap guess followed by one parallel check. The catch is that the speedup is a function of two numbers most teams never measure (how often the guesses are accepted, and how busy the GPU already is), and when either one is wrong the technique quietly costs you throughput instead of saving latency.
This post walks through why the trick works, the exact acceptance rule that keeps it lossless, the arithmetic that predicts your speedup, how the main variants (draft models, Medusa, EAGLE, n-gram lookup, multi-token prediction) differ, and the conditions under which you should turn it off.
Autoregressive decoding produces one token per forward pass. For every token, the GPU streams the model's entire weight matrix out of HBM, does a sliver of arithmetic on a single position, and writes back one row of KV cache. At batch size 1 a 70B-parameter model in FP8 moves roughly 70 GB of weights to produce a few bytes of output. The tensor cores spend most of that time idle, waiting on memory. That is the same bandwidth wall that limits on-device LLM inference, just at data-center scale.
The useful consequence: a forward pass over 5 positions costs almost the same wall-clock time as a forward pass over 1, because the weights are read once either way and the extra arithmetic fits in the idle compute. Prefill already exploits this. Speculative decoding exploits it during generation by giving the big model several candidate tokens to score at once.
The technique was published almost simultaneously by Leviathan, Kalman and Matias at Google (Fast Inference from Transformers via Speculative Decoding) and by Chen and colleagues at DeepMind (Accelerating Large Language Model Decoding with Speculative Sampling). Each step has three parts:
The worst case is still progress: even if the very first draft token is rejected, the target pass produces one corrected token, which is exactly what normal decoding would have produced. You lose the draft's compute, not correctness.
The part people skip is the reason the technique is safe. Let p(x) be the target's probability for token x at a position and q(x) the draft's. For each draft token, in order:
x with probability min(1, p(x) / q(x)).max(0, p(x) − q(x)), renormalized, and stop.The proof in both papers shows the tokens produced this way follow the target distribution p exactly. Where the draft is overconfident (q > p) tokens get thinned out; the residual adds back exactly the mass the draft under-weighted. Under greedy decoding the rule collapses to something simpler: accept a draft token if and only if it equals the target's argmax.
Here is the rule in a few lines of Python, for one position:
import numpy as np
def verify_position(draft_token, p, q, rng):
"""p, q: target and draft probability vectors over the vocabulary."""
if rng.random() < min(1.0, p[draft_token] / q[draft_token]):
return draft_token, True # keep going to the next draft token
residual = np.maximum(p - q, 0.0)
residual /= residual.sum()
return rng.choice(len(p), p=residual), False # replacement token, stop here
One caution for production: "lossless" describes this exact rule, not every implementation that calls itself speculative decoding. Serving engines expose knobs that trade exactness for acceptance rate (Medusa's "typical acceptance" scheme is deliberately lossy, and vLLM's speculative decoding docs list several rejection-sampling methods, including a lossy verifier). Know which one your config selects before you claim outputs are unchanged.
Two parameters drive everything: the draft length γ and the acceptance rate α (the chance a given draft token survives verification). Treating acceptances as independent, the expected number of tokens committed per target pass is:
E[tokens per pass] = (1 − α^(γ+1)) / (1 − α)
Wall-clock speedup also has to pay for drafting. If one draft step costs a fraction c of a target step, the Leviathan paper gives:
speedup = (1 − α^(γ+1)) / ((1 − α)(γc + 1))
Plugging in realistic values with a draft that costs 5% of the target per step (c = 0.05):
| Acceptance rate α | Tokens per target pass (γ = 4) | Speedup (γ = 4) | Speedup (γ = 8) |
|---|---|---|---|
| 0.5 | 1.94 | 1.61x | 1.43x |
| 0.6 | 2.31 | 1.92x | 1.77x |
| 0.7 | 2.77 | 2.31x | 2.28x |
| 0.8 | 3.36 | 2.80x | 3.09x |
| 0.9 | 4.10 | 3.41x | 4.38x |
Three things fall out of this table. First, acceptance rate dominates: going from 0.6 to 0.8 is worth more than any amount of tuning γ. Second, longer drafts only pay when acceptance is high; at α = 0.5, γ = 8 is slower than γ = 4 because the tail of the draft is almost always thrown away. Third, the draft has to be genuinely cheap. With c = 0.2 (a draft one fifth the target's cost), the α = 0.8, γ = 4 case drops from 2.8x to about 1.9x.
Real acceptance is not independent per position (a draft that goes wrong tends to stay wrong), so treat the formula as a planning estimate and measure the actual mean accepted length on your traffic.
All the variants answer the same question differently: where do the guesses come from, and how much do they cost to produce and maintain?
| Method | Where drafts come from | Extra training | Typical fit |
|---|---|---|---|
| Separate draft model | A smaller model sharing the target's tokenizer | None if a family sibling exists | General chat when a small sibling model exists |
| Medusa | Extra decoding heads on the target's last hidden state, tree verification | Train the heads (target frozen or jointly tuned) | Self-hosted models where a second model is a burden |
| EAGLE / EAGLE-3 | A lightweight head that autoregresses over the target's internal features | Train the head per target model | Highest acceptance among drafted methods; the common default in serving engines |
| N-gram / prompt lookup | Copy spans that already appear in the prompt or earlier output | None | Code edits, RAG answers that quote sources, rewriting |
| Multi-token prediction (MTP) | Prediction modules trained into the model itself | Done at pre-training time | Models shipped with MTP heads |
| Lookahead decoding | Jacobi-style parallel iteration on the target alone | None | When no draft is available and acceptance from n-grams is poor |
The original recipe. The draft must share the tokenizer (or you need a translation layer, which mostly destroys the gains), and it should be trained on similar data so its guesses track the target's style. The operational cost is real: a second set of weights, its own KV cache, and a second model to upgrade every time the target changes.
Medusa bolts several extra heads onto the target's final hidden state, each predicting a token further ahead, and verifies a tree of candidate continuations in a single pass using a tree-shaped attention mask. No second model to host, but each head guesses blind to the tokens chosen by the heads before it, which caps acceptance.
EAGLE fixes that by running a small autoregressive head over the target's second-to-top-layer features instead of over tokens, feeding in the token actually sampled so the head knows which branch it is on. The observation is that features are far more predictable than tokens. EAGLE-3 drops the requirement to predict features exactly, fuses features from several layers, and trains the head on its own outputs ("training-time test"), which lets acceptance keep improving as you add training data. The authors report speedups up to roughly 6x at batch size 1 on some benchmarks; production numbers on mixed traffic are usually lower, and the published figures are all measured on specific target models with heads trained for them.
Prompt lookup decoding needs no model at all: if the last few generated tokens match a span in the prompt, propose whatever followed that span. It sounds crude, but for an agent rewriting a file, a RAG answer quoting retrieved passages, or a model echoing a JSON structure, a large fraction of output tokens are literal copies. vLLM's ngram method and its suffix method (which also matches against previous responses) do exactly this. Lookahead decoding generalizes the idea by generating its own n-gram candidates in parallel with Jacobi iteration.
Some recent models are pre-trained with multi-token prediction modules that predict a token or more beyond the next one. DeepSeek-V3 is the best-known example; its technical report says the extra predicted token was accepted roughly 85 to 90 percent of the time when used for speculative decoding. When a model ships with MTP heads, they are usually the best draft available, because they were trained alongside the weights they are guessing for.
All of the major engines covered in our vLLM, SGLang and TensorRT-LLM comparison support some form of speculative decoding. In vLLM it is one JSON config. Prompt lookup, which needs nothing extra:
vllm serve <target-model> \
--speculative-config '{
"method": "ngram",
"num_speculative_tokens": 4,
"prompt_lookup_min": 2,
"prompt_lookup_max": 5
}'
For a trained EAGLE-3 head, set "method": "eagle3" and point "model" at the head checkpoint built for your exact target model. A head trained for a different fine-tune of the same base will load and run, then accept far fewer tokens than advertised.
Interactions to check before shipping:
p(x)/q(x) for the draft's favorite tokens and with it acceptance.The whole technique rests on idle compute during decoding. Anything that removes that idle compute removes the gain.
Large batches. At high concurrency the GPU is already doing useful arithmetic on many sequences per weight load, so decoding becomes compute-bound. Verifying γ extra positions per sequence then costs real FLOPs, and every rejected token is pure waste. Throughput-oriented batch jobs (offline summarization, evals, synthetic data generation) frequently get slower with speculation on. Some engines adapt γ to load or disable speculation above a batch threshold; if yours does not, measure throughput at your real concurrency, not just single-stream latency.
Low acceptance. Creative writing at temperature 1.0, a draft trained on chat answering questions about code, a target fine-tuned on a domain the draft never saw: all of these push α toward 0.5, where the table shows gains collapsing to 1.5x or less, before counting the draft's memory.
Memory pressure. A draft model and its KV cache take GPU memory that would otherwise hold more concurrent sequences. On a memory-bound deployment that trade can lower total tokens per second per GPU even while each individual request gets faster.
Tiny outputs. If most responses are a few dozen tokens (classification labels, short tool calls), time to first token dominates and speculation has little decode time to shrink.
Speculative decoding is the closest thing inference has to a free latency win, but only in the regime it was designed for: memory-bound decoding at modest batch sizes, with a draft whose guesses the target agrees with. Before enabling it, log two numbers on real traffic, the mean accepted length per target pass and the throughput at your actual concurrency. If mean accepted length is above about 2.5 and throughput at peak load does not drop, keep it on. If your workload copies a lot from its context, start with n-gram lookup because it costs nothing. If your model ships MTP heads or has a well-matched EAGLE-3 head, use those before reaching for a separate draft model.
Free, in your browser, no sign-up.
One email when a new post goes up. No other mail; unsubscribe in one click.
We store your email only to send new posts. See the privacy policy.