# Speculative decoding: when it helps and when it doesn't Speculative decoding speeds up generation without changing the output distribution. It works by guessing several tokens cheaply and verifying them all with one pass of the big model. It is not a free lunch, and knowing when it backfires matters as much as knowing how it works. ## How it works 1. A cheap **draft** proposes k tokens (a small model, extra heads like Medusa/EAGLE, or n-gram lookup from the prompt). 2. The **target** model processes all k proposals in one forward pass, the same cost profile as a short prefill. 3. Proposals are accepted left to right using a rejection-sampling rule (Leviathan et al., 2023; Chen et al., 2023) that guarantees the output follows the target model's distribution. At the first rejection, the target supplies a corrected token. So each target pass yields between 1 and k + 1 tokens. ## Why it can be faster At small batch sizes, a decode step is memory-bandwidth-bound: the GPU spends its time reading weights, not computing. Verifying 5 tokens costs nearly the same as generating 1, because the weights are read once either way. If several are accepted, you get several tokens for about the price of one. ## The expected speedup If each draft token is accepted with probability a (assumed independent), the expected tokens per target pass with k drafts is E = (1 - a^(k+1)) / (1 - a) | a | k = 2 | k = 4 | k = 8 | |---|---|---|---| | 0.5 | 1.75 | 1.94 | 2.00 | | 0.7 | 2.19 | 2.77 | 3.20 | | 0.8 | 2.44 | 3.36 | 4.33 | | 0.9 | 2.71 | 4.10 | 6.13 | Example: a = 0.8, k = 4 gives (1 - 0.8^5) / 0.2 = (1 - 0.328) / 0.2 = 3.36. Wall-clock speedup is lower than E, because each step also pays for the draft and for a verification pass that is slightly more expensive than a normal decode. If drafting costs c (relative to one target step) per draft token, a rough estimate is speedup = E / (1 + k x c + verification overhead). ## When it helps - **Low concurrency, latency-sensitive traffic** (chat with few simultaneous users, coding assistants). - **Predictable text:** code, structured output, summaries and edits that copy from the prompt. N-gram/prompt-lookup drafting is very effective when outputs repeat input text. - **A well-matched draft:** same tokenizer, trained on similar data, or heads trained on the target (EAGLE-style), which raise a. ## When it doesn't - **High batch sizes.** When the batch already fills the GPU, decode is closer to compute-bound and extra verification tokens are no longer nearly free. Many engines see speedups shrink toward zero, or become slowdowns, as concurrency rises. - **Low acceptance:** creative writing at high temperature, or a draft that disagrees often. With a = 0.5, you never exceed 2 tokens per pass regardless of k. - **Too large k:** gains saturate (see the table) while draft and verify costs keep growing. - **Memory-tight deployments:** a draft model needs its own weights and KV cache, taking room from the batch. ## How to evaluate it 1. Measure acceptance rate on real prompts, not benchmarks. 2. Sweep k (2 to 6 is typical) and concurrency (1, 8, 32, 64). 3. Report inter-token latency and throughput at each point. Expect a crossover concurrency where speculation stops paying off. 4. Enable it only below that crossover, or use an engine that adapts automatically. ## Takeaway Speculative decoding trades spare compute for fewer sequential steps. It shines when compute is idle (small batches) and drafts are accurate; it fades when the GPU is already busy. --- *If you want to go deeper, the free Foundations course at [Inference Engineering Academy](https://www.inference-engineering.xyz/) covers these topics with browser labs. Disclosure: written by the academy team.*