Speculative decoding: how draft tokens cut LLM latency
Speculative decoding has a cheap draft propose tokens that the target model checks in one pass. How it works, the speedup math, and when it stops paying off.
- Published
- Reading time
- 12 min read
In short
- Speculative decoding has a cheap draft propose several tokens and the target model verify them in one forward pass. A rejection-sampling rule keeps the output distribution the same as the target model's.
- It works because decoding is limited by memory bandwidth rather than arithmetic, so checking several tokens in one pass costs about as much as generating one.
- The gain depends on the acceptance rate. With 80% acceptance and four draft tokens, the paper's formula predicts about 3.4 tokens per target pass; at 20%, almost nothing.
- It lowers inter-token latency at low batch sizes and does nothing for time to first token. Under heavy load the spare compute it depends on disappears, so measure acceptance per workload before you rely on it.
Speculative decoding is an inference technique in which a cheap draft proposes several next tokens and the large target model checks all of them in a single forward pass. The target keeps the longest run of drafts it agrees with, adds one token of its own, and the cycle repeats. When the drafts are usually right, the model produces several tokens for the cost of one step, and a sampling rule from the original paper keeps the output distribution exactly the same as the target model's.
This deep dive covers why that works, the acceptance rule that preserves the output, the speedup formula and its assumptions, the main ways to produce drafts, and what speculative decoding does to the latency numbers you track. The short version: it is a reliable win for latency-sensitive traffic at low batch sizes, and a weak or negative one for a busy server.
Why one forward pass can check several tokens
A forward pass during decoding is limited by how fast the GPU can read memory, not by how fast it can do arithmetic. The model reads all of its weights to produce one token per sequence, and the arithmetic units wait on that read. Scoring a few extra positions in the same pass uses compute that would otherwise sit idle.
The numbers make this concrete. An 8-billion-parameter model stored in 16-bit precision has about 16 GB of weights. An H100 SXM reads memory at 3.35 TB/s.
time to read the weights once = 16 GB / 3.35 TB/s ≈ 4.8 ms
upper bound at batch size 1 = 1 / 4.8 ms ≈ 209 tokens per secondThat ceiling holds no matter how many arithmetic units the GPU has, and it ignores the KV cache, which adds more reads per step. The speculative decoding paper by Leviathan, Kalman, and Matias builds on exactly this observation: inference "is often not bottlenecked on arithmetic operations" but on "memory bandwidth and communication." If a pass costs the same whether it scores one position or five, the only question is how to get good guesses for the other four.
How draft-then-verify works
Speculative decoding runs in rounds. Each round, a draft proposes a short sequence of tokens, the target model scores the whole sequence in one pass, and an acceptance rule decides how many drafted tokens to keep. Every round produces at least one token, so the worst case is ordinary decoding plus the cost of the draft.
One round, with the draft length set to four:
- The draft generates four tokens one at a time. A draft is cheap, so this takes a fraction of a target step.
- The target model runs one forward pass over the context plus the four drafted tokens. Because it scores every position at once, it gets its own probability for each drafted token, plus a distribution for the position after the last one.
- The acceptance rule walks the drafts in order and keeps them until the first rejection.
- At the rejection point, the target samples a replacement token. If nothing was rejected, it samples one extra token from the last distribution it computed.
The KV cache entries for rejected tokens are thrown away, and the next round starts from the last kept token. KV cache explained covers why that bookkeeping is cheap in an engine that manages the cache in blocks.
The acceptance rule that keeps outputs identical
The acceptance rule compares the target's probability for each drafted token with the draft's probability for it. Tokens the target likes at least as much as the draft are always kept. Tokens the draft overrated are kept only some of the time. That combination makes the final output a sample from the target model's own distribution.
In the paper's notation, p is the target model's distribution and q is the draft's.
for each drafted token x, in order:
if q(x) <= p(x): keep x
else: keep x with probability p(x) / q(x)
if rejected: sample a replacement from norm(max(0, p - q)) and end the round
if every draft was kept: sample one more token from p at the next positionThe replacement distribution, the normalized positive part of p - q, adds back exactly the probability mass the rejection step removed. The paper proves the resulting tokens follow p, and a second paper from the same period describes the same idea as "a novel modified rejection sampling scheme which preserves the distribution of the target model." At temperature 0 the rule reduces to a simple check: keep a drafted token when it matches the target's top choice.
In practice the guarantee holds up to floating-point limits. vLLM's speculative decoding docs call it "theoretically lossless up to the precision limits of hardware numerics," and warn that batch size changes can shift log probabilities. Some newer variants relax verification on purpose and are not distribution preserving, so read the method's documentation before you assume the output is unchanged.
Acceptance rate and the speedup formula
The acceptance rate is the expected probability that the target keeps a drafted token. It sets the speedup. The paper gives the expected number of tokens per target pass as (1 - α^(γ+1)) / (1 - α), where α is the acceptance rate and γ is the number of drafted tokens per round.
The formula assumes acceptances are independent and identically distributed, which real text does not quite satisfy. Theorem 3.8 of the paper then turns tokens per pass into an expected wall-time improvement:
tokens per target pass = (1 - α^(γ+1)) / (1 - α)
wall-time improvement = (1 - α^(γ+1)) / ((1 - α) x (γc + 1))
α = acceptance rate
γ = drafted tokens per round
c = time for one draft step / time for one target stepThe second formula also assumes that verifying γ + 1 positions costs the same as one target step, which is true only while decoding is memory bound. Here is what it predicts with four drafted tokens and a draft that runs at 5% of the target's step time:
| Acceptance rate (α) | Tokens per target pass | Predicted speedup (γ = 4, c = 0.05) |
|---|---|---|
| 0.9 | 4.10 | 3.41x |
| 0.8 | 3.36 | 2.80x |
| 0.6 | 2.31 | 1.92x |
| 0.4 | 1.65 | 1.37x |
| 0.2 | 1.25 | 1.04x |
Two lessons follow. Acceptance rate dominates everything else, and the right draft length depends on it. At an acceptance rate of 0.4, drafting two tokens instead of four predicts 1.42x instead of 1.37x, because fewer drafts are wasted. At 0.9, drafting eight predicts about 4.4x. A slower draft makes everything worse: at c = 0.1, the 0.2 row drops below 1, which means slower than not speculating.
The paper's own measurements fit this picture. With T5-small drafting for the 11-billion-parameter T5-XXL on English-to-German translation, acceptance was 0.75 at temperature 0 and 0.62 at temperature 1, for measured speedups of 3.4x and 2.6x. Higher sampling temperature lowered acceptance, and the speedup fell with it.
Where the draft tokens come from
Drafts can come from a separate small model, from extra heads trained onto the target, from a light layer that predicts the target's internal features, or from text already in the prompt. The choices trade training effort against acceptance rate, and each has its own published results.
| Method | Where drafts come from | Training needed | Published result |
|---|---|---|---|
| Separate draft model | A smaller model with the same tokenizer | None, if a compatible small model exists | 2x to 3x on T5-XXL; 2x to 2.5x on Chinchilla 70B in a distributed setup |
| Medusa | Extra decoding heads on the target, checked together as a tree | Train the heads; Medusa-1 keeps the backbone frozen | Over 2.2x for Medusa-1, 2.3x to 3.6x for Medusa-2 |
| EAGLE | A light layer that predicts the target's second-to-top-layer features | Train the draft layer | 2.7x to 3.5x latency speedup on LLaMA2-Chat 70B |
| N-gram (prompt lookup) | Token spans copied from the prompt or earlier output | None | Strongest when output repeats the input, as in summarization and document QA |
| Multi-token prediction (MTP) | Prediction heads the model was trained with | None at serving time; the model must include them | Depends on the model |
Medusa adds heads that "predict multiple subsequent tokens in parallel" and verifies several candidate continuations at once with tree attention. EAGLE argues that "autoregression at the feature (second-to-top-layer) level is more straightforward than at the token level," and reports doubled throughput on top of the latency gain. Prompt lookup decoding replaces the draft model with string matching against the prompt, which costs almost nothing and works when the output copies spans of the input.
Speculative decoding in vLLM, SGLang, and TensorRT-LLM
All three major open-source serving engines support speculative decoding, with different sets of draft methods. The method list matters less than whether a trained draft exists for your exact target model, since EAGLE and Medusa heads are trained per model.
| Engine | Draft methods in its docs | What the docs say about fit |
|---|---|---|
| vLLM | EAGLE (including EAGLE-3), MTP, separate draft model, n-gram, suffix decoding | Aimed at "medium-to-low QPS (queries per second), memory-bound workloads" |
| SGLang | EAGLE-2, EAGLE-3 (recommended), MTP, standalone draft model, n-gram (CUDA only) | Leave the three draft-shape flags unset for auto-tuning, or set all three |
| TensorRT-LLM | Draft-target model, n-gram, Medusa, ReDrafter, EAGLE-1 and EAGLE-2, lookahead decoding | Aimed at cases where "the GPU is underutilized due to small batch sizes" |
In vLLM, the setting is a speculative config passed to the server, with a method and a draft length. SGLang selects the method with --speculative-algorithm and tunes the draft shape with --speculative-num-steps, --speculative-eagle-topk, and --speculative-num-draft-tokens. SGLang's docs note that a wider draft tree improves acceptance but uses more memory and compute, and that deeper drafts risk "rejection cascades." If you are still choosing an engine, vLLM vs SGLang compares them more broadly.
vllm serve <target-model> \
--speculative-config '{"method": "draft_model", "model": "<draft-model>", "num_speculative_tokens": 5}'When speculative decoding helps and when it hurts
Speculative decoding helps when the GPU has idle compute and the drafts are usually right. It hurts when the GPU is already busy, when acceptance is low, or when memory is tight. Most production disappointment comes from enabling it on a busy server after testing it at batch size 1.
| Condition | Effect | Why |
|---|---|---|
| Low batch size, latency-sensitive traffic | Largest gain | Decoding is memory bound, so verification uses idle compute |
| Predictable output: copied spans, structured formats, low temperature | Gain | Acceptance rate is high |
| High batch size, high request rate | Small or negative | The GPU is closer to compute bound, so extra positions are no longer free |
| High sampling temperature or open-ended text | Small | Acceptance falls, as the paper's temperature 1 results show |
| Tight GPU memory | Can lower throughput | Draft weights and draft KV cache take space from live requests |
The batch-size effect is the one to plan around. As more sequences share each forward pass, the weight read is spread across more tokens, and the spare compute that verification relied on gets used by real requests. That is why vLLM and TensorRT-LLM both describe the technique in terms of low request rates and small batches. A server that runs hot during the day and quiet at night may gain at night and lose at peak.
Which latency numbers speculative decoding moves
Speculative decoding lowers inter-token latency and raises output tokens per second for each request. It does not lower time to first token. If your users complain about the wait before the answer starts, look elsewhere.
| Number | Effect | Reason |
|---|---|---|
| Time to first token | No improvement; can rise slightly | Prefill is unchanged, and a separate draft model must also read the prompt |
| Inter-token latency (average) | Falls | Several tokens per target step |
| Inter-token latency (spread) | Widens | Tokens arrive in bursts of accepted drafts, then pause |
| Tokens per second, per request | Rises | Same as above |
| Throughput, whole server at high load | Flat or lower | Verification competes with other requests for compute |
The burstiness matters for streaming interfaces. A stream that delivers four tokens, pauses, then delivers two can feel less smooth than a steady stream with a slightly lower average rate. Record inter-token latency percentiles, not only the mean.
How to measure speculative decoding in production
Measure acceptance rate per workload, then measure latency at your real load. A single benchmark number tells you little, because acceptance changes with the kind of text, the temperature, and the draft, and the speedup changes with batch size.
- Track acceptance rate by traffic class. Code completion, chat, summarization, and JSON extraction will each settle at a different rate. vLLM's docs list per-request acceptance metrics for this purpose.
- Pick the draft length from the acceptance rate. Low acceptance wants short drafts; high acceptance can use longer ones. The formula above gives a starting point; your measurements give the answer.
- A/B test at production load. Compare inter-token latency percentiles and server throughput with and without speculation on the same hardware, at the batch sizes you actually run.
- Check correctness once. At temperature 0, outputs with and without speculation should match apart from floating-point effects. A systematic difference means a lossy method or a bug.
- Budget the memory. Count the draft's weights and KV cache against the cache budget for live requests.
The position worth taking: turn speculative decoding on for interactive, latency-bound endpoints with a draft trained for your target model, and leave it off for batch and high-throughput endpoints until a load test says otherwise. The cost is one more component to version with the model, and a speedup that changes with traffic.
Frequently asked questions
What is speculative decoding?
Speculative decoding is a way to generate several tokens per forward pass of a large model. A cheap draft proposes a few tokens, the large target model scores them all in one pass, and a rejection-sampling rule keeps a prefix of them plus one token from the target. Because decoding is memory bound, checking several tokens costs about the same as generating one.
Does speculative decoding change the model's output?
Standard speculative decoding does not change the output distribution. The acceptance rule, proven in the original paper, makes accepted and replacement tokens follow the target model's probabilities exactly. In practice, floating-point effects can cause small differences, and some newer variants relax verification on purpose. Check that the method you enable is described as distribution preserving.
What is a good acceptance rate for speculative decoding?
A good acceptance rate is one high enough that the predicted speedup clearly exceeds 1 at your draft cost. With four drafted tokens and a draft at 5% of the target's step time, 0.6 predicts about 1.9x and 0.8 about 2.8x, while 0.2 predicts almost no gain. The original paper measured 0.53 to 0.75 with T5-small drafting for T5-XXL.
Does speculative decoding reduce time to first token?
No. Time to first token is dominated by queueing and prefill, which speculative decoding does not change. With a separate draft model, the draft also has to process the prompt, so time to first token can rise slightly. Speculative decoding lowers inter-token latency and raises tokens per second once the answer has started.
What is a draft model in speculative decoding?
A draft model is a smaller, faster model that proposes the next few tokens for the large target model to verify. It must share the target's tokenizer. The closer its predictions are to the target's, the higher the acceptance rate. Alternatives to a separate draft model include Medusa heads, EAGLE draft layers, and n-gram lookup from the prompt.
Does speculative decoding work at high batch sizes?
Speculative decoding helps less as batch size grows and can slow a busy server down. At high batch sizes the GPU's spare compute is already used by real requests, so verifying extra drafted positions is no longer free. vLLM's docs aim it at medium-to-low request rates, and TensorRT-LLM's at GPUs underutilized by small batches.
Sources
- 01Fast Inference from Transformers via Speculative DecodingarXiv:2211.17192
- 02Accelerating Large Language Model Decoding with Speculative SamplingarXiv:2302.01318
- 03Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding HeadsarXiv:2401.10774
- 04EAGLE: Speculative Sampling Requires Rethinking Feature UncertaintyarXiv:2401.15077
- 05Prompt lookup decodingGitHub
- 06Speculative decodingvLLM docs
- 07Speculative decodingSGLang docs
- 08Speculative samplingTensorRT-LLM docs
- 09NVIDIA H100 Tensor Core GPUNVIDIA