Chapter 7 · Inference and Serving 7.8
Speculative Decoding: Draft with a Small Model, Verify with a Large One
Speculative decoding lets a small, fast draft model guess the next few tokens and the large model verify them in one parallel forward pass, with an accept-and-correct rule that keeps the output distribution unchanged. This page derives the expected speedup and lets you tune it interactively.
After this page you will be able to
- Explain why decoding is slow and how guess, verify and correct speeds it up.
- Explain why the accept-and-resample rule leaves the output distribution unchanged, and check it in code.
- Derive the expected yield and speedup, and use the interactive lab to see how acceptance rate and draft length move them.
- Say where drafts come from and when speculative decoding does not pay off.
On this page
- Why decoding is slow, and why it can be sped up
- The core idea: guess, verify, correct
- Why the output distribution does not change
- How much faster: expected output and speedup
- Hands-on: the speculative decoding lab
- Where the draft comes from
- When it does not pay off
- Hands-on code: verify “the distribution is unchanged” and the expected output
- Summary and exercises
- Quick self-check
- Further reading
- FAQ
Speculative decoding lets a small, fast draft model guess the next tokens, then lets the large model verify them in a single parallel forward pass. An “accept with a probability, resample from a corrected distribution on rejection” rule guarantees that the output distribution is exactly the same as using the large model alone. The speedup is lossless: each round yields at least 1 token, and with luck . The actual gain is set by two quantities, the probability that a draft token is accepted and the time ratio of the draft model to the large model.
Why decoding is slow, and why it can be sped up
Autoregressive decoding produces one token at a time, and the next step has to wait for the previous one. At small batch sizes the bottleneck is not compute but moving all the weights from GPU memory into the compute units: every generated token reads the whole model once.
Take a 7B-parameter BF16 model decoding on an A100 80GB SXM (batch size 1, ignoring the reads of attention and the KV cache and kernel overheads):
| Quantity | Value | How it is obtained |
|---|---|---|
| BF16 weight size | 14 GB | parameters × 2 bytes |
| Memory bandwidth | 2,039 GB/s | NVIDIA A100 datasheet (80GB SXM) |
| BF16 dense compute | 312 TFLOPS | NVIDIA A100 datasheet |
| Time to read the weights once | 6.87 ms, an upper bound of about 146 tokens/s | 14 GB ÷ 2,039 GB/s |
| Compute time for one token | 0.045 ms | FLOP ÷ 312 TFLOPS |
| Compute time for 5 positions at once | 0.22 ms | 5 × 0.045 ms |
Reading the weights takes 6.87 ms while the compute for one token takes only 0.045 ms, a gap of about 153 times (the ratio of compute to bandwidth is FLOP/byte). Since the weights have to be read anyway, letting the large model process positions on that same pass is almost free. Speculative decoding finds positions worth processing together: a cheap draft model guesses a string of candidates and the large model verifies them in one go. The “ratio of compute to bandwidth” here is the ridge point of the roofline model, derived in GPUs and the Roofline Model.
The core idea: guess, verify, correct
One round of speculative decoding goes like this:
- Guess: the draft model autoregressively proposes candidate tokens and records the probability it gave to each.
- Verify: the large model concatenates the prefix with the candidates and runs one forward pass, which yields the distributions at positions at once.
- Accept or reject: check from left to right. Candidate is accepted with probability ; at the first rejection, stop, and discard all later candidates.
- Correct: at the rejected position, resample a token from the corrected distribution (next section). If all candidates are accepted, sample one extra “bonus” token from the distribution at position .
Why the output distribution does not change
Look at a single position. Let the target model’s distribution be and the draft model’s be . A draft token is accepted with probability , and on rejection a token is drawn from the corrected distribution:
Write . It is both the total probability that a draft token is accepted and equal to , where is the total variation distance. The denominator is exactly . The probability of outputting is therefore
The accepted part contributes , and the gap is filled in exactly by the corrected distribution; together they give . If a rejection sampled directly from instead, high-probability tokens would be counted twice and the distribution would be skewed. Later positions are used only when all earlier ones were accepted, so the per-position result extends to the whole sequence (Leviathan et al., 2023, Appendix A.1).
How much faster: expected output and speedup
Let the probability that each draft token is accepted be (assuming the positions are independent and identically distributed). The number of tokens produced in a round is “the number of consecutive acceptances (at most ) plus 1”:
One round costs draft steps plus 1 verification by the target model. Let one draft step take times as long as one target step ( is called the draft cost ratio). A round then takes , and the speedup over ordinary decoding is
This is Theorem 3.8 of Leviathan et al. Letting and , the speedup tends to . Table 1 of the paper gives several numbers for , and the widget below reproduces them, for example 6.86x for .
Hands-on: the speculative decoding lab
Drag the acceptance rate , the draft length and the draft cost ratio . The top chart shows the speedup as a function of , and the bottom chart shows the distribution of tokens produced per round, where the dots are the frequencies from simulating 2000 rounds with the same rule.
- A longer draft is not always better. With the defaults (, ), gives a 2.80x speedup. The optimum is at 3.09x, and stretching to drops it to 2.72x, because later draft tokens are less and less likely to be accepted yet still cost draft time.
- Even has a ceiling. For the limit is x. With you only get 3.36x, and you need to approach 5.0x.
- The acceptance rate matters more than the draft length. Keep and and lower from 0.8 to 0.6: the speedup falls from 2.80x to 1.92x, and the number of positions the target model has to process per kept token rises from 1.49x to 2.17x. Rejected drafts burn compute for nothing.
- An expensive draft eats the gain. At , raising from 0.05 to 0.3 shrinks the best from 8 to 3 and leaves only a 1.55x speedup.
- It can be slower. With , and the speedup is 0.65x, slower than not using it at all. For the speedup is , so it pays off only if .
Where the draft comes from
| Approach | Source of the draft | Characteristics |
|---|---|---|
| Separate small model | A smaller model of the same family with the same tokenizer | Plug and play, no training needed, but one more model to host. Leviathan et al. report that a draft about two orders of magnitude smaller than the target usually works best |
| N-gram lookup | A statistical language model; evaluating it is a table lookup, so | Lower : with a bigram model on T5-XXL English-to-German translation they got |
| Extra decoding heads (Medusa) | Several heads on top of the target model predict multiple future tokens in parallel | No separate draft model, and tree attention verifies several candidates at once; the heads need training |
| Feature-level drafting (EAGLE) | Autoregression on second-to-top-layer features predicts the draft | Reports a 2.7x to 3.5x latency speedup on LLaMA2-Chat 70B |
| Multi-token prediction module (MTP in DeepSeek-V3) | The MTP module that exists from training is reused at inference | Reports an acceptance rate of 85% to 90% for the second token across topics, and a 1.8x higher decoding throughput |
The DeepSeek-V3 numbers can be cross-checked with the formula above. Predicting one extra token beyond the next amounts to , and a round yields tokens in expectation. For to 0.90 that is 1.85 to 1.90, and the reported 1.8x is slightly below it. The gap can be read as the overhead of the draft module and verification: treating 1.8x as gives of about 0.03 to 0.06.
When it does not pay off
| Situation | Reason | Quantity involved |
|---|---|---|
| Low acceptance rate (open-ended writing, a draft model that is too weak) | Most candidates are rejected, so a round yields barely more than 1 token | small |
| The draft model is not cheap enough | Every round spends an extra | large |
| Large batch, decoding already compute-bound | Verifying positions is no longer free. In the A100 example above, compute is only saturated at a batch of about 150, after which the benefit shrinks quickly | a round no longer costs 1 |
| Tight memory | The draft model and its KV cache must be hosted as well | — |
Hands-on code: verify “the distribution is unchanged” and the expected output
The snippet below uses a toy distribution over 4 tokens to check two things: whether the frequencies produced by the accept-and-correct rule equal , and whether the average number of tokens per round matches the formula:
import numpy as np
rng = np.random.default_rng(0)
p = np.array([0.50, 0.25, 0.15, 0.10]) # target model's distribution at one position
q = np.array([0.25, 0.25, 0.25, 0.25]) # draft model's distribution at the same position
residual = np.maximum(p - q, 0)
residual /= residual.sum() # corrected distribution norm(max(0, p - q))
alpha = np.minimum(p, q).sum() # probability that one draft token is accepted
def one_position(n):
x = rng.choice(4, size=n, p=q) # the draft model proposes
accept = rng.random(n) < np.minimum(1, p[x] / q[x]) # accept with probability min(1, p/q)
out = np.where(accept, x, rng.choice(4, size=n, p=residual)) # on rejection, resample from the corrected distribution
return out, accept.mean()
out, rate = one_position(1_000_000)
print("output frequencies :", np.round(np.bincount(out, minlength=4) / len(out), 3))
print("target distribution:", p)
print(f"acceptance rate {rate:.3f}, theory sum(min(p, q)) = {alpha:.2f}")
gamma, rounds = 4, 200_000
x = rng.choice(4, size=(rounds, gamma), p=q)
accept = rng.random((rounds, gamma)) < np.minimum(1, p[x] / q[x])
n_accepted = np.where(accept.all(axis=1), gamma, accept.argmin(axis=1)) # number accepted before the first rejection
print(f"{np.mean(n_accepted + 1):.3f} tokens per round, formula (1-a^(g+1))/(1-a) = {(1 - alpha ** (gamma + 1)) / (1 - alpha):.3f}")
Output:
output frequencies : [0.5 0.25 0.149 0.1 ]
target distribution: [0.5 0.25 0.15 0.1 ]
acceptance rate 0.750, theory sum(min(p, q)) = 0.75
3.054 tokens per round, formula (1-a^(g+1))/(1-a) = 3.051
The output frequencies agree with to three decimals, and the simulated 3.054 tokens per round differs from the formula’s 3.051 only by sampling error.
Summary and exercises
Key points:
- Small-batch decoding is limited by memory bandwidth, so letting the large model process a few more positions barely adds any time.
- Speculative decoding has a draft model guess tokens, lets the large model verify them in one forward pass, accepts each with probability and resamples from the corrected distribution on rejection. The output distribution is exactly the same as with the large model alone.
- The expected output per round is tokens, and the speedup divides that by . A low acceptance rate, an expensive draft or a large batch shrinks the gain, even to below 1.
Quick self-check
1. Why does speculative decoding not lower the output quality?
- Because the draft model is as good as the large model
- Because draft tokens are accepted with probability min(1, p/q) and rejected ones are resampled from the corrected distribution norm(max(0, p−q)), so the output distribution at each position is exactly the target model’s
- Because the large model manually fixes all of the draft model’s mistakes
- Because it is only used with greedy decoding
The accepted part contributes min(p, q), and the gap p − min(p, q) is filled in by the corrected distribution; together they are exactly p. This holds at any sampling temperature, and greedy decoding is just a special case.
2. With acceptance rate α = 0.8 and draft length γ = 4, how many tokens does a round produce in expectation?
- 2.0
- 3.36
- 4.0
- 5.0
The expectation is (1 − 0.8⁵) / (1 − 0.8) = (1 − 0.32768) / 0.2 ≈ 3.36. The upper limit is γ + 1 = 5, which requires every candidate to be accepted.
3. Which of the following situations noticeably shrink the benefit of speculative decoding? (select all that apply)
- The draft model’s predictions disagree with the target model’s, so the acceptance rate is low
- The batch is large and decoding is already close to the compute limit
- The draft model is not cheap enough relative to the target model, so c is large
- The generated text is long
The first three correspond to a small α, verification no longer being free, and a large c. The longer the generation, the smaller the boundary effect of “each round calls the large model at least once” in the formula, so length is not a disadvantage.
4. Where should the token at a rejected position be sampled from?
- Directly from the target model’s distribution p
- From the corrected distribution norm(max(0, p − q))
- The draft model’s second most likely token
- Let the draft model sample again
The acceptance step has already contributed min(p, q), so only p − min(p, q) is left to fill in. Sampling directly from p would count high-probability tokens twice and change the distribution.
Exercises:
- For , how many tokens does a round produce in expectation, and what is the speedup?
- In the lab set . What is the best , and why is it much smaller than at ?
- The target distribution is and the draft distribution is uniform. Find the acceptance rate , then the expected number of tokens per round for .
Reference answers
- tokens. With a round takes 1, so the speedup is also 2.71x, which agrees with Table 1 of the paper.
- The best , with a speedup of about 1.55x. Once draft steps get expensive, every extra guessed token costs another target steps while the chance that later candidates are accepted keeps decaying as , so it is better to stop early.
- . The expected output per round is tokens, which matches the 3.051 from the code above.
Further reading
-
Paper readings: Fast Inference from Transformers via Speculative Decoding and DeepSeek-V3 (multi-token prediction). Related techniques: Decoding and Sampling, KV Cache and Inference Performance, Serving and Model Quantization.
-
Leviathan, Kalman and Matias, Fast Inference from Transformers via Speculative Decoding (ICML 2023): the acceptance rule, Theorem 3.8 and Table 1 used on this page come from this paper.
-
Chen et al., Accelerating Large Language Model Decoding with Speculative Sampling (2023): independent concurrent work from DeepMind, reporting a 2x to 2.5x speedup on Chinchilla 70B.
-
DeepSeek-AI, DeepSeek-V3 Technical Report (2024): multi-token prediction and its acceptance rate.
-
NVIDIA, A100 Tensor Core GPU datasheet: the bandwidth and compute figures used on this page.
-
Spector and Re, An Online Speculative Decoding Framework (2023): decide online whether to keep speculating based on the acceptance rate, falling back to ordinary decoding under light load.
-
Miao et al., SpecInfer (MLSys 2024): verifies multiple draft paths in parallel via a token tree, raising accepted tokens per step.
-
Fu et al., EAGLE-2 (2024) and EAGLE-3 (2025): feature-level draft heads push acceptance rates higher and are now a mainstream production approach.
-
Yan et al., Lookahead Decoding (2024): advances several positions in parallel via Jacobi iterations, with no separate draft model.
FAQ
- Does speculative decoding change the model's output?
- No. It accepts a draft token with probability min(1, p/q) and, on rejection, samples from a corrected distribution, which makes the output distribution at every position exactly equal to the target model's distribution p. The speedup is lossless, and with greedy decoding you get the target model's own greedy sequence (up to floating-point error). It changes the speed, not the quality.
- How should I choose the draft model?
- The most common choice is a small model from the same family with the same tokenizer. Leviathan et al. report that a draft model about two orders of magnitude smaller than the target usually works best, because the acceptance rate has to be balanced against the cost of drafting. If you do not want to maintain a separate draft model, you can use Medusa's extra decoding heads, EAGLE's feature-level drafting, or, as in DeepSeek-V3, reuse the multi-token prediction (MTP) module that already exists from training.
- How much faster does speculative decoding make generation?
- It depends on the acceptance rate, the drafting cost, the hardware and the batch size, so there is no fixed number. Published reports include 2x to 3x on T5-XXL (Leviathan et al.), 2x to 2.5x on Chinchilla 70B (Chen et al.), a 2.7x to 3.5x latency speedup for EAGLE on LLaMA2-Chat 70B, and a 1.8x higher decoding throughput from MTP in DeepSeek-V3.
- Is speculative decoding still useful at large batch sizes?
- The benefit shrinks. Speculative decoding exploits the fact that at small batch sizes decoding is limited by memory bandwidth and compute is idle. Once the batch is large enough to saturate compute (for a 7B model on an A100, roughly a batch of 150), verifying γ+1 positions is no longer free, and rejected drafts waste compute.
- Can speculative decoding be combined with KV cache and quantization?
- Yes, they stack. The KV cache means the target model only processes the new positions when verifying, and quantization means each step reads fewer weight bytes; both lower the cost of one target step. Speculative decoding reduces the number of serial target-model calls. The draft model can be quantized too, which lowers the draft cost ratio c.