This session explains speculative decoding: a cheap draft proposes several tokens, the target verifies them in one pass, and rejection sampling keeps the output law equal to the target.
1. 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 q.
cheaper q+ more accurate q+ verify many tokens in one pass
Core. Exact speculative sampling keeps the target law. A worse q only lowers the accept rate.
pSD=p

Prefix: Under the pale moon
- Case 1: Reject. Draft
a cat crossed the garden, keep a cat, drop the suffix, resample slept from p′. 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.
2. Why it is fast
Low-batch decode is memory-bound: each target pass reloads weights for one token. Speculative decoding spends idle compute — the target checks γ+1 positions in one pass.
- Acceptance rate α — mean keep-probability over positions/contexts
- Accepted length τ — expected tokens emitted per cycle (accepted drafts plus one correction or bonus)
α=Ex∼q[min(1,q(x)p(x))]=x∑min(p(x),q(x))
If accepts are i.i.d. with mean α and draft length γ:
τ=i=0∑γαi=1−α1−αγ+1
If α=1, then τ=γ+1. The i=0 term is the token the target always emits, so τ∈[1,γ+1].
Per-token latency (Sadhukhan et al.):
L=τTdraft+Tverify
Latency per token drops if (1) drafts match p more often (larger τ); (2) drafting is cheaper; (3) verification is cheaper.
3. Math
This section proves that speculative sampling outputs xout∼p, the same as the target distribution.
Let p be the target next-token distribution and q the draft distribution, same context.
Split p into overlap (accepted drafts) plus leftover (filled only after reject):
p(x)=min(p(x),q(x))+max(0,p(x)−q(x))
3.1 Acceptance
α(x) is the probability we accept the draft token, given that the draft proposed x:
α(x)=P(accept∣draft=x)
Draw u∼Unif[0,1]; keep x iff u≤α(x). For q(x)>0,
α(x)=min(1,q(x)p(x))
Then
P(x,accept)=q(x)α(x)=q(x)min(1,q(x)p(x))=min(p(x),q(x))
- q(x)>p(x): over-propose; keep fraction p/q
- q(x)≤p(x): under-propose; keep every such x
Acceptance stores exactly the overlap min(p,q).
3.2 Rejection correction
r(x) is the uncovered part of p(x): how much target mass is still missing after the accept path has taken min(p,q).
- p(x)>q(x): accept only covered q(x), so r(x)=p(x)−q(x)
- p(x)≤q(x): accept already covered all of p(x), so r(x)=0
r(x)=p(x)−min(p(x),q(x))=max(0,p(x)−q(x))
Z is the total uncovered mass (over the vocabulary):
Z=y∑r(y)
If rejected and Z>0, sample the correction from p′(x)=r(x)/Z.
Accept probability A=∑xq(x)α(x)=∑xmin(p(x),q(x)). Since ∑p=1,
P(reject)=1−A=Z
Correction path:
P(reject)p′(x)=Z⋅Zr(x)=max(0,p(x)−q(x))
Add the two paths:
PSD(x)=min(p(x),q(x))+max(0,p(x)−q(x))=p(x)
So PSD=p. If p=q then Z=0: every proposal is kept and p′ is unused.
3.3 Multiple draft tokens
Draft d1,…,dγ. After d1,…,di−1 are kept, both models share context ci=prefix+d1+⋯+di−1. Verify left to right:
qi(x)=q(x∣ci),pi(x)=p(x∣ci),αi=min(1,qi(di)pi(di))
Reject at k. Keep d1,…,dk−1. Drop dk,…,dγ (later drafts assumed dk). Sample xcorr∼pk′. Emit d1,…,dk−1,xcorr.
All γ accepted. The same pass has pγ+1(x)=p(x∣prefix+d1+⋯+dγ). Sample xbonus∼pγ+1. Emit d1,…,dγ,xbonus.
A cycle emits between 1 and γ+1 tokens. Repeating the one-step rule at each valid context gives the target sequence law:
PSD(x1:n)=i=1∏np(xi∣x1:i−1)=Ptarget(x1:n)
Speculative decoding changes how many target passes are needed, not the target output distribution.