Speculative Decoding
Draft small model + verify with large model to speed generation without quality loss.
In plain words
A small fast model guesses the next few words, and the big model checks all of them at once; every correct guess saves the big model a turn.
Think of it like…
A junior writes a paragraph quickly and a senior editor reads the whole draft in one go, keeping everything up to the first mistake and fixing that spot: the senior's scarce time goes into checking in bulk, not writing word by word.
Where you’ve seen it
A 70B target model has a 20 ms decode step at batch 1 (50 tokens per second). A 1B draft model runs a step in 1 ms and proposes k = 4 tokens; the target verifies them in one 20 ms pass. With a per-token acceptance rate α = 0.8, the expected tokens produced per iteration are (1 − α^(k+1)) / (1 − α) = (1 − 0.8⁵) / 0.2 = 3.36. One iteration costs 4 × 1 ms + 20 ms = 24 ms, so throughput is 3.36 ÷ 0.024 = 140 tokens per second, a 2.8 times speedup over 50. If the domain is harder and α drops to 0.6, expected tokens are 2.31 and the speedup is 1.92 times; at α = 0.4 it is 1.37 times. At batch 32, where the GPU is already compute-saturated, verifying 5 tokens per sequence consumes extra compute and the benefit largely disappears, so the team enables it only on the low-concurrency latency tier.
Words you’ll hear
- Draft and target
- The cheap proposer and the large model whose distribution must be preserved.
- Acceptance rate (α)
- The probability that a drafted token is accepted by the target.
- Rejection sampling
- A verification rule that accepts or resamples tokens so the output matches the target exactly.
- Speculation length (k)
- How many tokens the draft proposes per verification step.
Visual diagram
Theory & deep dive
Why verification is cheap and the speedup formula
A decode step is memory-bandwidth-bound: the GPU spends its time streaming weights, not computing, so evaluating the target on k + 1 positions at once costs only slightly more than one position. Speculative decoding exploits this: the draft proposes tokens x₁ ... x_k, the target computes its next-token distributions for all positions in one pass, and each drafted token is accepted with probability min(1, p_target / p_draft); at the first rejection, a replacement token is sampled from the normalised residual distribution, and if all k are accepted the target contributes a bonus token. This rejection sampling guarantees the emitted tokens follow exactly the target distribution (for greedy decoding it reproduces the target's greedy output).
If each drafted token is accepted independently with probability α, the expected number of tokens per iteration is (1 − α^(k+1)) / (1 − α). With α = 0.8 and k = 4 that's 3.36. If a draft step costs a fraction c of a target step (c = 1 ms / 20 ms = 0.05), an iteration costs (1 + k c) target-step-equivalents = 1.2, so the speedup is 3.36 ÷ 1.2 = 2.8. Too large a k wastes draft work (later tokens are rarely accepted), too small leaves speedup on the table; the best k is typically 3 to 8 and depends on α and c. Real acceptance is not independent (it varies by position and content) so measure it.
k = 4, draft cost c = 0.05, iteration cost 1.2: α = 0.8 → 3.36 tokens → 2.80× faster; α = 0.6 → 2.31 → 1.92×; α = 0.4 → 1.65 → 1.37×. Better alignment between draft and target pays off directly.
Draft options, deployment and limits
Drafting options: a separate small model from the same family (shares tokenizer and style; easiest to deploy); self-speculation variants such as Medusa heads or EAGLE-style feature predictors added to the target and trained on its outputs (no second model, but training required); n-gram or prompt-lookup drafting that copies from the prompt (excellent for summarisation, code editing and RAG where output repeats input, with zero training); and early-exit or layer-skip drafts. Draft quality is domain-dependent: a draft trained or distilled on your target's outputs and domain accepts more tokens. Temperature matters too: high-temperature sampling lowers acceptance, while greedy or low-temperature decoding raises it.
Operationally, evaluate on your traffic: measure acceptance rate, tokens per target pass, end-to-end tokens per second and latency at your real batch sizes. Benefits are largest at low concurrency (latency-bound), and shrink as batches grow, since verification then uses compute that other sequences could have used; many deployments enable speculation only for latency-critical tiers or dynamically when load is low. Costs include extra memory for the draft model and its KV cache, scheduling complexity in continuous batching and tuning k per workload. Because outputs are unchanged in distribution, you don't need quality re-evaluation beyond verifying the implementation is correct (for example comparing greedy outputs with and without speculation). It complements, rather than replaces, quantisation, batching and prefix caching.
Summarising a contract, many output n-grams already appear in the input. A prompt-lookup draft proposes the continuation of the matching input span for free; acceptance rates of 0.7 to 0.9 on such tasks give a 2× speedup with no draft model at all.
How it works, step by step
Step 1 of 41. Choose a draft mechanism
Pick a small same-family model, trained prediction heads or prompt-lookup drafting depending on the task.
- Same
- tokenizer
When to use it & trade-offs
What it is
Speculative decoding speeds up generation without changing the output distribution. A small, fast draft mechanism (a small model, extra prediction heads or a prompt-lookup n-gram matcher) proposes the next k tokens; the large target model then verifies all k in a single forward pass, accepting the longest prefix that matches what it would have produced and sampling one corrected token at the first mismatch, using rejection sampling so the result is statistically identical to sampling from the target alone. Because decoding is memory-bandwidth-bound, checking k tokens costs about as much as generating one, so each target pass can yield several tokens.
Why it matters: Decode speed limits per-user latency for long answers: one token per memory-bound pass of a very large model. Speculative decoding converts spare compute into fewer sequential passes, commonly giving 2 to 3 times faster generation at low batch sizes with no quality loss, which matters for interactive chat, agents with long outputs and latency-sensitive products. Its gains depend on how well the draft predicts the target and shrink under heavy batching, so the decision is empirical.
When to reach for it
- Interactive chat with long answers
- Code and document editing with high input-output overlap
- Low-concurrency latency tiers
When to avoid or be careful
- Assuming speedups hold at high batch sizes
- Using a draft from a different tokenizer or domain
- Setting k very high without measuring acceptance
Ways to speed up decoding
Strengths: Lossless; 2–3× speedups are common.
Watch out: Extra draft memory; gains fall at high batch.
Strengths: Less memory traffic; more capacity.
Watch out: Possible quality loss.
Strengths: Large speed and cost gains.
Watch out: Quality ceiling.
Interview signals & numbers to know
When this topic comes up
- “Decoding is slow for long outputs”
- Draft and verify
- Acceptance rate
- Medusa or EAGLE heads
- Prompt lookup decoding
Benchmarks & rules of thumb
- (1 − α^(k+1)) / (1 − α)
- expected tokens per verification pass
- 3.36 tokens → 2.8×
- α = 0.8, k = 4, draft cost 0.05
- 1.92× at α 0.6
- speedup when the draft is weaker
Common mistakes & follow-ups
Common interview mistakes
- Enabling speculation for a heavily batched service and seeing no gain.
- Evaluating on easy prompts and overestimating acceptance.
- Forgetting the draft's own memory and latency cost.
Likely interviewer follow-ups
- Why is speculative decoding lossless?
- How does acceptance rate affect speedup?
- When would you not use speculative decoding?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Speculative Decoding with generative AI interview Q&A and hands-on practice.