Speculative Decoding
Speculative decoding is an inference-time acceleration technique for autoregressive language models in which a small, cheap draft model proposes a sequence of candidate tokens that a larger target model then verifies in a single parallelized forward pass, accepting or rejecting each token according to a rejection-sampling scheme that preserves the target model's exact output distribution. It matters because the memory-bandwidth bottleneck of autoregressive generation—not FLOPs—dominates wall-clock latency at typical batch sizes, and speculative decoding directly attacks this bottleneck by amortizing the cost of the large model over multiple tokens per step. The counterintuitive fact is that the technique produces outputs with provably identical distribution to the target model alone, so it is a lossless speedup—not an approximation.
Autoregressive decoding is bottlenecked not by arithmetic throughput but by memory bandwidth: at each step the entire model must be loaded from HBM to generate a single token, leaving accelerators severely underutilized. Speculative decoding reframes the problem: instead of asking the large model to generate, ask it only to verify a batch of candidate tokens, a task that runs in parallel across the sequence dimension and thus achieves near-peak hardware utilization. A fast draft model provides the candidates, and a mathematically rigorous acceptance criterion guarantees that any rejected token is replaced by a corrected sample so that the final distribution is exactly that of the target. The "aha moment" is that verification is strictly cheaper than generation when the draft model is sufficiently accurate, turning the serial bottleneck into a parallel one.
The most pervasive mistake practitioners make is assuming that speculative decoding trades output quality for speed—treating it as a form of approximate or distilled inference similar to running the small model directly. This confusion arises because the draft model's outputs are visibly present in the pipeline and the technique superficially resembles model distillation or cascaded generation. The correct mental model is that the acceptance–rejection step is a statistical correction: whenever the draft model's token probability is lower than the target's, the target model's distribution is restored exactly via a modified rejection-sampling formula (see Eq. [3]), and when candidates are rejected the algorithm falls back to sampling from a corrected distribution derived from the target. The output is identically distributed to running the target model alone—the draft model's quality affects only throughput, not correctness.
How It Works
Setup and Notation
Let denote the target model's conditional distribution over vocabulary at position given prefix , and let denote the corresponding draft model distribution. At each speculative step the draft model autoregressively generates candidate tokens , after which the target model performs a single forward pass over the extended sequence to obtain all conditional distributions simultaneously.
Acceptance Probability
For each candidate token drawn from the draft distribution , define the acceptance probability:
Explanation: Each draft token is accepted with probability equal to the ratio of target to draft probability, clamped to 1, so tokens the target model finds at least as likely as the draft are always accepted. Here ; when assigns higher probability than to a token, and rejection can occur. A Bernoulli trial with probability decides acceptance. If token is accepted the algorithm proceeds to token ; otherwise a correction sample is drawn.
Corrected Distribution on Rejection
When candidate is rejected, the algorithm samples a bonus token from the residual distribution:
Explanation: The corrected distribution redistributes probability mass to tokens where the target exceeds the draft, ensuring the marginal distribution over accepted-or-corrected tokens is exactly . The operator normalizes the non-negative residual vector to sum to 1. This is the key identity: combining the acceptance step (Eq. [1]) with the correction step (Eq. [2]) yields outputs with marginal distribution regardless of .
Distribution-Preservation Theorem
Theorem (Leviathan et al., 2023). For any draft distribution and any draft token drawn from , the token emitted by the accept/correct procedure has distribution . Proof sketch. Let be arbitrary. The probability of emitting is:
Explanation: The first term accounts for accepting the draft token ; the second accounts for rejecting whatever draft token was drawn and then sampling from the corrected distribution. Substituting Eq. [1] for and Eq. [2] for and simplifying via the identity (both equal ) yields for all .
Expected Tokens per Step
The key throughput quantity is the expected number of tokens produced per target-model call. Let denote the mean acceptance rate. Assuming i.i.d. acceptance across positions (an approximation; see Stern et al. 2018 for tighter bounds):
Explanation: This geometric-series formula counts the expected number of tokens accepted before the first rejection plus the mandatory bonus token, showing that even moderate acceptance rates yield significant multi-token gains. When (draft nearly matches target), ; when it degrades to 1, i.e., standard decoding. In practice – for well-matched draft/target pairs, giving speedups of 2–4×.
Yaniv Leviathan is a research scientist at Google, working primarily on efficient inference for large language models. He is the lead author of the landmark 2022 paper "Fast Inference from Transformers via Speculative Decoding" (published at ICML 2023), which provided the first rigorous proof that the accept/correct scheme preserves the target distribution exactly, transforming a heuristic idea into a mathematically grounded algorithm. Surprisingly, a near-simultaneous and independently derived equivalent result appeared from Chen et al. at DeepMind under the name "Speculative Sampling," making this one of the few cases of genuine simultaneous independent discovery in recent deep-learning research.
Intuition
Imagine a senior professor grading an exam assisted by a junior teaching assistant. The TA quickly drafts answers to multiple questions at once—they're fast but occasionally wrong. The professor then reads all the TA's answers in a single sitting, checking each one: answers that are clearly correct are accepted as-is, while answers that are wrong are crossed out and replaced with the professor's own answer. The student receives only the professor's-quality responses, yet the professor's time is spent reviewing in batch rather than writing from scratch. The draft model is the TA—cheap and fast—and the target model is the professor who validates in parallel. Crucially, even when the TA writes something subtly suboptimal, the professor's correction ensures the final answer is indistinguishable from what the professor would have written alone. The speedup depends entirely on how often the TA is right: the better the TA, the less the professor has to rewrite, and the faster the overall process.
Historical Development
Why It Matters
Prerequisites
What This Leads To
See Also
KV-Cache and Inference Optimization · Non-Autoregressive Generation · Knowledge Distillation · Beam Search and Decoding Strategies · Inference-Time Compute Scaling