Skip to content
Inference Academy

Speculative decoding explained: faster LLM output with the same answers

How a small draft model (or extra heads) guesses several tokens and the big model checks them in one step, why the output distribution doesn't change (with a worked example of the acceptance test), how to estimate the speed-up from the acceptance rate and drafter cost, why the gain shrinks as batch size grows, how to turn it on in vLLM, SGLang and llama.cpp, and how to measure it. Covers draft models, EAGLE, Medusa, multi-token prediction and n-gram lookup.

Key takeaways

  • A cheap drafter guesses several tokens and the big model checks them all in one forward pass.
  • The acceptance test keeps the output distribution exactly the same as normal decoding.
  • The speed-up depends mostly on the acceptance rate: at 50 percent it tops out around 1.6 times; at 90 percent it can exceed 3 times.
  • Predictable text such as code, structured output and quoting speculates well; high-temperature creative text doesn't.
  • The gain is largest at low concurrency and shrinks as batch size grows, so measure at your real load.

By

7 min read

Share
On this page

Decode is slow because each token requires reading the entire model from memory, and the GPU's compute mostly sits idle while it does (prefill vs decode). Speculative decoding puts that idle compute to work: guess several tokens cheaply, then check all the guesses at once with the big model.

Done right, it gives exactly the same output distribution as normal decoding, just faster. This guide explains how it works, why it's exact, how to estimate the speed-up, why it fades at high load, and how to turn it on and measure it.

#The core trick

Checking kk tokens costs the big model about the same as generating one. That's because verifying a sequence of guessed tokens is a small prefill: the model processes all kk positions in one forward pass, reading its weights once. At batch 1, reading the weights is almost the whole cost, so a few extra positions are nearly free.

So the loop is:

  1. A cheap drafter proposes kk next tokens, say 4.
  2. The big target model runs one forward pass over those 4 positions and computes what it would have produced at each.
  3. Accept the guesses from left to right as long as they match (or pass a probability test); at the first rejection, use the target's own token instead.
  4. Repeat from the new position.
Speculative decoding: guess cheap, verify in bulk
Animated

Draft model proposes (small, fast)

The quick brown fox

Output so far

Purple = token supplied by the big model (correction or bonus).

Tokens produced

0

Big-model passes

0

Speedup so far

–

Round 1 · Draft

A tiny, fast draft model guesses the next 4 tokens. Cheap, because the draft model is small.

The result is exactly what the big model would have produced alone. Only speed changes, and only when the draft model guesses well.

If all 4 guesses are accepted, you get 5 tokens (4 accepted plus the target's next one) for the cost of one big-model step plus 4 cheap drafter steps. If the first guess is rejected, you still get 1 token: the target's correction. You never do worse than one token per target step.

#Why the output doesn't change

With greedy decoding, it's obvious: a guess is accepted only if it's exactly the token the target would have picked.

With sampling, the acceptance test is probabilistic. A drafted token xx is accepted with probability min⁡(1,p(x)q(x))\min\left(1, \frac{p(x)}{q(x)}\right), where pp is the target's probability and qq the drafter's. On rejection, the replacement is sampled from the leftover distribution max⁡(0,p−q)\max(0, p - q), renormalised.

#A worked example

Suppose that at some position the drafter proposes the word "blue" with probability q=0.6q = 0.6, but the target gives it only p=0.3p = 0.3.

  • The guess is accepted with probability 0.3/0.6=0.50.3 / 0.6 = 0.5.
  • So the overall chance of outputting "blue" through acceptance is 0.6×0.5=0.30.6 \times 0.5 = 0.3: exactly the target's probability.
  • If it's rejected, the replacement is drawn from the tokens the drafter under-rated (where p>qp > q), in proportion to how much it under-rated them. That restores the target's probabilities for every other token.

If the drafter gives a token less probability than the target (q<pq < p), it's always accepted when proposed, and the leftover distribution makes up the rest. The maths guarantees the accepted tokens follow the target's distribution exactly. Speed changes; quality doesn't.

#How much faster?

It depends on the acceptance rate α\alpha: the chance that each drafted token is accepted. With kk drafted tokens and a constant acceptance rate, the expected number of tokens per target step is

E[tokens]=1−αk+11−αE[\text{tokens}] = \frac{1 - \alpha^{k+1}}{1 - \alpha}
Acceptance rate α\alpha k=2k = 2 k=4k = 4 k=8k = 8
0.5 1.75 1.94 2.00
0.7 2.19 2.77 3.20
0.9 2.71 4.10 6.13

The speed-up is that number divided by the cost of a speculative step relative to a plain decode step. If each drafter pass costs 5% of a target pass (a small draft model against a large target), a step costs 1+0.05k1 + 0.05k, and the speed-up at batch 1 is:

Acceptance rate α\alpha k=2k = 2 k=4k = 4 k=8k = 8
0.5 1.59 times 1.61 times 1.43 times
0.7 1.99 times 2.31 times 2.28 times
0.9 2.46 times 3.41 times 4.38 times

Three practical lessons fall out of these tables:

  • The acceptance rate matters more than kk. At 50% acceptance, drafting more than 2 or 3 tokens buys almost nothing, and drafting 8 is slower than drafting 4.
  • There's a best kk for each acceptance rate, and it rises as acceptance rises.
  • Predictable text speculates well. Code, structured output, translation and text that repeats the prompt have high acceptance. Creative writing at high temperature has low acceptance.

#Kinds of drafters

Drafter How it works Notes
Small draft model A smaller model from the same family (say 1B for a 70B) Simple; needs a matching tokenizer; uses extra memory
N-gram or prompt lookup Copy likely continuations from the prompt or earlier text Free; great for editing, summarising and RAG answers that quote sources
Medusa-style heads Extra prediction heads on the target model guess several future tokens No separate model; heads need training
EAGLE-style drafters A small network that reads the target's hidden states to predict ahead High acceptance rates; needs a drafter trained for the specific target
Multi-token prediction Some models are trained with extra prediction heads built in Speculation comes with the model

Two refinements are common:

  • Tree speculation. Instead of one chain of guesses, the drafter proposes a small tree of alternatives (for example, the top 2 candidates at each position). The target verifies the whole tree in one pass using an attention mask, and keeps the longest accepted branch. This raises the expected number of accepted tokens at the cost of more verification work.
  • Built-in multi-token prediction. DeepSeek-V3 was trained with an extra module that predicts one token further ahead. Its technical report says the second token's acceptance rate is between 85% and 90%, giving about 1.8 times the decode speed when used for speculation.

#The catch: batch size

Speculative decoding spends extra compute to save memory reads. At batch 1, the GPU has plenty of idle compute, so this is a great deal. At large batch sizes, decode is no longer purely bandwidth bound: the GPU is doing real work for many sequences, and verifying extra drafted tokens for all of them competes for that compute.

A rough way to see where this happens: an H100 can do about 590 FP8 operations per byte of memory bandwidth. A decode step with FP8 weights does about 2 operations per weight byte per token in the step. So once a step processes more than roughly 300 tokens, it becomes compute-bound. With k=4k = 4, each sequence puts 5 tokens into the step, so a batch of about 60 sequences already reaches that point. Beyond it, extra verified tokens make the step slower, and the speed-up shrinks or disappears.

So the speed-up is largest at low concurrency and shrinks (sometimes below 1) as the batch grows. That makes speculation a natural fit for latency-sensitive, low-concurrency serving, and a questionable one for maximum-throughput batch jobs. Engines increasingly adjust or disable speculation dynamically based on load.

#Turning it on

Flags change between versions, so check your engine's documentation. Typical forms:

bash
# vLLM: an EAGLE-style drafter, 3 speculative tokens
vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --speculative-config '{"method": "eagle3", "model": "PATH_TO_DRAFTER", "num_speculative_tokens": 3}'

# vLLM: n-gram lookup from the prompt, no drafter model needed
vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --speculative-config '{"method": "ngram", "num_speculative_tokens": 4, "prompt_lookup_max": 4}'

# llama.cpp: a small draft model from the same family
llama-server -m Llama-3.1-70B-Instruct-Q4_K_M.gguf -md Llama-3.2-1B-Instruct-Q8_0.gguf -ngl 99 -ngld 99

SGLang has equivalent options for EAGLE and draft models (--speculative-algorithm and related flags).

#How to measure it

  1. Record the acceptance rate or mean accepted length your engine reports, on your real prompts. Engines log or export it as a metric.
  2. Measure time per output token with and without speculation, at several concurrency levels: 1, 4, 16, 64 and your expected peak (how to benchmark an LLM server).
  3. Check memory: a draft model takes GPU memory from the KV cache, which can lower your maximum concurrency.
  4. Split by traffic type. Code and chat can have very different acceptance rates; a blended number hides that.

#When to use it

  • Yes: interactive chat or coding assistants at modest concurrency; long structured outputs; anything where per-user tokens per second is the metric that matters.
  • Maybe: mixed workloads, if your engine can turn speculation down under load.
  • No: offline batch jobs that run at high batch sizes and care only about total throughput.

#Common mistakes

  • Measuring only at batch 1 and promising the same gain in production.
  • Using a drafter from a different model family, which mostly gets rejected (and may not share a tokenizer).
  • Forgetting the drafter's memory, which takes space from the KV cache.
  • Drafting too many tokens for your acceptance rate.
  • Judging by tokens per second without checking acceptance rate across your real prompts.

#FAQ

Does speculative decoding change the model's answers? No. With the correct acceptance test, outputs follow exactly the same distribution as normal decoding.

Does it help time to first token? No. It speeds up decode. Time to first token is set by prefill (serving metrics).

Can I use it locally? Yes. llama.cpp supports a draft model, and on a single-user machine the batch-size problem doesn't arise, so the gains can be large for code and structured output.

#Go deeper

Speculative decoding in depth works through the acceptance maths and drafter choices, and the speculative decoding lab has you measure acceptance and speed-up across batch sizes on a real engine. Both are in the Inference Engineering course.

speculative-decodinglatencydecodeinference-engineering

Found this useful?

Send it to someone who is learning the same thing.

Share this article

Preparing for an interview?

Next: learn it step by step, free

Prefill, decode and the roofline

Why decode is memory-bound, with worked numbers for real GPUs. The idea the rest builds on. A free lesson with step-through diagrams and a quiz.

Get new articles by email

One short email when a new guide is out. Unsubscribe any time.