Inferensys

Glossary

Speculative Decoding

Speculative decoding is an inference acceleration technique where a small, fast draft model proposes candidate tokens for parallel verification by a larger target model, reducing the number of costly autoregressive steps.
Developer testing AI inference on mobile phone in hand, laptop with optimization code visible, casual tech review moment.
INFERENCE OPTIMIZATION

What is Speculative Decoding?

Speculative decoding is a latency reduction technique that accelerates the autoregressive generation of large language models by using a smaller, faster draft model to propose token sequences for parallel verification.

Speculative decoding is an inference acceleration technique where a small, fast draft model (e.g., a distilled model) proposes a sequence of candidate future tokens. The primary, larger target model then verifies these proposals in a single, parallel forward pass, accepting correct tokens and rejecting incorrect ones with a single rollback step. This process reduces the number of costly, sequential autoregressive steps required from the large model, directly lowering generation latency.

The technique hinges on a high acceptance rate for the draft tokens. It is most effective when the draft model's predictions align closely with the target model's, making it a form of approximate computation. Key implementations include Google's Medusa and speculative sampling. It is fundamentally a memory-bound optimization, as its primary gain comes from reducing the number of high-latency model evaluations rather than arithmetic operations, complementing other KV cache management strategies.

INFERENCE OPTIMIZATION

Key Characteristics of Speculative Decoding

Speculative decoding accelerates autoregressive generation by using a small draft model to propose token sequences, which are then verified in parallel by a larger target model. This reduces the number of costly sequential steps.

01

Draft-Verify Paradigm

The core mechanism involves a two-stage process:

  • Drafting Phase: A small, fast draft model (e.g., a distilled version of the target) runs autoregressively for k steps to propose a candidate sequence of tokens.
  • Verification Phase: The larger, more accurate target model processes this entire candidate sequence in a single, parallel forward pass. It scores the draft tokens against its own predictions, accepting them in a contiguous block up to the first mismatch. This allows the target model to generate multiple tokens per its own expensive forward pass, breaking the sequential bottleneck.
02

Wall-Time Speedup

The primary goal is to reduce end-to-end latency (wall-clock time). Speedup is achieved when the time saved by verifying k tokens in parallel outweighs the time cost of running the draft model.

  • Key Metric: The acceptance rate—the average number of draft tokens accepted per verification step. A high acceptance rate is critical for gains.
  • Theoretical Limit: Speedup is bounded by the draft model's latency and the verification cost. It is most effective when the target model is significantly slower than the draft model.
  • Real-World Impact: Can achieve 2-3x latency reduction for large models like Llama-70B when paired with a well-chosen draft model, without altering the final output distribution.
03

Lossless Acceleration

A defining feature of standard speculative decoding is that it is mathematically lossless. The output distribution is identical to what the target model would produce running standard autoregressive decoding.

  • Verification Guarantee: The target model's parallel verification acts as a rejection sampling mechanism. Only tokens that match the target model's own probability distribution are accepted.
  • No Quality Degradation: Unlike quantization or pruning, there is no approximation error or change in the model's behavior. This makes it ideal for production systems where output fidelity is paramount.
  • Deterministic Output: Given the same random seed, the speculative decoding run will produce the exact same sequence as the standard autoregressive run.
04

Model Requirements & Pairing

Successful deployment depends on a strategic draft-target pairing.

  • Draft Model Traits: Must be small, fast, and aligned. Common choices include:
    • A distilled version of the target model.
    • A shallower or narrower architecture (e.g., fewer layers).
    • A n-gram or statistical model in some implementations.
  • Alignment is Critical: The draft model must have a high probability of predicting the same next token as the target model. Poor alignment leads to low acceptance rates and negates the speedup.
  • Training: Draft models are often specifically trained on the target model's outputs to maximize prediction alignment.
05

Memory and Compute Trade-off

Speculative decoding trades increased memory bandwidth and compute intensity for reduced latency.

  • Memory Bandwidth: The verification phase requires loading the full target model parameters and the KV cache for a batch size equal to the draft length k+1. This can be high but is amortized over multiple accepted tokens.
  • Compute: The draft model adds extra FLOPs. The verification phase is a single forward pass but on a batch of k+1 sequences.
  • Optimal k: The lookahead length k must be tuned. A larger k increases the potential reward (more tokens accepted) but also the cost of a failed draft (more wasted verification compute). The optimal k is hardware and model-dependent.
06

Related Techniques & Evolution

The core idea has inspired several variants and adjacent optimizations:

  • Medusa & Self-Speculative Decoding: Uses multiple prediction heads attached to the same target model to draft future tokens, eliminating the need for a separate draft model.
  • Speculative Sampling: The original algorithm for lossless acceleration.
  • Lossy Variants: Techniques like EAGLE modify the verification step for greater speedup at a potential, controlled cost to output quality.
  • Integration with Other Optimizations: Often combined with PagedAttention (for efficient KV cache management of draft sequences) and continuous batching to maximize GPU utilization during verification.
INFERENCE ACCELERATION TECHNIQUES

Speculative Decoding vs. Standard Autoregressive Decoding

A technical comparison of two primary methods for generating tokens from a large language model, focusing on latency, throughput, and computational trade-offs.

Feature / MetricStandard Autoregressive DecodingSpeculative Decoding

Core Mechanism

Sequentially generates one token per model forward pass.

Uses a small draft model to propose multiple candidate tokens in parallel for verification by the target model.

Latency per Token

Directly proportional to the target model's latency.

Reduced; latency amortized over multiple verified tokens per target model call.

Throughput (Tokens/sec)

Limited by serial dependency of the decode phase.

Increased; higher token generation rate due to parallel verification of token drafts.

Computational Load

One full target model forward pass per generated token.

Variable; cost includes draft model passes + target model verification passes. Net reduction when acceptance rate is high.

Memory Access Pattern

Predictable, sequential reads/writes to the KV Cache.

Irregular; depends on draft accuracy. Requires efficient, parallelizable KV Cache access for verification.

Optimal Use Case

General-purpose, deterministic generation.

Scenarios with high draft-target model correlation (e.g., domain-specific tasks, summarization).

Key Limitation

Inherently sequential; latency scales linearly with output length.

Performance degrades if draft model accuracy is low, leading to high rejection rates and wasted computation.

Implementation Complexity

Standard, well-understood inference pattern.

High; requires coordinating two models, managing draft sequences, and implementing a verification/rollback mechanism.

SPECULATIVE DECODING

Frameworks and Implementations

Speculative decoding is an inference acceleration technique where a small, fast draft model proposes a sequence of candidate tokens, which are then verified in parallel by the larger target model, reducing the number of costly autoregressive steps required.

01

Core Mechanism: Draft & Verify

The technique operates in a two-stage loop. First, a small draft model (e.g., a distilled version of the target) runs autoregressively for γ steps to propose a candidate sequence. Second, the large target model processes this entire candidate sequence in a single, parallel forward pass. It scores the draft tokens and, upon finding a mismatch, rejects all subsequent tokens and generates a correction. This replaces γ serial target model calls with one parallel verification, achieving speedups of 2-3x.

02

Key Implementation: Medusa & Self-Speculation

Medusa is a prominent framework that adds multiple prediction heads (a 'medusa head') on top of the target model's backbone, enabling it to act as its own draft model. This self-speculation eliminates the need for a separate model. Key components include:

  • Multiple Decoding Heads: Predict several future tokens in parallel.
  • Tree Attention: Efficiently verifies a tree of candidate token sequences.
  • Typical Acceptance Rates: Often achieves 2-4 accepted tokens per verification step, significantly reducing latency.
03

Speculative Sampling Algorithm

This is the standard algorithm for token acceptance. After the target model verifies the draft:

  1. It generates adjusted probability distributions.
  2. For each position, the draft token is accepted with probability min(1, p_target / p_draft).
  3. If a token is rejected, a new token is resampled from the adjusted distribution. This ensures the output distribution is mathematically identical to that of the original target model, preserving quality. The speedup is directly tied to the draft model's accuracy and the number of speculative steps (γ).
04

System Optimizations: vLLM & TensorRT-LLM

Leading inference engines integrate speculative decoding to maximize hardware utilization.

  • vLLM: Leverages its PagedAttention mechanism to efficiently manage the KV caches for both draft and target models within its continuous batching scheduler, minimizing memory fragmentation.
  • TensorRT-LLM: Provides optimized kernels for the draft and verification passes, fusing operations and leveraging in-flight batching to maintain high GPU utilization during the variable-length acceptance phase.
05

Draft Model Selection Strategies

Choosing the draft model is critical for performance. Common strategies include:

  • Distilled Model: A smaller version of the target, trained to mimic its output distributions.
  • N-gram or Lookup Model: Extremely fast, shallow models based on statistical frequency.
  • Structured Drafting: Using a lossless method like BiLD, which employs a different, faster model family (e.g., a non-autoregressive model) to generate candidates without distributional mismatch. The goal is to maximize the acceptance rate while minimizing the draft model's computational overhead.
06

Limitations and Trade-offs

Speculative decoding introduces specific engineering trade-offs:

  • Memory Overhead: Must maintain two sets of model weights and KV caches in GPU memory.
  • Draft Model Accuracy: Speedup collapses if the draft model is poor; the rejection rate must be low.
  • Context Length: The technique is most effective for the decode phase. Very long context prefill phases remain a bottleneck.
  • Hardware Saturation: On memory-bound systems, the parallel verification pass may not fully hide the draft latency, diminishing returns.
SPECULATIVE DECODING

Frequently Asked Questions

Speculative decoding is a key technique for accelerating large language model inference. These FAQs address its core mechanisms, trade-offs, and practical implementation.

Speculative decoding is an inference acceleration technique where a small, fast draft model proposes a sequence of candidate tokens, which are then verified in parallel by a larger, more accurate target model, reducing the number of costly autoregressive steps. The process works in three stages: 1) The draft model runs autoregressively for k steps to generate a speculative sequence. 2) The target model processes this entire sequence in a single, parallel forward pass, producing logits for each position. 3) A verification algorithm compares the draft and target model outputs, accepting consecutive tokens where the distributions align and rejecting the first mismatch, after which the process repeats. This allows the target model to generate multiple tokens per step when speculation is correct.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.