Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← Inference and servingAI guideAdvanced#inference#speculative-decoding#eagle#latency
Frame · ai-engineering / inference-serving / 04-speculative-decoding.mdGuide 063 / 103

Speculative decoding, from draft models to EAGLE-3

Decode is slow because each token needs a full pass over the model's weights, and the GPU spends most of that pass waiting on memory rather than computing. Speculative decoding exploits the idle compute: a cheap guesser proposes several tokens, and the big model checks all of them in one pass. When the guesses are good you get multiple tokens for the price of roughly one step, and with the right acceptance rule the output distribution is identical to running the big model alone.

Why it matters

For interactive products, inter-token latency is what users feel once text starts streaming. Speculative decoding is one of the few techniques that cuts per-token latency for a single stream without changing the model's outputs, which makes it attractive for chat, coding assistants and agents where each step waits on the previous one. It is also mostly a serving-side change: you keep the same model and the same API.

It is not free, though. It spends extra compute to save memory-bandwidth time, so its value depends on how much spare compute you have. At high batch sizes, where the GPU is already busy, gains shrink and can even turn negative.

How it works

The loop, from the original papers by Leviathan et al. and Chen et al.:

  1. A drafter proposes k tokens after the current context.
  2. The target model runs one forward pass over the context plus those k tokens. Because a forward pass scores every position in parallel (just like prefill), this costs about the same as one decode step when k is small.
  3. Walking left to right, each drafted token is accepted with a probability based on the ratio of target to draft probability. The first rejection is replaced by a token sampled from a corrected distribution, and everything after it is discarded.
  4. If all k are accepted, the target's pass also yields one bonus token for free.

The rejection-sampling rule is what guarantees the final text has exactly the distribution of the target model. With greedy decoding it simplifies to "accept while the draft matches the target's argmax".

Rendering diagram…

The expected speedup depends mainly on the acceptance rate (how often the target agrees with the draft) and the draft cost relative to a target step. A simple way to reason about it:

tokens_per_target_step ≈ expected accepted tokens + 1
speedup ≈ tokens_per_target_step / (1 + k × draft_cost_ratio + verify_overhead)

High acceptance and a nearly free drafter give big wins. Low acceptance means you pay for drafting and throw most of it away.

Kinds of drafters

  • Separate small model. A smaller model from the same family (sharing the tokenizer). Easy to understand, but the drafter needs its own memory and KV cache.
  • N-gram or prompt lookup. Propose tokens by matching the last few tokens against the prompt itself. Costs almost nothing and works surprisingly well for summarisation, code editing and RAG answers that copy from context.
  • Extra heads (Medusa style). Small heads on top of the target predict several future tokens.
  • EAGLE family. A lightweight draft head that reads the target's own hidden states instead of starting from scratch. EAGLE-3 fuses hidden states from several intermediate layers of the target (low, middle and high) and is trained to match the target's outputs, which gives notably higher acceptance than earlier EAGLE versions. Drafts must be trained for the specific target model.
  • MTP (multi-token prediction). Some models ship with built-in prediction modules trained alongside the main model, which engines can use as the drafter.
Rendering diagram…

Reference architecture

Inside a serving engine, speculative decoding lives in the scheduler and executor. Each step, the engine runs the drafter for every active sequence, builds one verification batch for the target, and then updates each sequence's KV cache with only the accepted tokens. Rejected positions must be rolled back from the cache. That is why engines expose it as a configuration on the server rather than something clients control.

The vLLM project also maintains Speculators, a library and model hub for training and packaging EAGLE-3 style drafters that vLLM can load directly.

Code

vLLM configures speculative decoding with a speculative_config dictionary. This is the shape of the EAGLE-3 example from the vLLM docs:

from vllm import LLM, SamplingParams

llm = LLM(
    model="meta-llama/Llama-3.1-8B-Instruct",
    tensor_parallel_size=1,
    speculative_config={
        "model": "RedHatAI/Llama-3.1-8B-Instruct-speculator.eagle3",
        "num_speculative_tokens": 3,
        "method": "eagle3",
    },
)

params = SamplingParams(temperature=0.0, max_tokens=256)
out = llm.generate(["Write a Python function that merges two sorted lists."], params)
print(out[0].outputs[0].text)

For the server, the same dictionary is passed as JSON to vllm serve through its speculative config flag; check vllm serve --help for your version. The vLLM repo also includes an offline example script that reports per-request acceptance rates, which is the first number I look at.

Trade-offs and pitfalls

  • Measure acceptance on your traffic. Acceptance varies by domain, language and sampling temperature. A draft trained on general chat may do poorly on your legal or code workload.
  • Batch size erodes the win. At low concurrency the GPU has spare compute and speculation shines. At high concurrency verification work competes with real work. Benchmark at your production load, not with a single request.
  • More draft tokens is not always better. Each extra speculative token is less likely to be accepted. Small values of k are the usual starting point; tune upward only if acceptance stays high.
  • Memory overhead. Draft models and heads need weights and sometimes their own KV cache, which reduces how many sequences fit.
  • Tokenizer and version coupling. Drafts must match the target's tokenizer, and EAGLE heads are tied to a specific target checkpoint. Upgrading the target means upgrading the draft.
  • Sampling still matches. With correct rejection sampling, output quality does not change. If you see quality changes, suspect a bug or a mismatched draft, not the technique.

Checklist

  • I measured inter-token latency with and without speculation at my real concurrency.
  • I log acceptance rate per endpoint and alert if it drops after a model upgrade.
  • I tried n-gram lookup first for copy-heavy workloads.
  • My draft head or model is pinned to the exact target checkpoint.
  • I tuned num_speculative_tokens starting small.
  • I have a flag to disable speculation quickly if throughput suffers under load.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.