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.
The core insight
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.
How It Works
Setup and Notation
Let pθ(⋅∣x1:t) denote the target model's conditional distribution over vocabulary V at position t+1 given prefix x1:t, and let qϕ(⋅∣x1:t) denote the corresponding draft model distribution. At each speculative step the draft model autoregressively generates K candidate tokens x~t+1,…,x~t+K, after which the target model performs a single forward pass over the extended sequence x1:t,x~t+1,…,x~t+K to obtain all K+1 conditional distributions simultaneously.
Acceptance Probability
For each candidate token x~t+k drawn from the draft distribution qϕ, 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 αk∈[0,1]; when qϕ assigns higher probability than pθ to a token, αk<1 and rejection can occur. A Bernoulli trial with probability αk decides acceptance. If token k is accepted the algorithm proceeds to token k+1; otherwise a correction sample is drawn.
Corrected Distribution on Rejection
When candidate x~t+k 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 pθ. The norm(⋅) 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 pθ regardless of qϕ.
Distribution-Preservation Theorem
Theorem (Leviathan et al., 2023). For any draft distribution qϕ and any draft token x~ drawn from qϕ, the token emitted by the accept/correct procedure has distribution pθ. Proof sketch. Let x∈V be arbitrary. The probability of emitting x is:
Explanation: The first term accounts for accepting the draft token x; the second accounts for rejecting whatever draft token was drawn and then sampling x from the corrected distribution. Substituting Eq. [1] for α(x) and Eq. [2] for pcorr(x) and simplifying via the identity ∑xmax(0,p−q)=∑xmax(0,q−p) (both equal 21∥p−q∥1) yields Pr[emitx]=pθ(x) for all x. □
Expected Tokens per Step
The key throughput quantity is the expected number of tokens produced per target-model call. Let β=E[αk] denote the mean acceptance rate. Assuming i.i.d. acceptance across positions (an approximation; see Stern et al. 2018 for tighter bounds):
4
E[tokens per step]=1−β1−βK+1
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 β→1 (draft nearly matches target), E[tokens per step]→K+1; when β→0 it degrades to 1, i.e., standard decoding. In practice β≈0.7–0.85 for well-matched draft/target pairs, giving speedups of 2–4×.
researcher · Yaniv Leviathan | b. ~1985 | Formal proof of distribution-preserving speculative decoding
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.
Figure
Speculative Decoding Data Flow
Intuition
The Mental Model
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
Origins · 1 minhow this was discovered
History
2018
Blockwise parallel decoding (Stern, Shazeer, Uszkoreit) introduces the idea of predicting multiple future tokens in parallel using auxiliary heads, providing early evidence that speculative token proposals could accelerate autoregressive generation.
2020
Non-autoregressive and semi-autoregressive generation research (Gu et al.; Ghazvininejad et al.) demonstrates that masked language model heads can verify proposals quickly, motivating the batch-verification paradigm.
2022
(May): Leviathan, Kalman & Matias (Google) post "Fast Inference from Transformers via Speculative Decoding" to arXiv, providing the first complete acceptance–rejection proof and empirical demonstration with T5 and LaMDA variants.
2022
(May): Chen, Borgeaud, Irving, Lespiau, Sifre, Jumper (DeepMind) independently post "Accelerating Large Language Model Decoding with Speculative Sampling," deriving the identical algorithm and proving distribution preservation with a different proof strategy.
2023
Both papers appear at ICML 2023, establishing speculative decoding as a peer-reviewed, theoretically sound technique; Google integrates it into production serving infrastructure.
2023
Cai et al. introduce Medusa, replacing an external draft model with multiple auxiliary decoding heads on the target model itself, enabling draft generation without a separate model and reducing memory overhead.
2023
Fu et al. and others introduce draft-then-verify with retrieval-augmented speculation (REST), using retrieved document n-grams as draft proposals rather than a learned model.
2024
SpecTr (Sun et al.) and Optimal Transport-based methods provide tighter theoretical analysis of the acceptance-rate–speedup trade-off and introduce multi-candidate (tree-structured) speculative decoding for further gains.
2024
Eagle and EAGLE-2 (Li et al.) propose training the draft model with a feature-level objective aligned to the target's hidden states, achieving acceptance rates exceeding 0.85 on coding benchmarks and speedups of 3–4× over vanilla decoding.
Why It Matters
Real-World Impact
Google PaLM and Gemini ServingGoogle's production inference stack applies speculative decoding using a smaller model from the same family as the draft, achieving reported 2–3× latency reduction at interactive serving batch sizes; this directly enables sub-second response times for Gemini-powered products.
Anthropic Claude APISpeculative decoding with draft models matched to Claude's tokenizer and vocabulary contributes to Claude's low time-to-first-token and high inter-token throughput, critical for streaming interfaces where perceived responsiveness dominates user experience.
Meta LLaMA Inference (llama.cpp, vLLM)The vLLM serving framework (Kwon et al., 2023) ships speculative decoding support using smaller LLaMA variants as drafters, enabling researchers to serve 70B-parameter models on commodity A100 clusters with throughput competitive with cloud APIs.
Medusa in Open-Source Serving (Together AI, Fireworks AI)Medusa heads—auxiliary linear layers trained on top of frozen target models—are deployed in several commercial serving platforms as a drop-in speculative acceleration layer requiring no separate model weights, reducing deployment complexity while retaining most of the speedup.
GitHub Copilot / Code Generation WorkloadsCode completion exhibits high draft-acceptance rates because syntax-constrained outputs are predictable by small code models; speculative decoding is particularly effective here, with acceptance rates of 0.80+ reported for fill-in-the-middle tasks.
On-Device Inference (Apple Neural Engine, Qualcomm)Memory bandwidth constraints on mobile accelerators make speculative decoding disproportionately valuable; Apple's on-device LLM stack reportedly uses small "draft" networks to keep latency acceptable for Siri-class interactions on M-series chips.
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