Fast Inference from Transformers via Speculative Decoding
TL;DR. A small draft model guesses the next γ tokens. The large target model scores all of them in one parallel pass. A rejection rule keeps each guess with probability min(1, p/q) and, on the first rejection, samples a replacement from the leftover probability mass. The output distribution is exactly the target model’s, but each expensive pass now yields several tokens. Leviathan et al. report 2–3× speed-ups on T5-XXL; Chen et al. report about 2× on Chinchilla 70B.
Why it matters now. Long answers from RAG readers, long reasoning traces, and the rollouts of RL-trained search agents are all latency-bound decoding. Speculative decoding is one of the few speed-ups that changes neither the model nor its output distribution, so it is safe for evaluation and for on-policy RL. Its acceptance rate is also a useful lens on when a small model “agrees” with a large one.
Key idea
Section titled “Key idea”Let be the target distribution and the draft’s (Leviathan et al.’s notation; Chen et al. swap the letters). For a drafted token :
This yields exactly . The per-token acceptance probability is (Theorem 3.5), and . If acceptances are i.i.d., the tokens per target pass form a capped geometric variable:
where is the draft’s run time relative to the target’s (Theorem 3.8). The extra arithmetic is (Theorem 3.11).
Key results
Section titled “Key results”- Table 1 (theory, c = 0): α = 0.8, γ = 5 gives 3.69× speed for 1.63× operations; α = 0.9, γ = 10 gives 6.86× for 1.60×.
- Table 2 (T5-XXL 11B target, measured): with T5-small (77M) as draft, EnDe translation reaches 3.4× (α = 0.75, temperature 0) and 2.6× (α = 0.62, temperature 1); CNN/DM summarisation 3.1× and 2.3×. T5-large reaches α = 0.82 but only 1.7×.
- §4.2: drafts a couple of orders of magnitude smaller than the target give α between 0.5 and 0.9; sharper distributions give higher α.
- Chen et al. (2302.01318): Chinchilla 70B (14.1 ms/token) with a 4B, 8-layer draft (1.8 ms/token) runs 1.92× faster on XSum with nucleus sampling, 2.01× greedy, and 2.46× on HumanEval, while benchmark scores stay essentially the same (XSum ROUGE-2 0.112 vs 0.114 with nucleus sampling). The XSum speed-up peaks at K = 3 draft tokens.
Limitations & open questions
Section titled “Limitations & open questions”- The analysis assumes i.i.d. acceptances and spare compute for γ + 1 parallel target evaluations. At large batch sizes the target pass is no longer memory-bound and the gain shrinks.
- You need a draft model with the same tokenizer that is both cheap and well aligned. When the target changes, as in RL, the draft goes stale.
- Speed-ups are measured on translation, summarisation and code. Retrieval-grounded generation, where answers copy from passages, may behave differently.
- Open: can the retrieved passages themselves serve as a draft for copy-heavy RAG answers, and how should γ adapt within one generation?
Connections
Section titled “Connections”- Alongside: GQA and PagedAttention attack the same memory-bound decoding step from the cache side.
- After: Multi-token prediction trains a model to predict several future tokens, which could serve as a built-in draft.
- Drafts: a natural draft is a distilled copy of the target.
- RL: exact sampling matters for on-policy methods such as PPO; latency of long traces is the theme of test-time compute.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
Over a 3-token vocabulary (a, b, c), the target model gives p = (0.5, 0.3, 0.2) and the draft gives q = (0.2, 0.6, 0.2). Compute the acceptance probability β, the chance of keeping a drafted b, the residual distribution used after a rejection, and show that the final output distribution is exactly p.
What a strong answer covers
- β = Σ min(p, q) = 0.2 + 0.3 + 0.2 = 0.7, so 30% of draft tokens are rejected on average. Equivalently β = 1 − D_LK(p, q), with D_LK the total-variation distance.
- Drafted a: q(a) = 0.2 ≤ p(a) = 0.5, always kept. Drafted c: q = p, always kept. Drafted b: q(b) = 0.6 > p(b) = 0.3, kept with probability p/q = 0.5.
- Residual: norm(max(0, p − q)) = norm(0.3, 0, 0), a point mass on a. A rejection always outputs a.
- P(a) = 0.2 × 1 + P(reject) × 1 = 0.2 + 0.6 × 0.5 = 0.5. P(b) = 0.6 × 0.5 = 0.3. P(c) = 0.2. This is p exactly.
- Intuition: the draft over-proposes b, so its excess is trimmed; a is under-proposed, so the rejected mass is given back to a.
- Derive / compute
With acceptance rate α = 0.8, draft length γ = 5 and draft cost c = 0.05 (draft run time relative to one target run), compute the expected tokens per target pass, the walltime speed-up from Theorem 3.8 and the increase in arithmetic operations from Theorem 3.11 (take ĉ = 0.05). Is γ = 5 the best choice here?
What a strong answer covers
- E[tokens] = (1 − α^(γ+1)) / (1 − α) = (1 − 0.8⁶) / 0.2 = (1 − 0.262) / 0.2 ≈ 3.69.
- Speed-up = 3.69 / (γc + 1) = 3.69 / 1.25 ≈ 2.95×. Table 1 gives 3.69× for c = 0 at these settings.
- Operations = (1 − α)(γĉ + γ + 1) / (1 − α^(γ+1)) = 0.2 × 6.25 / 0.738 ≈ 1.69×. You trade about 70% more FLOPs for about 3× lower latency.
- Scanning γ: 1 → 1.71×, 3 → 2.57×, 5 → 2.95×, 8 → 3.09×, 10 → 3.05×. The optimum is near γ = 8, but the curve is flat between 6 and 10, so γ = 5 gives up only about 5%.
- Corollary 3.9 check: since α > c, the gain is at least (1 + α)/(1 + c) = 1.71×, which γ = 1 achieves.
- Mechanism
Why can the large model score γ + 1 positions in roughly the time it takes to generate one token, and why does the method reduce memory traffic even though it increases FLOPs? Explain in terms of what is read from HBM per decoding step.
What a strong answer covers
- Autoregressive decoding at small batch is memory-bound: each step reads all weights and the whole KV cache to produce one token, and the arithmetic units are mostly idle.
- Scoring γ + 1 positions in one pass reads the weights and cache once and does γ + 1 times the arithmetic, which fits in the idle compute. This is the same parallelism as a prefill.
- Per accepted token, weights and cache are read (1 − α)/(1 − α^(γ+1)) times as often, which the paper notes as a reduction in memory accesses.
- FLOPs rise because rejected draft positions are still scored by the target and because the draft itself runs, per Theorem 3.11.
- The analysis assumes spare compute. At large batch sizes the target pass is already compute-bound and the gain shrinks.
- What if…
In Table 2 (T5-XXL target), T5-large as the draft has the highest acceptance rate (α = 0.82 on EnDe at temperature 0) yet the lowest speed-up (1.7×), while T5-small gives α = 0.75 and 3.4×. Explain this with the walltime formula, and explain why every draft does worse at temperature 1.
What a strong answer covers
- Speed-up = E[tokens] / (γc + 1). A larger draft raises α but also raises c; with γ = 7, every extra 0.01 of c costs 7% in the denominator.
- T5-small (77M) is about 140× smaller than the 11B target, so c is near 0 and almost all of E[tokens] turns into speed. T5-large is much closer to the target in cost, so its higher α is eaten by γc.
- At temperature 1, α drops (0.75 → 0.62 for T5-small) because two full distributions overlap less than their argmaxes agree. The paper notes that sharper distributions give higher α.
- Chen et al. see the same trade-off in γ: for Chinchilla 70B on XSum the speed-up plateaus and the best lookahead is K = 3, with variance rising as K grows.
- Design
You want to speed up rollout generation for on-policy RL of a 7B search agent (GRPO, temperature 1). Argue whether speculative sampling is appropriate, what draft model you would use, and which effects could erase the gain. State what you would measure.
What a strong answer covers
- Correctness: the rejection rule makes samples follow the target policy exactly, so rollouts stay on-policy and log-probs used in the policy-gradient update are valid. Greedy-only tricks would not be.
- Draft choice: a much smaller model with the same tokenizer, ideally distilled from the current policy. The policy changes every update, so a fixed draft drifts and α can fall over training.
- Temperature 1 lowers α compared with greedy decoding (Table 2), and RL rollouts are usually generated in large batches where the target pass is less memory-bound, which shrinks the gain.
- Tool calls and retrieved passages are inserted by the environment, not generated, so they need no drafting but still break the speculation chain at each tool boundary.
- Measure α per token type, rollouts per second at the real batch size, and exact agreement of sampled-token log-probs with standard decoding on a fixed seed sample.
- Critique
The expected-tokens formula assumes acceptance events are i.i.d. with mean α. Critique this assumption for a RAG reader that often copies spans from retrieved passages, and design an experiment that would show whether the formula over- or under-predicts the real speed-up.
What a strong answer covers
- Acceptances are correlated: inside a copied span both models agree on many tokens in a row, and at the start of new reasoning they disagree. Bursty acceptance changes the distribution of accepted run lengths.
- With the same mean α, clustered successes give more runs that hit the γ + 1 cap and more runs that stop at once, so the mean tokens per pass can differ from the i.i.d. prediction. The sign depends on γ and the burst structure.
- The paper itself compares predicted and measured speed-ups (Table 4, appendix), which is the right check but on translation and summarisation, not retrieval-grounded generation.
- Experiment: log per-position accept/reject decisions on RAG answers, compare the empirical tokens-per-pass histogram with a capped geometric of the same α, and test an adaptive γ that drafts longer inside detected copy spans.