Zack Li logoZack Li

Back to Blog

Speculative Decoding Deep Dive I: Math Foundations

Created on July 30, 2026

A cheap draft proposes several tokens, the target verifies them in one pass, and rejection sampling keeps the output probability distribution equal to the target.

Overview

Autoregressive decoding: one token per target pass. Latency scales with length.

Speculative decoding (Chen et al. 2023; Leviathan et al. 2023): draft several tokens cheaply, verify them in one target pass. Methods differ in how they build .

Core. Exact speculative sampling keeps the target probability distribution. A worse only lowers the accept rate.

Draft then parallel verify, then reject

Prefix: Under the pale moon

  • Case 1: Reject. Draft a cat crossed the garden, keep a cat, drop the suffix, resample slept from . Emit Under the pale moon a cat slept.
  • Case 2: All accept. Prefix Beside the silent lake, draft birds began to sing, bonus softly. Emit Beside the silent lake birds began to sing softly.

Why it is fast

Key: a Transformer can parallel-verify many positions.

Low-batch decode is memory-bound: each ordinary pass reloads weights for one token. Verifying draft tokens is still one target forward — load weights once, then spend idle GPU compute on positions at once. In that regime, is often close to a normal decode step.

  • Acceptance rate — mean keep-probability over positions/contexts
  • Accepted length — expected tokens emitted per cycle (accepted drafts plus one correction or bonus)

If accepts are i.i.d. with mean and draft length :

If , then . The term is the token the target always emits, so .

Per-token latency (Sadhukhan et al.):

Latency per token drops if (1) drafts match more often (larger ); (2) drafting is cheaper; (3) verification is cheaper.

The autoregressive ceiling

If the drafter is itself autoregressive, is the bottleneck. A KV cache avoids recompute, but not the serial one-token passes:

Accepted draft tokens (the formula above already adds the bonus/correction) saturate:

Cost grows linearly in ; extra draft tokens buy almost nothing. So an AR drafter must stay shallow, which caps . Parallel drafting (DFlash) makes independent of .

Why output follows target distribution

This section proves that speculative sampling outputs , the same as the target distribution.

Let be the target next-token distribution and the draft distribution, same context.

Split into overlap (accepted drafts) plus leftover (filled only after reject):

Acceptance

is the probability we accept the draft token, given that the draft proposed :

Draw ; keep iff . For ,

Then

  • : over-propose; keep fraction
  • : under-propose; keep every such

Acceptance stores exactly the overlap .

Rejection correction

is the uncovered part of : how much target mass is still missing after the accept path has taken .

  • : accept only covered , so
  • : accept already covered all of , so

is the total uncovered mass (over the vocabulary):

If rejected and , sample the correction from .

Accept probability is the total overlap. Since ,

Correction path:

Add the two paths:

So . If then : every proposal is kept and is unused.

Multiple draft tokens

Draft . After are kept, both models share context . Verify left to right:

Reject at . Keep . Drop (later drafts assumed ). Sample . Emit .

All accepted. The same pass has the next-token distribution after the whole draft. Sample . Emit .

A cycle emits between and tokens. Repeating the one-step rule at each valid context gives the target sequence probability distribution:

Speculative decoding changes how many target passes are needed, not the target output distribution.

References

  • Leviathan et al., 2023. Fast Inference from Transformers via Speculative Decoding. arXiv 2211.17192
  • Chen et al., 2023. Accelerating Large Language Model Decoding with Speculative Sampling. arXiv 2302.01318
  • Cai et al., 2024. Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads. arXiv 2401.10774

© Copyright 2026 Zack Li.