How do you deploy speculative decoding in production — draft selection, tree attention, and batch-size trade-offs?
Written by the mlprep team · Updated
You've implemented basic speculative decoding with a small draft model and a 70B target model, and it gives a 2.5× speedup at batch size 1. When you roll it out to production at batch size 64, latency actually gets worse. Why does this happen, and how do modern serving systems decide when and how to run speculative decoding?
The batch-size crossover (why speculation can hurt at high load)#
Speculative decoding only works for "free" while the target model's verification pass stays memory-bandwidth-bound.
- At batch size
B = 1withK = 5draft tokens, the target model processes1 × 6 = 6tokens per step. That's still far below the H100's compute ridge point (~295 FLOPs/byte), so verifying 6 tokens takes nearly the exact same wall-clock time as decoding 1 token. - At batch size
B = 64withK = 5, the target model suddenly processes64 × 6 = 384tokens per step! Now the verification pass crosses into the compute-bound regime.
Once compute-bound, every rejected draft token is wasted FLOPs that directly increase step latency and reduce system throughput. Add the overhead of running the draft model (and KV-cache management for rejected tokens), and speculative decoding becomes slower than standard autoregressive decoding under heavy batch load.
How production systems handle this#
- Dynamic / batch-aware speculation: Monitor active batch size (and acceptance rate). Use
K = 5at low batch sizes (B <= 8), taper toK = 2at medium batches, and automatically disable speculation onceBexceeds the compute-bound crossover threshold (oftenB ≈ 32–64depending on GPU and model). - Workload-selective routing: Enable speculation for latency-sensitive interactive coding/editing endpoints (where acceptance rates on structured syntax and boilerplate are 80%–90%+) and disable it on offline high-throughput batch jobs.
Maintaining a separate draft model complicates deployment — you need matching tokenizers, extra GPU memory, and another model to fine-tune whenever the target changes. What are the modern alternatives (like Medusa, EAGLE, or n-gram/prompt-lookup drafting), and how does tree-based verification boost acceptance rates?
Drafting without a separate model#
- N-gram / Prompt-Lookup Decoding (zero extra weights):
- Look for the last 2–4 generated tokens inside the input prompt or recent output; if found, copy the next
Ktokens as the draft. - Completely free, zero training, and surprisingly strong (2×–3× speedup) on RAG, document editing, summarization, and code refactoring where chunks of text are copied verbatim.
- Look for the last 2–4 generated tokens inside the input prompt or recent output; if found, copy the next
- Medusa (parallel prediction heads):
- Attach
Klightweight MLP heads on top of the target model's final hidden state to predict tokenst+1, t+2, ..., t+Ksimultaneously in one pass. - Easy to train (freeze the base model), minimal memory overhead, though heads predict independently (no token-to-token conditioning between drafted positions).
- Attach
- EAGLE / EAGLE-2 / EAGLE-3 (feature-level autoregressive draft head):
- Runs a tiny 1-layer transformer draft head that takes both the target model's second-to-top hidden states and the sampled token embeddings to autoregressively draft
Ktokens. - Because it conditions on rich target features and previous draft tokens, EAGLE achieves much higher acceptance rates than Medusa while costing under 2% of target parameters — making it the dominant production approach today.
- Runs a tiny 1-layer transformer draft head that takes both the target model's second-to-top hidden states and the sampled token embeddings to autoregressively draft
Tree-based verification (tree attention)#
Instead of drafting a single chain of K tokens (where one early mistake invalidates the entire rest of the chain), draft a small tree of candidate continuations (e.g., top-2 branches at step 1, top-2 at step 2) and flatten all tree nodes into a single target forward pass using a custom tree attention mask so each node only attends to its ancestors in the tree.
Because the target model verifies the whole tree in one parallel pass, the probability of finding a long accepted path increases substantially — pushing average accepted tokens per step higher without extra target forward passes.
Senior/staff considerations#
- KV cache rollback: When draft token
iis rejected, you must cleanly truncate/discard KV cache entries for tokensi..K(or overwrite their block slots in PagedAttention) so rejected tokens never pollute subsequent attention. - Tokenizer lock-in: Classic draft-model speculation requires identical vocabulary and tokenizer between draft and target. If you post-train or add special tokens to the target model, a stale draft model's acceptance rate collapses.
- Sampling temperature: Higher temperature (
T > 0.7) spreads probability mass across more tokens, lowering acceptance rate compared to greedy decoding (T = 0).
Interview red flags#
- Assuming speculative decoding improves maximum throughput at full cluster saturation (it is primarily a latency / low-to-medium batch optimization; at saturated batch sizes, wasted FLOPs on rejected tokens reduce throughput).
- Claiming speculative decoding trades off output quality for speed (standard rejection sampling is mathematically lossless; only relaxed/lossy variants trade quality).
- Ignoring KV-cache rollback and alignment with PagedAttention/continuous batching.
Go deeper: How speculative decoding works covers the core draft-then-verify algorithm and why rejection sampling keeps outputs exact.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Speculative decoding shines in the memory-bandwidth-bound regime (low-to-medium batch sizes) but degrades throughput once verification crosses into compute-bound batch sizes. Production deployments use batch-aware dynamic speculation, lightweight feature-conditioned drafters like EAGLE or zero-cost prompt-lookup drafting, and tree-attention verification to maximize accepted tokens per target forward pass.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How does acceptance rate behave as you increase sampling temperature from 0.0 to 1.0, and why?
- Why does EAGLE outperform Medusa on acceptance rate while adding almost no extra memory?
- How would you benchmark whether speculative decoding improves goodput on your actual production traffic distribution?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
When do you use tensor parallelism vs. pipeline parallelism vs. data parallelism for LLM inference?
What is speculative decoding and how does it speed up LLM inference?
How do you serve ML models at low latency and high throughput?
Why do prefill and decode have opposite hardware bottlenecks, and how does disaggregated serving help?