Speculative decoding

A big model spends one expensive forward pass to produce a single token — and that pass costs nearly the same whether it checks one token or five. So let a small, fast model guess several tokens ahead, then have the big model verify the whole guess in one pass. Keep the run of correct guesses, fix the first wrong one. The output is identical to the big model's; you just got there faster.

1 The pass that's mostly wasted

From Chapter 13: generating a token is memory-bound. The expensive part of a forward pass is hauling the model's billions of weights out of memory, and that cost is paid whether the pass produces one token or processes a hundred in parallel. Standard decoding produces exactly one token per pass — which means almost all of that hauled-in compute capacity sits idle.

draft model small · fast proposes a guess of k tokens t1t2t3t4t5 target model big · verifies once accept the matching prefix, re-sample at the first mismatch 3 tokens in one verification pass — same output distribution
Speculative decoding uses a small fast model to guess several tokens ahead, then a single pass of the big model to verify them. Every token the big model agrees with is free; at the first disagreement it re-samples. The trick is provably lossless — the output matches plain sampling from the big model.

So here's the opening: a single forward pass can score many token positions at once for nearly free. If you only had some candidate tokens to score, you could verify a whole batch of them in the time it normally takes to make one. The catch is producing the candidates cheaply — which is where a second, smaller model comes in.

One big pass can check many tokens for the price of one. The bottleneck isn't doing the arithmetic for several tokens — it's loading the weights. Speculative decoding exists to put that already-paid-for capacity to use.

2 Draft and verify

The setup is two models: a large target (the one whose output you actually want) and a small, cheap draft model. Each round goes:

The draft model quickly generates a guess of the next K tokens, running itself K times — cheap, because it's small. The target model then takes that whole guess and verifies all K positions in a single forward pass. You accept the longest prefix of the guess that the target agrees with, and at the first disagreement you throw out the rest and substitute the target's own token. Every round costs one target pass but emits anywhere from one token (draft was wrong immediately) up to K+1 (draft was right the whole way, plus a free bonus token).

One target pass, several tokens out. Standard decoding is one pass per token. Speculative decoding is one pass per round, and a round emits as many tokens as the draft got right — plus one. When the draft is good, that's a multiplier on throughput.

3 Lossless, not approximate

The surprising part: this is not a quality trade-off. The acceptance rule is designed so that the tokens you emit follow exactly the target model's own distribution. For greedy decoding the check is simple — accept the draft's token only if it equals the token the target would have picked — so the output is bit-for-bit identical to running the target alone. For sampling, a slightly cleverer probabilistic acceptance test (speculative sampling) gives the same guarantee in expectation.

That's what makes the technique a free lunch in a field that rarely offers one. You aren't approximating the big model with the small one; the small one only ever proposes, and the big one has the final say on every token. Wrong guesses cost a little wasted draft compute, never a wrong answer.

The draft proposes; the target decides. Because the target verifies every token, a bad draft can only make you slower, never wrong. The output distribution is provably the target's. Speedup with no quality cost is the whole reason this is everywhere now.

4 Acceptance rate

The speedup lives entirely in the acceptance rate — how often the draft's guess matches the target. The closer the draft mimics the target, and the more predictable the text, the longer the accepted runs. Boilerplate, code, and formulaic prose get devoured many tokens per round; genuinely novel or high-entropy text barely beats one.

This is why drafts are usually a smaller model from the same family, or even a few extra prediction heads bolted onto the target itself (Medusa, EAGLE) so the draft and target can't help but agree. A draft that's fast but rarely right is worse than useless — you pay its cost and accept almost nothing.

5 Where the speedup hides

Net speedup is a tug-of-war. Drafting more tokens per round (K) raises the ceiling on tokens you can accept — but every drafted token past the first rejection is wasted draft compute, and the draft isn't free. Push K too high and you spend more time drafting tokens that get thrown away than you save. There's an optimal draft length, and it moves with the acceptance rate and the draft's relative cost.

Roughly, the speedup is the average tokens accepted per round divided by the overhead of running the draft K times. A draft that's, say, ten times cheaper than the target, getting three or four tokens accepted per round, lands you a 2–3× throughput win in practice — which is why nearly every serious inference stack now ships it.

6 Reading the playground

Two real models run here — a well-trained target and a deliberately weaker draft, both character-level, both trained live in your browser. The draft-and-verify loop is genuine speculative sampling: the draft proposes, the target's acceptance test decides, and the emitted tokens come out distributed exactly as the target's own.

Step through rounds: the draft's guess in yellow, accepted tokens in green, the first rejected one struck out, and the target's correction in blue.

Live stats — acceptance length, agreement rate, and the estimated speedup under a draft cost you control.

The speedup-versus-draft-length curve, with the optimal K marked — push the draft cost and agreement and watch the sweet spot move.

The reading is the setup. The playground is the point.

Speculative decoding real target + draft models · trained live
Draft length K: 4
Temperature: 1.00
Draft cost (× target): 0.10
Step 1 · this round draft guesses, target verifies in one pass
draft guess accepted rejected target correction / bonus
t
1tokens generated
0target passes (rounds)
avg accepted / round
draft agreement
est. speedup
Step 2 · where the speedup hides speedup vs draft length, given agreement & draft cost
Draft agreement q: (measured: )

Speedup vs draft length K

Longer drafts accept more — until wasted draft compute on rejected tokens overtakes the gain. The peak is the optimal K.

The trade, in one line

tokens/round = 1 + Σ qⁱ
cost/round = 1 + K · r
speedup = tokens / cost

q = per-token agreement, r = draft cost relative to one target pass. The target pass is the "1"; the draft adds K·r.