Paper 48~12 min readICML 2023worked math + runnable code
Paper Breakdown

Speculative decoding,
explained.

Generating text from a large model is slow for a frustrating reason: it makes one token at a time, and each token forces the whole model to be read from memory. Speculative decoding turns that waste into speed with a simple bet — let a tiny, cheap model guess a few tokens ahead, then have the big model check them all at once. When the guesses are good you get several tokens for the price of one, and the output is provably identical. Here's the trick, and the math that says how much it saves.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

Why decoding is slow

A language model generates autoregressively: each token depends on all the ones before it, so they come out strictly one at a time. And here is the painful part — producing that single token requires reading the model's entire set of weights from memory. For a large model that is tens or hundreds of gigabytes moved per token. Decoding is memory-bandwidth-bound: the GPU's arithmetic units sit mostly idle, starved while weights stream in.

That idle compute is the opportunity. Checking whether a proposed token is correct costs one forward pass — and a forward pass can check many token positions at once for barely more than the cost of one, because it is bandwidth-bound, not compute-bound. So if something could guess the next few tokens, the big model could verify the whole batch of guesses in a single pass, spending its wasted compute to produce several tokens at once.

The one-sentence version

Decoding wastes compute waiting on memory; speculative decoding fills that idle compute by verifying several cheaply-guessed tokens in the one pass it takes to make one.

02

Draft, then verify

The scheme uses two models: a small fast draft model and the large target model whose output you actually want. Each round:

One round of speculative decoding
Draft kThe small model autoregressively proposes k tokens (cheap).
Verify onceThe big model scores all k positions in one parallel pass.
Accept prefixKeep the longest leading run the target agrees with; reject at the first disagreement.
+1 tokenThe target contributes one more token (a correction, or a bonus if all k passed).

If the draft is good, most of its k guesses survive and you advance many tokens per expensive target pass. If it is bad, you reject early — but you have still produced at least one correct token (the target's own), so you never do worse than ordinary decoding, only better.

03

Why the output is identical

The subtle, beautiful part is that this is lossless. You might expect a shortcut to change what the model says — but speculative decoding is arranged so the tokens it emits are distributed exactly as if you had sampled from the target model normally. It uses a modified rejection sampling rule: accept the draft's token with probability min(1, ptarget/pdraft), and on rejection sample the correction from an adjusted distribution. The algebra works out so the combined process's distribution equals the target's, token for token.

That guarantee is what makes it deployable. It is not an approximation with a quality knob — it produces the same samples as the model it accelerates, so a serving system can switch it on transparently and users see identical outputs, just faster. Speed for free, in the truest sense the field offers.

04

The expected-tokens math

How much faster? Model each drafted token as accepted independently with probability α, the acceptance rate (how often the little model agrees with the big one). Accept a leading run until the first rejection, then add the target's one guaranteed token. The expected number of tokens produced per target pass is a geometric sum:

𝔼[tokens per target pass] = 1 + α + α² + … + αk = (1 − αk+1) / (1 − α)

Standard decoding produces exactly 1 token per target pass, so this ratio is the speedup in target passes. With α = 0.8 and k = 4 it is ~3.4 tokens per pass. But drafting isn't free: each of the k draft tokens costs the draft model's (smaller) compute, wasted whenever the token is rejected. Dividing the expected tokens by that draft overhead gives a real-time speedup that peaks at a modest k and then falls — guessing too far ahead spends draft compute on tokens that rarely survive. The runnable model below computes both the token count and that peak.

RUN IT YOURSELF

How many tokens per pass, and the best k

The speedup is a geometric sum you can hold in your hand. This computes the expected tokens per target pass, (1 − αᵏ⁺¹)/(1 − α), and checks its limits: a useless draft (α=0) yields exactly 1 token per pass, a perfect draft (α=1) yields k+1. Then it factors in draft cost and sweeps the draft length k — and you'll see the speedup rise, peak around k=2–4, and fall as over-long drafts waste compute on tokens that get rejected. Change the acceptance rate α or the draft cost and watch the sweet spot move.

CPython · WebAssembly
05

Choosing the draft

The whole method lives or dies on the acceptance rate — how often the draft agrees with the target. Two levers set it, and both are design decisions:

LeverEffect
Draft model qualityA stronger, better-aligned draft raises α — but a slower draft eats into the savings. The draft must be much cheaper than the target, yet close enough to agree often (often a smaller model from the same family).
Draft length kLonger drafts win more per pass when accepted, but acceptance decays the further ahead you guess, and rejected tokens waste draft compute. There is a peak — usually a handful of tokens.
DomainPredictable text (code, boilerplate, formatting) gets very high α and huge speedups; open-ended creative text is harder to guess.

Because acceptance varies with context, good implementations adapt: draft more tokens when recent acceptance was high, fewer when it drops. The payoff is real — production systems routinely report 2–3× faster generation, more on predictable content, at exactly zero cost to output quality.

06

What came after

Speculative decoding kicked off a wave of "guess-and-verify" inference methods, most aimed at removing the need for a separate draft model. Medusa bolts extra prediction heads onto the target model itself so it can propose its own future tokens. EAGLE drafts in the model's feature space for higher acceptance. Lookahead decoding generates and verifies n-grams without any draft model at all. All share the same skeleton: propose cheaply, verify in parallel, keep what's correct.

The lasting idea is a reframing of what a forward pass is for. A big model's pass has spare compute; instead of spending it on one token, spend it checking many. That principle — verification is parallel and cheap, generation is serial and expensive, so trade the former for the latter — now underlies a whole branch of efficient-inference research.

Worth knowing

The same verify-in-parallel trick appears elsewhere: it's why prefilling a long prompt is fast (all positions at once) but generating is slow (one at a time). Speculative decoding basically makes generation borrow prefill's parallelism.

Frequently asked

Quick answers

Does it change the output?

No — modified rejection sampling makes the emitted tokens distributed exactly as the target model's. The speedup is lossless, so it can be enabled transparently.

Where does the speedup come from?

Decoding is memory-bound, so verifying k proposed tokens in one pass costs almost the same as making one. You turn idle compute into extra tokens per pass.

What's the acceptance rate?

How often the small draft model agrees with the big target. Higher α means more of the draft survives per pass; it's the single number that governs the speedup.

How long should the draft be?

There's an optimum — usually a few tokens. Longer drafts win more when accepted but waste draft compute on rejections, so the real-time speedup peaks and then falls.

Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns