TL;DR
Large language models write one token per pass through the whole network, and that pass is limited by how fast weights can be read from memory. Chen and colleagues let a small, fast draft model guess a short run of tokens, then ask the large target model to score all the guesses in one parallel call. A modified rejection rule keeps the guesses that the target agrees with and corrects the first one it does not, so the output has the target's distribution. On the 70 billion parameter Chinchilla model they report a 2 to 2.5 times decoding speedup with no change to the model.
Builds on: Rejection Sampling, KV Cache, Speculative Decoding · Leads to: the concurrent Leviathan et al. paper, which named the same idea
Why it mattered
Speculative sampling is one of the two papers that set out the modern form of speculative decoding. The authors say their work was undertaken concurrently and independently of Leviathan, Kalman and Matias (2022), and that the core idea is the same. The idea, a cheap draft model plus a rejection test against the expensive model, has since reached open-source inference libraries as an option. Its distinctive contribution is the distributed setting. The authors show the method on a model too large for one accelerator, where communication between chips makes each call expensive and the draft model has to be chosen with the hardware in mind.
The numbers that made it concrete are in its Table 1: Chinchilla, served on 16 TPU v4 chips at batch size 1, drops from 14.1 ms per token to 7.52 ms on XSum summarisation with nucleus sampling and to 5.73 ms per token on 100-shot HumanEval code generation, a speedup of 2.46 times on that benchmark.
History
Before 2023, decoding speedups mostly changed the model: distillation, quantisation, and smaller models. Parallel decoding was proposed in several forms, including blockwise parallel decoding by Stern and colleagues in 2018, but those methods either changed the target or biased its output, or worked only with greedy decoding.
Two groups worked on the same core idea at the same time. Leviathan, Kalman and Matias posted their paper in November 2022 (arXiv 2211.17192) under the name speculative decoding. Chen and colleagues posted theirs in February 2023 (arXiv 2302.01318) and focused on the distributed serving of very large models and on scoring with Chinchilla. The idea spread because it needed no retraining and no change to the target, so libraries could offer it as an option next to ordinary sampling.
The problem
Decoding is sequential. Token cannot be sampled until token exists, so producing tokens needs calls to the big model. In the paper's words, transformer sampling is typically memory bandwidth bound: a call to a model with billions of parameters reads nearly all of its weights from memory to produce one token for each sequence in the batch. The time per token is therefore set by how many bytes must move, not by arithmetic. For a model split over several accelerators, every layer also needs an all-reduce, which adds latency.
Two obvious fixes do not solve it here. Smaller models lower the cost but change the outputs. Techniques that shrink the key-value cache (multi-query attention) mostly raise throughput at large batch sizes, not latency at batch size 1. The paper asks for a method that keeps the target model exactly as it is and does not bias what it samples.
How it works
Here is one round on a toy case. The context is the prefix "The". The draft model is small and fast; the target model is the large one whose distribution we want. The round uses a lookahead of K = 2.
- Draft. The draft model guesses two tokens one after the other. It proposes "cat" with draft probability 0.6, then "sat" with draft probability 0.5 given "The cat". Check: each guess costs one cheap draft call.
- Score in parallel. The target model runs once on "The cat sat". That single call returns its distributions at three positions: for the first new token, for the second, and for a bonus token after the second. The first distribution gives the target probability 0.5 to "cat"; the second gives 0.4 to "sat". Check: one target call, three distributions.
- Test the first guess. Accept "cat" with probability min(1, 0.5 / 0.6) = 0.833. Suppose a uniform draw gives 0.7, which is below 0.833, so "cat" is accepted. Check: the output so far is "The cat".
- Test the second guess. Accept "sat" with probability min(1, 0.4 / 0.5) = 0.8. Suppose the draw gives 0.9. That is above 0.8, so "sat" is rejected. Check: the round stops here, and no further guesses are used.
- Correct. Replace the rejected token by a sample from the leftover target mass, the part of the target distribution the draft did not cover. The full distributions are not shown here, so assume the leftover target mass sits only on "ran"; the replacement is "ran". Output: "The cat ran", two new tokens from one target call. Check: the output is a legal sample from the target.
If all K guesses had been accepted, the bonus distribution from step 2 would give one more token, so a round yields between 1 and K+1 tokens. The method does not need the draft to be right; it only needs the rejection test to be cheap and the draft's probabilities to be known.
flowchart LR
A[Prefix] --> B[Draft model guesses K tokens]
B --> C[Target model scores all K in one call]
C --> D{Test guesses in order}
D -- accept --> E[Keep token, test next]
E --> D
D -- reject --> F[Sample correction from leftover target mass]
E -- all accepted --> G[Sample one bonus token]
The math
The paper writes for the target model and for the draft model. Both are distributions over the vocabulary after any sampling adjustment such as nucleus truncation or temperature. Write for the probability the target gives to token after the context.
Given a context and a draft token drawn from , accept with probability
If it is rejected, draw from the residual distribution
This is the rejection sampler of with the draft as the proposal. The difference is what happens on rejection. A plain rejection sampler would simply try again. Here the rejected mass is refilled from the places where the target is larger than the draft, and that refill is what makes the output exact.
Step 2 in symbols: the acceptance probability
The probability that one draft token is accepted is
In the single-token example below, . The rejection probability is , and it equals the total leftover mass , because
Step 5 in symbols: the output has the target's distribution
Theorem 1 of the paper says the output has distribution . For a value , the output equals either because the draft proposed and it was accepted, or because some draft was rejected and the correction produced :
The first term is and the second is . Their sum is , as the identity shows for any . The draft distribution therefore cancels out of the final answer, which is why the draft can be any model that exposes its probabilities.
Rounds with K draft tokens
The paper applies the test to the K draft tokens from left to right and stops at the first rejection. A round therefore returns at least one token, because a rejected first guess is replaced by a corrected one, and at most tokens, the accepted guesses plus the bonus. The paper uses K = 4 in Table 1 and notes that the best K depends on the task.
Worked examples
A toy vocabulary has three tokens A, B and C. The target gives and the draft gives .
- Acceptance probabilities : A gives , B gives , C gives .
- The draft proposes A, B or C with probabilities 0.2, 0.5 and 0.3. Probability of acceptance overall: .
- Leftover target mass , so every rejection is corrected to A.
- Probability the output is A: accepted A (0.2) plus rejected-then-corrected (0.3) gives 0.5, which equals .
- Probability the output is B: accepted B gives , and B is never a correction. Likewise C gives .
Interpretation: the single-token output has exactly the target's distribution, even though the draft put only 0.2 on A.
Suppose the draft proposes four tokens, and the test accepts the first three and rejects the fourth.
- Four draft calls, each costing about 1.8 ms on the paper's draft model: ms.
- One target call scoring all four guesses in parallel, costing about 14.1 ms, the paper's per-token time for Chinchilla. The paper reports that scoring K tokens in parallel has very similar latency to sampling one token, so we take it as 14.1 ms.
- The round outputs three accepted tokens plus one corrected token: four tokens in total.
- Time for the round: ms. Time per token: ms.
- Ratio against ordinary decoding at 14.1 ms per token: .
Interpretation: this is an idealised estimate from the paper's own per-call times, not a measurement. It shows why a high acceptance rate matters: a round that accepts more guesses spreads the one expensive call over more tokens.
Results
The paper's main results are Table 1 (speed and quality on XSum and HumanEval, batch size 1, K = 4) and Figure 1 (the effect of K on XSum). Table 1 is summarised under Why it mattered; the example below works from its HumanEval row.
Worked example on HumanEval
The paper runs 16,400 HumanEval samples with a maximum length of 512, at batch size 1, with nucleus parameter 0.95 and temperature 0.8.
- Ordinary sampling: 45.1% pass, 14.1 ms per token, speedup 1.
- Speculative sampling: 47.0% pass, 5.73 ms per token.
- Speedup as the paper reports it: , which the table gives as 2.46 times.
- Quality: the pass rates differ by 1.9 points. The paper reads the two rows as parity and says the sample distribution is the same up to numerics. A single benchmark cannot establish that, so this is their reading, not a proof from the table alone.
Interpretation: on code, the draft's guesses were accepted often enough that time per token fell by a factor of 2.46 on this benchmark, the largest speedup in Table 1.
Try it: the table's greedy XSum row gives ArS at 14.1 ms per token and SpS at a speedup of 2.01. What time per token does SpS reach? Answer: ms, close to the 7.00 ms the table lists.
Limits and common misreadings
It is tempting to think that speculative sampling trades quality for speed. In fact the rejection rule is built so the sample distribution is the target's, because the correction term refills exactly the mass the draft missed. The paper's own qualifier is "within hardware numerics": a different order of floating-point operations can flip a token, so two runs need not match token for token.
It is tempting to think a bigger K always gives more speed. In fact Figure 1 shows that, for XSum with nucleus sampling, the average time to generate 128 tokens is lowest at K = 3, and the speedup plateaus or regresses at larger K. Variance also grows with K, which matters if tail latency (P90, P99) is the goal.
It is tempting to think any small model will do as a draft. In fact the paper shows that a 7 billion model is fastest on 4 TPU v4 chips, and on 16 chips it becomes slower because communication dominates. Their 4 billion draft has a slightly smaller width than Chinchilla and only 8 layers, so it runs on the same 16 chips as the target with few communication steps. The draft also has to share the target's tokeniser, since its guesses are token ids.
Use it when the target is large, latency at batch size 1 matters, and a cheap draft with a similar tokeniser exists. Do not use it when throughput across a large batch is the goal, because the target is then no longer memory bound and the gain shrinks. Alternatives include quantisation, which changes the model, and multi-query attention, which shrinks the key-value cache and mainly helps throughput.
Recap
- Decoding a large model is one expensive, memory-bound call per token, so latency is set by memory traffic.
- A small draft model proposes K tokens, and the target scores them all in one parallel call.
- The modified rejection test accepts a guess with probability and corrects a rejection from .
- The correction makes the output exactly the target's distribution, so the target is never changed.
- On Chinchilla 70B the paper reports 2 to 2.5 times faster decoding, with the largest gain on code.
Read next: Speculative Decoding states the general method as a concept, and Fast Inference from Transformers via Speculative Decoding covers the concurrent paper that introduced the name.
Reading guide
- Abstract and Section 1 (Introduction): the problem and the three steps: draft, score, modified rejection. Needs Autoregressive Model and Transformer.
- Section 2 (Related Work): quantisation, distillation and multi-query attention, the alternatives the paper compares itself with. Needs KV Cache.
- Section 3 (Auto-regressive Sampling) and Algorithms 1 and 2: the baseline loop and the speculative loop side by side. Needs Autoregressive Model.
- Section 4.1 (Conditional Scoring): why K draft tokens cost about as much to score as one. Needs GPU Memory Hierarchy for the memory-bound reasoning.
- Section 4.2 (Modified Rejection Sampling): the acceptance rule and the residual distribution. Needs Rejection Sampling and Softmax for the probabilities.
- Section 5 (Choice of Draft Models): the draft options, and why a small model is not enough on its own in a distributed setup.
- Section 6 (Results): the speed and quality numbers, and the trade-off in K. Needs Conditional Probability for the acceptance statistics.
- Appendix, Theorem 1: the proof that the output has the target distribution, which is Step 5 in symbols above.
Check yourself
QuestionWhy is the draft model's distribution absent from the final formula for the output's probabilities?Show answer
The output probability is , and the draft enters only through the min and max terms, which sum to . The draft changes how often a token is accepted, which affects speed, but not the distribution the output follows.
QuestionA toy target is q = (0.6, 0.4) and the draft is p = (0.5, 0.5). What is the probability a draft token is accepted?Show answer
Acceptance probability is .
QuestionWith the paper's timings, 1.8 ms per draft token and 14.1 ms per target call, how long do K = 4 draft calls and one target call take, and what is the time per token if all four guesses are accepted?Show answer
Draft time is ms, plus ms for the target call, for ms in total. If all four are accepted the round also yields a bonus token, so it outputs 5 tokens, giving ms per token.
QuestionWhy does the paper argue that a 7 billion parameter draft would be a poor choice on the same 16 chips as the target?Show answer
A model that is optimal on 4 chips becomes slower on 16, because the extra inter-device communication outweighs its memory-bandwidth savings. The paper therefore trains a 4 billion model with a slightly smaller width than Chinchilla and only 8 layers, which has few communication steps and can be sampled quickly on the same hardware.
QuestionA team wants to speed up a model that serves a large batch of requests to maximise total throughput. Is speculative sampling the right first choice? Explain.Show answer
Probably not. The method targets latency at batch size 1, where the target is memory bound and the drafts pay off. At a large batch the target does more arithmetic per weight read, so the speedup shrinks. For throughput, the paper points to techniques such as multi-query attention that shrink the key-value cache.
Sources
- Chen, C., Borgeaud, S., Irving, G., Lespiau, J.-B., Sifre, L., Jumper, J. (2023). Accelerating Large Language Model Decoding with Speculative Sampling. https://arxiv.org/abs/2302.01318
- Leviathan, Y., Kalman, M., Matias, Y. (2022). Fast Inference from Transformers via Speculative Decoding. https://arxiv.org/abs/2211.17192
- Hoffmann, J. et al. (2022). Training Compute-Optimal Large Language Models (Chinchilla). https://arxiv.org/abs/2203.15556
- Rejection sampling. https://en.wikipedia.org/wiki/Rejection_sampling