Skip to main content
issue 2026-07-27Inference40 minICML 2023interactive

Fast Inference from Transformers via Speculative Decoding

This research paper explains speculative decoding: draft-and-verify sampling that accelerates autoregressive Transformers without changing architectures, training, or the output distribution.

A small draft model proposes tokens that a large target verifies in parallelOn the left, a compact draft model emits a speculative token chain. On the right, a larger target model scores those guesses together in one parallel pass. Accepted tokens stay green; the first rejection is corrected from an adjusted target distribution.DRAFT MqSMALLAUTOREGRESSIVE γd1d2d3d4PROPOSETARGET MpLARGEPARALLEL VERIFYACCEPT · REJECT · RESAMPLESame output distribution as the target alone — fewer serial target stepsDRAFT γ TOKENS → ONE PARALLEL Mp PASS → KEEP PREFIX + ONE BONUS TOKENDraft then verifyMobile layout: draft proposes, target verifies, accept or correct.SPECULATIVE DECODINGDraft Mq · propose γcheap autoregressive guessesTarget Mp · verify parallelaccept prefix · fix first rejectIdentical distribution · 2×–3× walltime on T5-XXL

Autoregressive Transformers decode one token at a time. Generating KK tokens normally means KK serial runs of the large target model. That loop is often memory-bandwidth bound: the hardware has spare arithmetic capacity, but each step still waits on the previous token.

Speculative decoding attacks that serial bottleneck. A cheaper draft model MqM_q proposes γ\gamma tokens. The large target MpM_p then scores those guesses (and one extra prefix) in parallel. Speculative sampling accepts as long a prefix as possible while guaranteeing the emitted tokens still follow the target distribution alone — no architecture change, no retrain, identical outputs.

What this paper explains

Standard decoding from MpM_p is:

  1. Condition on the prefix.
  2. Sample one token from p(xtx<t)p(x_t \mid x_{<t}).
  3. Append and repeat.

Speculative decoding inserts a draft:

  1. Sample γ\gamma tokens autoregressively from a faster MqM_q.
  2. Run MpM_p once across the γ+1\gamma+1 prefixes needed to score those guesses in parallel.
  3. Accept the longest prefix allowed by speculative sampling; on the first rejection, resample from an adjusted residual of pp; if everything is accepted, still sample one bonus token from MpM_p.

So each parallel target pass produces at least one new token and at most γ+1\gamma+1.

Speculative decoding pipelineThree stages: draft model proposes gamma tokens, target model verifies in parallel, then accept a prefix and resample after the first rejection.DRAFT Mqsample γ tokensVERIFY Mpγ+1 parallel scoresCOMMITkeep · fix · +1
Each Algorithm-1 step always returns at least one new token from the target distribution, and can return up to γ+1 when the draft aligns well.

Prior limits

Earlier speedups usually trade something away:

  • Distillation, sparsity, early-exit, and adaptive compute often change architectures or training.
  • Many adaptive methods do not preserve the exact target distribution.
  • Naïve “run a small model instead” changes answers.

Speculative decoding’s claim is stricter: accelerate existing off-the-shelf models, keep identical sampling behavior, and exploit spare concurrency when memory bandwidth — not FLOPs — is the limiter.

The mechanism

Draft. MqM_q proposes x1,,xγx_1,\ldots,x_\gamma cheaply.

Verify. MpM_p evaluates p1,,pγ+1p_1,\ldots,p_{\gamma+1} for prefixes prefix\text{prefix}, prefix+[x1]\text{prefix}+[x_1], …, prefix+[x1,,xγ]\text{prefix}+[x_1,\ldots,x_\gamma] in parallel.

Speculative sampling. For each draft token xx with draft probability q(x)q(x) and target probability p(x)p(x):

  • If q(x)p(x)q(x) \le p(x), accept.
  • If q(x)>p(x)q(x) > p(x), reject with probability 1p(x)/q(x)1 - p(x)/q(x).
  • On rejection, sample from the normalized residual norm(max(0,pq))\mathrm{norm}(\max(0, p - q)).

That rule is distribution-preserving: the accepted (or resampled) token is still distributed as pp.

Speculative sampling acceptance ruleSample from the draft distribution q. Keep the token if q is at most p. Otherwise reject with probability one minus p over q and resample from the adjusted residual of p minus q.SAMPLE x ∼ qdraft proposalIF q(x) ≤ p(x)accept alwayselse reject w.p. 1−p/qx ∼ pexact target law
Speculative sampling keeps the marginal equal to sampling from the target alone. On rejection, the next token is drawn from the normalized residual max(0, p − q).

Acceptance rate. Let β\beta be the probability a draft token is accepted for a given prefix, and α=E(β)\alpha = \mathbb{E}(\beta). Under an i.i.d. simplification, the number of tokens from one Algorithm-1 step is a capped geometric random variable:

E(# tokens)=1αγ+11α\mathbb{E}(\#\text{ tokens}) = \frac{1 - \alpha^{\gamma+1}}{1 - \alpha}

between 1 and γ+1\gamma+1.

Interactive

How long should the draft be?

Under the paper’s i.i.d. acceptance assumption, one Algorithm-1 step produces on average (1 − α^(γ+1)) / (1 − α) tokens, between 1 and γ+1. Slide draft length γ and mean acceptance α.

With α = 0.65 and γ = 4, expect about 2.53 tokens per parallel target pass — roughly a 2.5× reduction in serial Mp steps if the draft is cheap enough (c small).

Algorithm walkthrough

  1. Sample γ\gamma draft tokens from MqM_q autoregressively.
  2. Run MpM_p in parallel on the γ+1\gamma+1 prefixes that score those drafts.
  3. Draw uniforms rir_i and accept until the first ii with ri>pi(xi)/qi(xi)r_i > p_i(x_i)/q_i(x_i).
  4. If a rejection happens at position nn, resample token n+1n+1 from the residual of pn+1p_{n+1} vs qn+1q_{n+1}.
  5. If all γ\gamma drafts pass, still sample one more token from pγ+1p_{\gamma+1}.

The opening figure is that story as a scene: small cube proposes a chain; large cube verifies; green checks keep a prefix, a red cross marks the first reject, and a star marks the corrected or bonus token.

What to notice when reading

  • Speculative execution is old hardware lore; the novelty is stochastic speculative sampling that preserves pp.
  • Walltime gains need enough spare concurrency to run γ+1\gamma+1 target evaluations without stretching each one’s latency.
  • Draft quality α\alpha and relative draft cost cc jointly set the best γ\gamma (paper Figure 3 / Theorem 3.8).
  • Even a trivial bigram draft can give α0.2\alpha \approx 0.2 and a small but real speedup on En→De.

Results and evidence

Implemented against T5X for T5-XXL (11B) on a single TPU-v4, batch size 1. Drafts are existing T5 checkpoints (small / base / large). Reported walltime speedups with identical outputs:

TaskDraft MqM_qTempγ\gammaα\alphaSpeed
En→DeT5-small (77M)070.753.4×
En→DeT5-small170.622.6×
CNN/DMT5-small050.653.1×
CNN/DMT5-small150.532.3×

Larger drafts raise α\alpha but also raise cc, so walltime can get worse even when guesses are better (T5-large rows). Argmax (temp=0) accepts more often than temp=1.

Limitations

  • Needs spare parallel capacity; if γ+1\gamma+1 concurrent MpM_p passes inflate latency, the win shrinks.
  • Rejected drafts waste work; total FLOPs can rise even when walltime falls.
  • Optimal fixed γ\gamma depends on α\alpha and cc; an oracle-varying γ\gamma could do better (left for future work in the paper).
  • Gains track how well MqM_q mimics MpM_p on the task — hard domains with low α\alpha help less.

How to read the paper

  1. Abstract + §1 — serial decode vs speculative concurrency.
  2. §2 — speculative sampling rule and Algorithm 1.
  3. §3 — α\alpha, expected tokens, walltime theorem, choosing γ\gamma.
  4. §4 — T5-XXL walltimes (Table 2) and supporting tasks.
  5. Appendix — correctness proof for speculative sampling.

Knowledge check

What does speculative decoding guarantee about outputs relative to decoding from the target alone?

In one Algorithm-1 step with draft length gamma, how many new tokens can you emit?

Why can a smaller draft (T5-small) beat a larger draft (T5-large) on walltime even when alpha is lower?

Keep reading

  1. Original paper (arXiv:2211.17192) — Algorithm 1, Eq. 1, Table 2.
  2. Related Fanout Daily: Orca continuous batching, GQA, FlashAttention, PagedAttention.
  3. Follow-on systems literature on speculative decoding in production LLM servers (same draft-verify idea; implementations differ).

Sources

  • Leviathan, Kalman, Matias, Fast Inference from Transformers via Speculative Decoding, ICML 2023 — arXiv:2211.17192