Speculative Decoding: How Draft Models Accelerate LLM Inference and When to Use Them
Speculative Decoding is an acceleration technique for large language models that requires no hardware upgrades or weight modifications, and is supported by mainstream inference frameworks. This article explores the bottlenecks in LLM generation, the underlying principles and workflow of speculative decoding, how to calculate its acceleration ratio, and practical guidelines for selecting draft models and adjusting parameters to optimize inference performance.
When deploying Large Language Models (LLMs), both VRAM and compute power can easily become bottlenecks. Many users experience slow, token-by-token generation even on high-end GPUs. Speculative Decoding is an acceleration method that operates without changing the hardware or the model weights, and it is now supported by many mainstream inference frameworks. This article explains why it works, when it is effective, and how to determine if it is cost-effective for your use case.
1. Where is the Bottleneck in Slow Generation?
An LLM inference process typically consists of two stages.
The Prefill stage processes the entire input prompt provided by the user. The model can compute attention in parallel and build the KV Cache in one pass. This step has high computational density, and its speed primarily depends on the GPU’s floating-point compute capability. While prefill can consume significant time for long inputs, it already utilizes the GPU quite efficiently.
The Decode stage generates output tokens one by one. For each generated token, the GPU must read all model weights and the existing KV Cache from VRAM, compute the result, and write back the new cache. With model parameters often reaching tens of gigabytes, moving this data back and forth for every single token is highly inefficient. During this stage, compute units are frequently stalled waiting for data, making the speed primarily limited by memory bandwidth.
Therefore, the optimization focus of Speculative Decoding is the decode stage. When the prompt is exceptionally long and prefill takes up a lot of time, its benefit is limited—a factor to consider during model selection.
2. The Basic Workflow of Speculative Decoding
The core idea is to let a small model guess first, and then have the large model verify the guesses. The process involves three steps.
First is Draft Generation. A Draft Model rapidly predicts γ consecutive candidate tokens based on the current context. γ represents the draft length, typically between 3 and 8. The draft model has fewer parameters, making the cost of reading weights and generating tokens very low.
Second is Parallel Verification. The Target Model concatenates these γ candidate tokens into a sequence and computes the probability distribution for each position using a single forward pass. The VRAM read overhead for this computation is similar to generating a single token, yet it can verify multiple positions simultaneously.
Third is Accept and Reject. For each candidate token x, let q(x) be the probability given by the draft model and p(x) be the probability given by the target model. The system accepts the token with a probability of min(1, p(x)/q(x)). If a token is rejected, that position and all subsequent candidates are discarded. The system then samples a replacement token from a corrected distribution (the positive part of p minus q, normalized). If all candidates are accepted, the target model can additionally sample an extra token at the final position.
This rule has a crucial property: theoretically, the distribution of the final output matches exactly that of running the target model directly. Speculative Decoding changes the computation method but preserves the statistical distribution of the generated results. For greedy decoding (temperature = 0), the acceptance rule simplifies to checking whether the candidate token is the same as the highest-probability token from the target model.
3. How to Calculate the Acceleration Effect
The acceleration effect depends on two factors: the average number of tokens advanced per round, and the overhead of the draft model.
Looking at the acceptance length: if the acceptance probability for each candidate token is α and the draft length is γ, the average number of tokens produced per target model forward pass is approximately (1 − α^(γ+1)) / (1 − α). This includes the replacement token or the extra sampled token. The higher the α, the more tokens produced per round.
Looking at the cost: if the time for the draft model to generate a single token is c times that of the target model, the total time per round is approximately (γc + 1) times a single forward pass of the target model. Thus, the theoretical speedup ratio is roughly the average tokens produced per round divided by (γc + 1).
Consider a simple example. If α is 0.8 and γ is 4, each round produces an average of about 3.4 tokens. Assuming the draft model takes only 5% of the target model’s time per token (c = 0.05), the round takes about 1.2 target units, yielding a speedup of ~2.8x. If α drops to 0.4, the average output is about 1.7 tokens, and the speedup is ~1.4x. However, if the draft model is too large and c rises to 0.3, with α at 0.4, the round takes ~2.2 target units but only produces ~1.7 tokens, making it slower than standard decoding.
These figures are theoretical estimates. Actual results will also be affected by memory access patterns, batch sizes, framework implementations, and hardware environments.
4. Draft Length is Not the Longer the Better
A larger draft length γ means higher potential gains per round, but if the acceptance rate drops, wasted draft computations increase. When the acceptance rate is high, γ can be appropriately increased. When it is low, the draft length should be shortened, or speculative decoding should be disabled if necessary.
Acceptance rates vary significantly across different tasks:
- Code generation, fixed-format outputs like JSON, and templated texts: These have strong regularity, so the draft model usually guesses correctly at a high rate, making them suitable for longer drafts.
- General Q&A and summarization: The acceptance rate is moderate, and γ can be adjusted based on actual data.
- Highly open-ended creative writing: The divergence between the draft and target models’ distributions is large, leading to a lower acceptance rate and limited gains.
There is also a constraint in high-concurrency scenarios. As batch sizes increase, the GPU transitions from being memory-bandwidth-bound to compute-bound. The extra computation during the verification stage will consume resources, and rejected drafts waste compute power. Therefore, the per-request speedup ratio is typically lower than in low-concurrency scenarios. Throughput improvements should always be verified with actual stress testing.
5. How to Choose a Draft Model
The draft model determines both the acceptance rate and the overhead. When selecting, refer to this checklist:
- Matching Vocabulary: The draft and target models must use the same Tokenizer; otherwise, candidate tokens cannot be mapped directly.
- Similar Architecture: Smaller versions from the same model family, or distilled models, usually have output distributions closer to the target, resulting in higher acceptance rates.
- Sufficient Speed: The draft model’s per-token latency must be significantly lower than the target model’s; otherwise, the draft computation itself becomes the bottleneck.
- Affordable VRAM: The draft model’s weights and KV Cache consume VRAM. On GPUs with tight memory, you need to calculate the remaining space first.
- Aligned Sampling Parameters: Settings like temperature and top-p must be consistent between the two models; otherwise, the probability ratios will be distorted, decreasing the acceptance rate.
- Adjustable Draft Length: The inference service should support dynamically adjusting γ and disabling the feature when necessary.
