- Key idea
- Rejection sampling, the speculative sampling acceptance rule, and acceptance rate as total variation
- Real world
- A junior editor drafts headlines quickly; the senior editor approves or rewrites each. If the junior's style is close to the senior's, most drafts pass and the desk moves fast. The paper's headlines still read exactly as if the senior had written them all.
- In an LLM
- A small draft model proposes the next 4 tokens. The large model checks all 4 in a single forward pass and accepts a prefix of them. Output follows the large model's distribution exactly, but it needs far fewer slow forward passes.
Rejection sampling
Suppose you can evaluate a target distribution but can't easily sample from it, and you can sample from a proposal . Rejection sampling:
- Draw from .
- Accept it with probability proportional to , scaled so the largest ratio gives probability 1.
- If rejected, start again.
Accepted samples follow exactly. The price is wasted proposals: the further is from , the more you throw away. Unlike importance sampling, which keeps every sample with a weight, rejection sampling produces honest, unweighted samples.
To pick a uniformly random point inside a circle, pick a random point in the surrounding square (easy) and throw it away if it lands outside the circle. About 79% of points are kept, the circle's share of the square. The kept points are perfectly uniform over the circle.
"Rejection sampling" in LLM papers usually means something looser: generate many answers, keep the ones a verifier or reward model accepts, and fine-tune on them. If you keep everything that passes a correct/incorrect check, the kept set is an exact sample from the model's distribution conditioned on being correct: . That's conditional probability by sampling, and the basis of STaR and expert iteration (distillation).
Speculative decoding
Generating text with a large model is slow mostly because each token needs a full forward pass, one after another. But checking several tokens at once costs about the same as generating one. Speculative decoding exploits this:
- A small draft model quickly writes tokens.
- The large target model computes its probabilities for all positions in one pass.
- Go through the drafted tokens in order. Keep token with probability .
- At the first rejection, sample a replacement from the residual distribution, proportional to , and discard the rest of the draft.
The rule is designed so that the token that comes out at each position, accepted or replaced, is distributed exactly as . Not approximately: exactly. A bad draft model costs speed, never quality.
The junior drafts "Mayor unveils budget plan". The senior would have written "Mayor" with 60% chance; the junior wrote it with 50%. Since the senior likes it at least as much, it's kept. The junior's "unveils" has 40% from the junior but only 10% from the senior: kept a quarter of the time. When it's rejected, the senior picks a replacement only from words they like more than the junior does.
The target gives "the" 0.42 and "a" 0.22; an overeager draft gives "the" 0.18 and "a" 0.40. A drafted "the" is always kept (the target likes it more). A drafted "a" is kept with probability . When it's rejected, the replacement is drawn mostly from "the", which the draft under-proposes. The bookkeeping works out to exactly 42% "the" and 22% "a" in the output.
How fast?
The chance that a drafted token is accepted is
where TV is the total variation distance (divergences). The better the draft matches the target, the higher , and the more tokens each expensive pass produces: about with drafted tokens. Real systems see acceptance rates of 0.6–0.9 and speedups of 2–3×.
Try it
Where this shows up
- Speculative decoding in inference engines (vLLM, SGLang, TensorRT-LLM), and variants like EAGLE and Medusa that predict drafts from the target's own features.
- Rejection-sampling fine-tuning, STaR, and best-of-n data filtering: distillation, latent variables.
- DAPO's dynamic sampling rejects prompt groups where every answer got the same reward: GRPO fixes.
- The same ratio is an importance weight; here it becomes an acceptance probability instead of a multiplier.
Rejection sampling
If for all , draw and , and accept when . Then
It also works when is known only up to a constant, which is why it suits "the model's distribution, conditioned on passing a verifier".
Speculative sampling
For one position, with draft and target :
Proof that the output is distributed as : the probability of outputting is
using . With drafted tokens and i.i.d. acceptance, the expected number of tokens per target pass is .
Papers
- Fast Inference from Transformers via Speculative Decoding (Leviathan et al., 2022)
- Accelerating Large Language Model Decoding with Speculative Sampling (Chen et al., 2023)
- EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty (Li et al., 2024)
- STaR: Bootstrapping Reasoning With Reasoning (Zelikman et al., 2022): rejection sampling on correctness, then fine-tuning
- DAPO (Yu et al., 2025): dynamic sampling