Autoregressive large language model (LLM) generation suffers from an acute hardware efficiency mismatch during inference. While the prefill phase (processing the input prompt) processes tokens in parallel and achieves high arithmetic intensity on modern matrix accelerators, the decode phase (generating text token-by-token) is fundamentally memory-bandwidth bound. At small batch sizes, each generated token requires transferring the model's entire multi-billion-parameter weight matrix from High-Bandwidth Memory (HBM) into on-chip Static Random-Access Memory (SRAM) and register files to execute a single matrix-vector product.
Speculative decoding, formalized independently by Leviathan, Kalman, and Matias (2022) and Chen et al. (2023), breaks this sequential memory bottleneck. By employing a fast, lightweight draft mechanism (such as a smaller companion model or specialized prediction heads) to propose sequences of candidate tokens and verifying them concurrently in a single forward pass of the larger target model, speculative decoding achieves 2x to 4x latency reductions. Crucially, through an exact speculative rejection sampling criterion, speculative decoding guarantees that the output token distribution remains identical to sampling directly from the target model.
The Memory-Wall Bottleneck in Autoregressive Generation
To understand the mechanics and necessity of speculative decoding, one must evaluate autoregressive inference through the Roofline model on modern GPU accelerators.
Arithmetic Intensity and the Roofline Model
The theoretical execution performance (in FLOPs per second) on an accelerator is governed by:
where represents peak floating-point compute capacity (FLOP/s), denotes peak memory bandwidth (bytes/s), and represents the ratio of computational operations to bytes transferred from global memory:
The machine balance threshold defines the transition between memory-bandwidth bound and compute-bound regimes.
Consider an NVIDIA H100 SXM5 GPU:
- Peak 16-bit Tensor Core compute (): 989.4 TFLOP/s (dense FP16/BF16)
- Peak HBM3 bandwidth (): 3.35 TB/s
- Machine balance threshold ():
The Arithmetic Intensity of Single-Token Decoding
For a standard Transformer decoder model with parameter count operating in 16-bit precision (2 bytes per parameter), computing a forward pass on a batch of tokens requires:
- Compute: (from linear projection layers, ignoring minor attention terms for short contexts)
- Memory Movement: to read weights from HBM, plus key-value cache access (where is layer depth and is context length).
When generating a single token for a single sequence ():
Because , single-token autoregressive decoding utilizes less than 0.5% of the accelerator's available arithmetic execution units. The GPU cores spend over 99% of execution cycles waiting for weights to travel across the memory bus.
Prefill vs. Verification Arithmetic Intensity
When verifying a sequence of candidate tokens concurrently, the target model processes all tokens in parallel within the same forward pass:
For , arithmetic intensity increases by while loading the exact same parameter weights from HBM once. Because the latency to read weights dominates the execution time, evaluating tokens simultaneously in parallel takes roughly the same wall-clock time as evaluating a single token. Speculative decoding exploits this slack capacity to convert wasted memory-read cycles into useful token verification.

Mathematical Foundations of Speculative Sampling
The primary theoretical achievement of speculative decoding is proving that acceleration does not require output approximation. The generated text follows the exact target distribution without altering token probabilities or sampling entropy.
Problem Formulation
Let denote the vocabulary space.
- Target model distribution:
- Draft model distribution:
At step , the draft model generates a sequence of speculative tokens sequentially:
The target model then performs a single parallel forward pass over the concatenated sequence , obtaining the exact conditional probability distributions for all simultaneously.
The Modified Rejection Sampling Algorithm
For each candidate token at position , we evaluate the speculative acceptance probability :
We sample a uniform random variable :
- Acceptance: If , the candidate token is accepted: . The verification proceeds to token .
- Rejection: If , the candidate token is rejected. The loop terminates immediately. A replacement token is sampled from the adjusted residual distribution :
All subsequent draft tokens are discarded.
- Bonus Token: If all candidate tokens are accepted, the target model's forward pass has already computed for the -th position. A bonus token is sampled directly from at zero additional marginal inference cost.
Thus, each speculative round produces between and valid tokens.
Mathematical Proof of Exact Distribution Preservation
We now prove that sampling a token through this speculative rejection mechanism yields the identical distribution as sampling directly from the target model: for all .
Proof
Let be the random variable representing the token chosen at position . A token can be produced via two mutually exclusive events:
- was proposed by the draft model () and subsequently accepted.
- The draft model proposed some token , which was rejected, and was sampled from the residual distribution .
The total probability is:
First, evaluate the probability of proposing and accepting it:
Second, evaluate the total acceptance rate , defined as the marginal probability that any proposed draft token is accepted:
Consequently, the total probability of rejection is:
Using the algebraic identity , we have:
Substituting this into the definition of the residual distribution :
Now, substitute these expressions back into the total probability formula:
Using the identity :
This completes the proof. The output distribution of speculative decoding is mathematically identical to the target model distribution.
Greedy Decoding Equivalence
For greedy decoding (temperature ), the target and draft distributions collapse to Dirac delta distributions:
The acceptance criterion simplifies to deterministic equality:
If the draft model's greedy prediction matches the target model's greedy prediction, it is accepted; otherwise, execution rolls back and emits the target model's greedy token.
Theoretical Speedup and Performance Economics
The acceleration achieved by speculative decoding depends on three interacting variables: the draft acceptance rate, the draft model latency, and the speculation window length.
Expected Accepted Tokens per Speculative Round
Assume an independent and identically distributed per-token acceptance rate across a speculation horizon of draft tokens.
The probability of accepting exactly draft tokens (where ) follows a geometric truncated distribution:
- For : Probability of accepting tokens and rejecting on token is . Each such event yields total emitted tokens (including the corrective token from ).
- For : Probability of accepting all tokens is . This event yields total emitted tokens (including the bonus token).
The expected number of emitted tokens per round is:
As , . When and :
Wall-Clock Speedup Formulation
Let:
- = execution time for one forward pass of the target model
- = execution time for one forward pass of the draft model
- = relative cost ratio ()
One round of speculative decoding with speculation length takes:
Standard autoregressive decoding requires for every single token, taking to produce tokens. The theoretical speedup factor is:
Table: Theoretical Speedup as a Function of Acceptance Rate (beta) and Cost Ratio (c) for gamma = 5
-------------------------------------------------------------------------------------------------
Acceptance (beta) | Cost Ratio (c = 0.05) | Cost Ratio (c = 0.10) | Cost Ratio (c = 0.15)
-------------------------------------------------------------------------------------------------
0.50 | 1.57x | 1.31x | 1.12x
0.70 | 2.37x | 1.97x | 1.69x
0.80 | 2.95x | 2.46x | 2.11x
0.90 | 3.75x | 3.12x | 2.68x
0.95 | 4.27x | 3.56x | 3.05x
-------------------------------------------------------------------------------------------------Optimal Speculation Horizon ()
Differentiating the speedup equation with respect to reveals that an optimal speculation horizon exists for any pair :
- If is too small, the system underutilizes the target model's parallel verification capacity.
- If is too large, the marginal probability of accepting distant tokens approaches zero, but the draft model cost continues to accumulate linearly, degrading overall throughput.
In production systems such as vLLM and SGLang, dynamic speculative schedulers track the running acceptance rate per sequence and adaptively resize on a per-step basis.
Tree-Structured Speculation Topologies
Standard speculative decoding uses a linear sequence of candidate tokens. However, linear speculation suffers from sequential dependency: if the second candidate token is rejected, all subsequent tokens () are immediately invalidated, regardless of their intrinsic quality.
Tree-based speculation constructs a branched tree of hypotheses, allowing the target model to evaluate multiple candidate execution paths in parallel.
SpecInfer and Tree-Based Verification
SpecInfer (Miao et al., 2023) introduced tree-structured speculation. The draft model generates a prefix tree (trie) of candidate tokens with branching factor and depth .
To verify a tree topology with total nodes in a single forward pass of the target model, SpecInfer constructs a specialized causal tree 2D attention mask :
This causal tree mask prevents attention leakage across distinct sibling branches while allowing each token to attend to its exact historical prefix path. The target model evaluates all nodes in a single forward kernel call, selects the longest valid accepted path, and rolls back all unselected branches.
Medusa: Multi-Head Speculation Without Companion Models
Medusa (Cai et al., 2024) eliminates the requirement for a separate draft model by appending lightweight decoding heads (single-layer feed-forward networks) directly to the final hidden state of the target model:
Medusa heads generate top- predictions at each positional offset simultaneously. The system takes the Cartesian product of the top candidates, filters them into a fixed tree structure (e.g., 64 candidate paths), and validates them via tree-attention masking in the next target step. Because Medusa heads run concurrently on the target model's existing activations, draft generation latency .
EAGLE and EAGLE-2: Feature-Level Extrapolation
EAGLE (Li et al., 2024) and EAGLE-2 (Li et al., 2024) observe that language modeling is substantially more predictable in feature representation space than in discrete token space.
EAGLE feeds the target model's second-to-last layer hidden states into a single transformer decoder layer, predicting top-level feature vectors autoregressively before projecting to token logits. EAGLE-2 incorporates dynamic draft trees that condition their branching factor on contextual draft confidence (entropy of draft heads), achieving acceptance rates exceeding 85% on coding and structured data benchmarks.
Drafting Paradigms: A Comparative Analysis
Modern inference engines utilize four primary speculative drafting architectures:
Speculative Drafting Architectures
----------------------------------------------------------------------------------------
1. Small Companion Model (Draft Model)
- Mechanism: Separate smaller model from the same architecture family (e.g. Llama-3-8B drafting for Llama-3-70B).
- Advantages: High acceptance fidelity, shares token vocabulary and tokenizer.
- Disadvantages: Requires additional GPU memory allocation for draft weights and draft KV cache.
2. Multi-Head Predictions (Medusa / Hydra)
- Mechanism: Additional linear / MLP heads attached to target model's final hidden state.
- Advantages: Zero additional weight memory overhead; no inter-model synchronization.
- Disadvantages: Requires dedicated supervised fine-tuning of heads; lower acceptance on out-of-distribution reasoning.
3. Feature-Level Recurrent Predictors (EAGLE / EAGLE-2)
- Mechanism: Single-layer transformer operating on top-layer target embeddings.
- Advantages: High acceptance rates (80-90%); robust across diverse temperatures.
- Disadvantages: Requires training an auxiliary lightweight feature module.
4. N-Gram & Prompt Lookup (Prompt-Lookup / REST)
- Mechanism: Matches context n-grams against prompt history to fetch candidate continuations.
- Advantages: Zero compute overhead, zero parameter training.
- Disadvantages: Effective only on high-redundancy tasks (retrieval-augmented generation, document summarization, code editing).Production Serving Constraints and System Dynamics
While speculative decoding consistently accelerates single-stream generation (), its economic viability shifts under heavy batch serving conditions.
The Batch Size Throughput Trade-off
As concurrent serving batch size increases on a GPU:
- High batch sizes () naturally elevate arithmetic intensity , pushing the GPU out of the memory-bandwidth bound regime and into the compute-bound regime.
- In the compute-bound regime, verifying speculative tokens requires additional FLOPs that compete directly with other concurrent requests for Tensor Core execution slots.
- If the acceptance rate is insufficient, the compute cost of rejected speculative tokens reduces overall token throughput (tokens/second across all users) compared to standard continuous batching without speculation.
Consequently, modern LLM inference systems deploy speculative decoding strategically:
- Low concurrency / Strict SLA regimes: Speculative decoding is activated to minimize Time-to-First-Token (TTFT) and Inter-Token Latency (ITL).
- High throughput / Saturated queue regimes: Speculative decoding is dynamically throttled or disabled to maximize global cluster throughput.
KV Cache Management in Speculative Verification
In standard autoregressive decoding, exactly one KV entry is appended to the KV cache per sequence per step. In speculative decoding:
- Speculative Allocation: Space for candidate tokens must be reserved in the paged KV cache during draft generation.
- Selective Pruning and Rollback: Upon target verification, only the accepted prefix of length is retained. The memory manager must immediately reclaim the unaccepted slots ( through ) without causing memory fragmentation or incurring memory copy overhead.
Engines such as vLLM implement paged tree-KV tables, using logical-to-physical block mapping tables to prune rejected branches with pointer reassignments.
Sources
- Leviathan, Y., Kalman, M., & Matias, Y. (2022). Fast Inference from Transformers via Speculative Decoding. arXiv:2211.17192.
- Chen, C., Borgeaud, S., Irving, G., Lespiau, J. B., Sifre, L., & Jumper, J. (2023). Accelerating Large Language Model Decoding with Speculative Sampling. arXiv:2302.01318.
- Miao, X., Oliaro, M., Zhi, Z., Le, T. V., Wang, X., Xu, Z., Lin, Z., Catalyurek, U., & Jia, Z. (2023). SpecInfer: Accelerating Large Language Model Serving with Tree-based Speculative Inference and Verification. arXiv:2305.09781.
- Cai, T., Li, Y., Geng, Z., Peng, B., Lee, J. D., Chen, D., & Dao, T. (2024). Medusa: Simple LLM Inference Acceleration with Multiple Decoding Heads. arXiv:2401.10774.
- Li, Y., Wei, F., Zhang, C., & Zhang, H. (2024). EAGLE: Speculative Sampling Requires Rethinking Feature Uncertainty. arXiv:2401.15077.
- Li, Y., Wei, F., Zhang, C., & Zhang, H. (2024). EAGLE-2: Faster Inference of Language Models with Dynamic Draft Trees. arXiv:2406.16858.
- Kwon, W., Li, Z., Zhuang, S., Sheng, Y., Zheng, L., Yu, C. H., Gonzalez, J. E., Zhang, H., & Stoica, I. (2023). Efficient Memory Management for Large Language Model Serving with PagedAttention. arXiv:2309.06180.
- Zheng, L., Yin, L., Xie, Z., Sun, C., Huang, C. H., Yu, C. H., Cao, S., Christakis, C., Stoica, I., Gonzalez, J. E., & Sheng, Y. (2023). SGLang: Efficient Execution of Structured Language Model Programs. arXiv:2312.07104.



