Background
The root cause of slow LLM generation isn’t that “the model can’t write the answer in one go,” but the sequential dependency of autoregressive decoding: each generated token requires a full forward pass of the target model based on all previous tokens. For scenarios like chat, code completion, Agent tool calls, and long-form answer generation, end-to-end latency is amplified by token-by-token decoding as output length grows.
Common inference optimization techniques include quantization, KV Cache, Prefix Caching, Continuous Batching, PagedAttention, and Tensor Parallelism. These address memory, repeated prefixes, throughput, and hardware parallelism, but none directly break the “one token per step” rhythm. Speculative Decoding aims to change this: a faster draft path first guesses multiple candidate tokens, then the target model verifies them in a single batch forward pass, reducing the number of sequential target model forward passes.
It’s not a universal accelerator for all inference. It targets a specific latency problem: in single-request or small-batch scenarios, where the target model’s per-step decoding doesn’t fully utilize the GPU, and the output contains predictable segments. Examples include code completion, summarization, document Q&A, formatted responses, customer service replies, and templated business copy.
Core Principle: From “One Token at a Time” to “Verify Multiple Tokens at Once”
The classic flow can be broken into three steps:
- Draft: Use a small model, NGram, extra decoding heads, or other lightweight methods to generate K candidate tokens.
- Verify: Feed these candidate tokens to the target model in a single batched forward pass for verification.
- Commit: Accept the prefix of tokens approved by the target model; at the first mismatch, discard subsequent candidates and let the target model correct.
Think of it as a variant of CPU speculative execution applied to LLM decoding: predict a future path, save time if correct, roll back if wrong. The key difference is that the LLM’s output distribution must not be altered. Classic speculative decoding uses rejection sampling to ensure the final distribution matches token-by-token decoding from the target model.
The paper “Fast Inference from Transformers via Speculative Decoding” proposed a method that accelerates existing autoregressive models without modifying their architecture, reporting 2x-3x speedup on T5-XXL while maintaining identical outputs. These results don’t directly generalize to all models and traffic patterns, but they highlight the core value: compressing multiple sequential target model forward passes into fewer verification passes.
Why It Can Be Faster
LLM inference is often memory-bandwidth-bound. Hugging Face’s assisted generation article notes that the latency bottleneck in text generation comes from the large model’s continuous forward passes; in many cases, loading model weights into compute cores is more critical than the arithmetic operations themselves. This means processing 1 new token versus a short sequence of candidate tokens doesn’t necessarily incur linear cost growth.
Speculative Decoding exploits this:
- The draft model is small, so generating candidate tokens is cheap.
- The target model verifies multiple tokens at once, increasing the “tokens confirmed per forward pass.”
- If the acceptance rate is high enough, the number of target model forward passes decreases.
- If the draft cost is lower than the saved target model cost, latency is reduced.
The key isn’t “the stronger the draft model, the better,” but rather the balance between draft model latency, acceptance rate, and target model verification overhead. A stronger but slower draft model can actually make the system slower.
Engineering Options: Mainstream Approaches
1. Draft-Target Model
This is the most intuitive approach: use a small draft model and a large target model. The draft model predicts candidate tokens, and the target model verifies them.
Suitable scenarios:
- The target model is large, making single-step decoding slow.
- A small model with the same tokenizer or high compatibility exists.
- Requests are small-batch, latency-sensitive.
- Outputs are relatively deterministic, leading to high acceptance rates.
Engineering constraints:
- Tokenizers should ideally match; otherwise, decoding/re-encoding costs are introduced.
- The draft model requires deployment, monitoring, and version management.
- Sampling parameter consistency between target and draft models must be handled.
- Streaming output must not expose unverified tokens prematurely.
Hugging Face’s assisted generation implementation requires the assistant model to share the same tokenizer as the main model and warns that benchmarking is necessary before application. Their article also notes that the assistant model should be at least an order of magnitude smaller than the main model for benefits to be more apparent.
2. NGram / Prompt-based Speculation
NGram speculative decoding doesn’t rely on a separately trained draft model. Instead, it copies potentially repeated n-grams from the input prompt or already generated output as candidates.
This approach is suitable for:
- Summarization.
- Document Q&A.
- Multi-turn chat with repetitive context.
- Code editing.
- Tasks where output heavily references input.
TensorRT-LLM documentation also lists NGram as a supported speculative sampling method, emphasizing its suitability for scenarios with high n-gram overlap between input and output.
The advantage is simple deployment without maintaining a draft model. The disadvantage is limited generalization; acceptance rates can be unstable for open-ended creative or reasoning tasks.
3. Medusa / Multi-Head Prediction
Medusa doesn’t use an independent draft model. Instead, it adds multiple extra decoding heads to the target model. These heads predict future tokens, and multiple paths are verified via tree-structured candidates and attention masks.
It reduces the complexity of “maintaining an extra draft model” but requires training extra heads and handling issues like candidate tree size, masks, KV Cache, and inference backend compatibility. The Medusa paper reports Medusa-1 achieving over 2.2x speedup without compromising generation quality, and Medusa-2 reaching 2.3-3.6x. These are experimental results and shouldn’t be taken as production SLA guarantees.
4. EAGLE / Feature-level Drafting
EAGLE shifts the draft prediction from the token level to the internal feature level of the model. The EAGLE paper argues that autoregressive prediction of the second-to-top-layer feature is more direct than predicting tokens, reporting 2.7x-3.5x latency speedup on LLaMA2-Chat 70B while maintaining the generated text distribution.
These methods are typically closer to the intersection of inference systems and model training: they can be more effective, but deployment is more complex, requiring specific models, draft components, backend runtimes, and verification logic.
5. Lookahead Decoding
Lookahead Decoding attempts to avoid a draft model altogether. It treats autoregressive decoding as a nonlinear equation-solving problem, using Jacobi-like parallel decoding to generate n-grams, which are then verified in the same step. The LMSYS blog reports 1.5x-2.3x latency reduction.
Its engineering value lies in reducing draft model maintenance costs. Whether it’s suitable for production depends on runtime support, attention mask implementation, and the specific model and task output format.
Production Deployment Workflow
Step 1: Identify Suitable Traffic First, Don’t Enable Site-Wide
Don’t treat Speculative Decoding as a universal toggle. Segment traffic by request type:
- Code completion.
- Document Q&A.
- Summarization.
- Formatted JSON or templated output.
- Customer service / internal assistants.
- Long reasoning or creative dialogue.
Start with scenarios that have low temperature, low openness, and predictable output. Open-ended creation, complex reasoning, strong sampling, and high-temperature output typically lead to less stable draft acceptance rates.
Step 2: Define the Draft Strategy
A draft strategy must answer at least four questions:
- What is the draft source: small model, NGram, Medusa head, EAGLE draft, or Lookahead?
- How is the candidate length K set: fixed, dynamic, or adjusted based on historical acceptance rates?
- Does it share the tokenizer, vocabulary, and sampling configuration with the target model?
- How does it fall back to normal decoding when drafting fails?
A simplified dynamic candidate length strategy:
class DraftBudget:
def __init__(self, min_k=2, max_k=8):
self.k = min_k
self.min_k = min_k
self.max_k = max_k
def update(self, accepted: int, drafted: int):
if drafted == 0:
return
ratio = accepted / drafted
if ratio > 0.8:
self.k = min(self.k + 1, self.max_k)
elif ratio < 0.4:
self.k = max(self.k - 1, self.min_k)
This code isn’t a complete inference implementation; it illustrates an engineering principle: K shouldn’t be a fixed guess; it should be constrained by acceptance rate and latency feedback.
Step 3: Integrate with the Inference Backend
If using an existing runtime, start with its native capabilities:
| Framework | Supported Speculative Approaches |
|---|---|
| TensorRT-LLM | draft-target, NGram, Medusa, ReDrafter, EAGLE, Lookahead |
| Hugging Face Transformers | assisted generation |
| vLLM / SGLang | Refer to current documentation and benchmarks |
Don’t just test with single-request demos in production. Cover at least:
- Single-request TTFT.
- Streaming output cadence.
- Low-concurrency, small-batch.
- High-concurrency batch.
- Long outputs.
- Multi-tenant mixed traffic.
- Failure fallback.
Step 4: Monitoring Metrics Must Be in Place
Establish the following metrics before going live:
| Metric | Description | Why It Matters |
|---|---|---|
| accepted_tokens / drafted_tokens | Draft token acceptance rate | Determines if the draft is effective |
| target_forward_passes_saved | Saved target model verification passes | Indicates if serial steps are truly reduced |
| draft_latency_ms | Draft generation cost | Prevents the draft model from slowing things down |
| verify_latency_ms | Target model verification cost | Assesses if batch verification is worthwhile |
| TTFT | Time to first token | Key user-perceived latency metric |
| TPOT | Time per output token | Core generation phase metric |
| rollback_rate | Rate of fallback to normal decoding | Indicates stability |
| quality_diff_sampled | Sampled quality difference | Prevents implementation details from degrading quality |
Relying only on GPU utilization and total tokens/s can be misleading. Speculative Decoding is often a latency optimization and may not increase total throughput under all concurrency levels.
Common Pitfalls
Pitfall 1: Taking Paper Speedups at Face Value
Speedups in papers and documentation are measured under specific models, hardware, tasks, and implementations. Production systems add factors like scheduling, networking, streaming responses, queue wait times, KV Cache management, and multi-tenant mixed loads. The correct approach is to benchmark your own business workload, not directly reuse published numbers.
Pitfall 2: Assuming a Stronger Draft Model is Always Better
A stronger draft model may have a higher acceptance rate, but if it’s slow, the overall system can still be slower. A more reasonable goal is to maximize:
saved_target_time - draft_time - verification_overhead - scheduling_overhead
Draft model selection should be based on end-to-end latency and cost, not just draft model perplexity or benchmark scores.
Pitfall 3: Ignoring Tokenizer and Sampling Parameters
Inconsistent tokenizers between the draft and target models introduce re-encoding costs and can complicate candidate token alignment. Inconsistencies in sampling parameters, stop tokens, logits processors, banned words, and structured output constraints can also cause verification logic to diverge from normal decoding behavior.
Pitfall 4: Assuming It’s Always Faster Under High Concurrency
TensorRT-LLM documentation notes that speculative sampling can reduce average token latency when the GPU is underutilized due to small batches. Conversely, if high-concurrency batches already saturate the GPU, verifying multiple candidate tokens can increase computational pressure, diminishing returns or even causing throughput regression.
Pitfall 5: Streaming Unverified Tokens to Users
If the system outputs draft tokens early for perceived speed, and they are later rejected by the target model, it leads to retractions, flickering, or incorrect output. Production systems should only stream verified tokens, unless the product layer explicitly accepts a “correctable draft” interaction pattern.
Production Readiness Checklist
Before going live, check at least:
- Enablement scope is defined: by model, route, business, tenant, or traffic percentage.
- One-click fallback to normal decoding is configured.
- Tokenizer, special tokens, and stop token strategies are verified between draft and target models.
- Sampling parameters, logits processors, and structured output constraints are aligned.
- Metrics for accepted_tokens, drafted_tokens, draft_latency, and verify_latency are recorded.
- Benchmarks for both low-concurrency and high-concurrency scenarios are completed.
- Regression testing with fixed golden prompts is performed.
- Streaming output is evaluated to ensure only verified tokens are exposed.
- KV Cache, position IDs, attention masks, and candidate tree implementations are evaluated.
- Anomaly fallback and alert thresholds are prepared.
Suitable Scenarios
More suitable for:
- Low-temperature code completion.
- Document summarization.
- RAG Q&A where answers largely come from context.
- Templated business replies.
- Multi-turn dialogues with common expressions and fixed flows.
- Single-request or small-batch, low-latency scenarios.
Use with caution for:
- High-temperature open-ended creation.
- Strong reasoning with long chains of thought.
- High-concurrency, large-batch workloads.
- Multi-model platforms where draft models are difficult to maintain.
- Agents whose output heavily depends on complex tool call states.
Summary
If your production bottleneck is primarily prefill, retrieval, tool calls, network queuing, or post-processing, Speculative Decoding may not be the top priority. It primarily optimizes the decode phase. Use tracing to clearly identify the bottleneck first. For matching scenarios, start with low-risk traffic, establish a comprehensive metric system, and have a solid fallback plan. That’s how you translate paper speedups into production gains.
References
- Yaniv Leviathan, Matan Kalman, Yossi Matias, “Fast Inference from Transformers via Speculative Decoding”, arXiv, 2022. https://arxiv.org/abs/2211.17192
- Hugging Face Blog, “Assisted Generation: a new direction toward low-latency text generation”, 2023. https://huggingface.co/blog/assisted-generation
- NVIDIA TensorRT-LLM Documentation, “Speculative Sampling”. https://nvidia.github.io/TensorRT-LLM/advanced/speculative-decoding.html
- LMSYS, “Break the Sequential Dependency of LLM Inference Using Lookahead Decoding”, 2023. https://www.lmsys.org/blog/2023-11-21-lookahead-decoding/
- Tianle Cai et al., “Medusa: Simple LLM Inference Acceleration Framework with Multiple Decoding Heads”, arXiv, 2024. https://arxiv.org/abs/2401.10774
- Yuhui Li et al., “EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty”, arXiv, 2024. https://arxiv.org/abs/2401.15077
- Shenggui Li et al., “SpecForge: A Flexible and Efficient Open-Source Training Framework for Speculative Decoding”, arXiv, 2026. https://arxiv.org/abs/2603.18567