Worked examples — Speculative decoding
This page is a drill. We take the parent topic and run it through every kind of situation the acceptance-sampling machinery can hit. If you have never seen the notation , , , before, read the two short reminders below first — then every example is self-contained.
The scenario matrix
Every worked example below is tagged with the cell it covers. Together they touch every cell.
| Cell | Situation | What's special | Example |
|---|---|---|---|
| A | at every position | all accepted, plus bonus token | Ex 1 |
| B | somewhere | biased coin, possible early stop | Ex 2 |
| C | exactly | boundary ; draft is "perfect" | Ex 3 |
| D | Degenerate: (target forbids token) | forced rejection, | Ex 4 |
| E | Degenerate: | overconfident-editor blow-up, capped at 1 | Ex 5 |
| F | The resample step itself | build over a full vocab | Ex 6 |
| G | Limiting and | speedup ceiling and floor | Ex 7 |
| H | Real-world word problem (latency budget) | pick , compute wall-clock speedup | Ex 8 |
| I | Exam twist: correct token but wrong ordering | acceptance ignores rank, only ratio | Ex 9 |
Ex 1 — Cell A: everything accepted, bonus token
Forecast: Guess before reading. More or fewer than ?
- Position : . Accept. Why this step? , editor is more confident, no reason to doubt the intern.
- Position : . Accept. Why this step? Again .
- Position : . Accept. Why this step? Boundary — equal confidence still gives (see Cell C).
- All accepted → sample bonus token from the target at position . Why this step? Since the target already ran a forward pass over the whole drafted block, it also produced a distribution one step past the last draft — that token is free.
Answer: output tokens from a single target forward pass.
Verify: The formula gives the expected count over random coins; the maximum it can output is the all-accept case . Here . ✓
Ex 2 — Cell B: biased coin, early stop
Forecast: Will position 's attractive ever get used?
- : . Accept "token 1".
- : . Accept "token 2".
- : . Coin flip → fails → reject. Why this step? Editor likes this token half as much as the intern claimed, so we only keep it half the time. This coin failed.
- Stop immediately. Discard the draft at even though its looked great. Why this step? Tokens are a sequence. The draft was written assuming 's "," — once that's gone, the context is different, so the probabilities are meaningless. We resample instead from .
Answer: 2 accepted + 1 resampled = 3 output tokens. Position 's is never used.
Verify: Output count on rejection at index (0-based) is . ✓
Ex 3 — Cell C: exactly (perfect draft)
Forecast: Perfect draft — do we always get ?
- Each position: for all. Why this step? Ratio is exactly 1 everywhere, so .
- Expected tokens: plug into . This is , so take the limit: it equals . Why this step? When every draft is guaranteed accepted, you always reach the bonus token.
Answer: , expected tokens .
Verify: (L'Hôpital / geometric sum six terms). ✓
Ex 4 — Cell D: , target forbids the token
Forecast: Can a token the editor calls impossible ever survive?
- Accept prob: . Always reject. Why this step? means the target would never produce this token; keeping it would break losslessness.
- Resample from . Why this step? The forbidden token has , so it gets zero resample mass too. Good — it's fully purged.
Answer: , token rejected, resample avoids it entirely.
Verify: and . ✓
Ex 5 — Cell E: (draft nearly rules token out)
Forecast: Does a tiny blow the ratio up to infinity and break things?
- Ratio: .
- Accept prob: . Always accept. Why this step? The cap is exactly here to stop the ratio from exceeding a probability. No matter how tiny is, never exceeds 1.
- Limit : , but . Stable. Why this step? Shows the algorithm is numerically safe against near-zero draft mass — the cap is load-bearing.
Answer: ; the cap makes harmless (the target simply reclaims the token).
Verify: . ✓
Ex 6 — Cell F: building the resample distribution
Forecast: Which token is most likely to replace ?
- Compute per token: ; ; .
- Apply : , , . Why this step? Only tokens the target wants more than the draft offered deserve extra mass. was over-supplied by the draft, so it drops to 0.
- Normalise: . Then . Why this step? Dividing by makes it a valid distribution summing to 1.
Answer: Resample gives with probability , and with probability .
Verify: , , normalised . ✓

Look at the figure: the blue bars are , the yellow bars are . The green bars are the leftover — only pokes above the draft, so all resample mass lands there.
Ex 7 — Cell G: the two limits of speedup
Forecast: What is the best speedup you can ever get with ?
Recall speedup , with .
- : . With : speedup . Why this step? Free draft + always-accept is the ideal ceiling, exactly .
- : . Speedup . Why this step? Nothing ever accepts, so you emit just the resampled token — same as plain decoding, no gain.
Answer: Speedup runs from 1 (worst, ) up to (best, free draft, ).
Verify: as and as ; speedups and . ✓

The curve rises fast near : the last few percent of acceptance rate buy most of the speedup.
Ex 8 — Cell H: real-world latency budget
Forecast: Bigger always better?
Effective ms/token , .
- : cost ; ; per-token ms.
- : cost ; ; per-token ms.
- : cost ; ; per-token ms. Why this step? Big pays for lots of draft tokens () that mostly get thrown away once acceptance stalls (geometric decay of ) — diminishing returns turn into losses.
Answer: wins at ms/token. Speedup vs. target-only ( ms) .
Verify: All three per-token costs and the speedup are checked below. ✓
Ex 9 — Cell I: exam twist, rank vs. ratio
Forecast: Does agreeing on the best token guarantee acceptance?
- Accept prob: . Why this step? Acceptance depends only on the ratio , never on rank. The draft was over-confident (0.9) about a token the target only mildly likes (0.4), so we keep it under half the time.
- On rejection: resample from — this token gets mass, so it's removed from the resample even though it was the top-1. Why this step? Losslessness cares about matching the full distribution, not preserving the argmax.
Answer: No — same top token does not guarantee acceptance. Here .
Verify: ✓
Recall Quick self-test
What is when ? ::: — always accept. Draft accepts all ; how many tokens out? ::: (the bonus token). Resample mass on a token with ? ::: , because . As , speedup? ::: — no gain.
Related: 5.3.2-Knowledge-distillation builds the draft; 6.1.11-Model-quantization shrinks it further; 3.2.4-Beam-search and 3.1.2-Transformer-architecture are the decoding backdrop; 6.13-Flash-attention speeds the verify pass; 6.2.1-Distributed-training scales the target.