How Speculative Decoding Speeds Up LLM Inference: Principles and Benchmarking Methods
Speculative decoding accelerates large language model inference by having a smaller draft model predict several tokens in advance and a larger target model verify them in batches. This article explains why autoregressive generation is slow, how speculative decoding works, which metrics determine its effectiveness, how to optimize an implementation, and how to benchmark results such as an increase from roughly 40 tokens/s to nearly 120 tokens/s without overstating the gain.
1. Why Traditional Autoregressive Generation Is Slow
One of the most important factors affecting the user experience of large language model inference is generation speed, commonly measured in tokens per second (tokens/s). For large models, each generation step often requires a complete forward pass. Performance can be affected by the number of layers, hidden dimension, attention mechanism, memory bandwidth, and concurrency, so the resulting speed may be unsatisfactory.
Most large language models generate text autoregressively. Given the tokens already produced, the model predicts the next token. That token is then added to the context before the model predicts the following token.
The process can be simplified as:
Existing context↓Predict the first new token↓Append the token to the context↓Predict the second new token↓Continue the loop
The key limitation is that the target model usually needs to be called once for every generation step. Even when the hardware provides substantial parallel computing capacity, generation still contains a strong sequential dependency: the next token cannot be confirmed until the previous token has been determined.
In practice, inference time depends on more than raw compute capacity. It also includes the following overhead:
Model weight loading
Large models may need to read a substantial amount of weight data from device memory at every step. If compute units are waiting for data, theoretical peak compute does not translate directly into practical throughput.Attention cache access
Autoregressive generation continuously maintains the historical key-value cache. As the context grows, the cache consumes more memory and creates increasing read and write pressure.Scheduling and framework overhead
A single-token loop creates many fine-grained tasks involving operator scheduling, memory management, tensor construction, and result sampling.Sequential dependency
Although a single forward pass can process multiple positions in parallel, the traditional generation process generally confirms new tokens one at a time.
For this reason, improving generation speed is not only a matter of using faster hardware. It is also important to reduce the number of times the target model must be executed token by token.
2. How Speculative Decoding Works
Speculative decoding uses two model roles:
- Draft model: A smaller and faster model that predicts a sequence of candidate tokens.
- Target model: The larger model whose output must ultimately be produced and whose predictions are used to verify the draft.
A typical speculative decoding iteration contains four steps.
2.1 Generate Candidate Tokens with the Draft Model
The draft model uses the current context to predict several tokens consecutively. For example, it may generate four or eight candidate tokens in one draft sequence:
Current context → Draft model → t1, t2, t3, t4
These tokens are not final outputs. They are proposals that must be verified. A longer draft sequence can allow more tokens to be confirmed in one iteration, but it may also increase the probability of prediction errors.
2.2 Verify the Candidates in Parallel with the Target Model
The target model receives the original context together with the candidate sequence and computes prediction distributions for the relevant positions in one forward pass. Because the candidate sequence is already available, multiple positions can be verified more efficiently as a batch.
The process can be illustrated as:
Original context + t1, t2, t3, t4↓Target model verification↓Accept candidates or find a mismatch
The main benefit is that the target model no longer computes only one new token. It checks multiple candidate positions in a single verification step.
2.3 Accept or Reject Candidates in Order
Candidates are normally evaluated from left to right. If the first candidate satisfies the target model’s acceptance rule, the system continues with the second candidate. If the second also passes, it proceeds to the next position.
Once a candidate is rejected, later candidates generally cannot be used directly because they depend on the earlier prediction. The system instead uses the target model’s result at the point of disagreement and starts another speculative iteration.
For example:
Candidate sequence: t1, t2, t3, t4Verification result: pass, pass, failFinal confirmation: t1, t2, plus a token resampled by the target model
When the draft model is accurate, one target-model computation may confirm several tokens. When its predictions are poor, only a small number of tokens may be accepted, and the speedup may be negligible.
2.4 Start the Next Iteration
After the accepted tokens and any replacement token are added to the context, the draft model continues from the updated context. The process repeats until an end-of-sequence token, a length limit, or another stopping condition is reached.
3. Why Speed Can Increase from About 40 to Nearly 120 Tokens/s
The fundamental reason for the speedup is not that the computation for an individual token suddenly becomes faster. Instead, the target model confirms more tokens per invocation on average.
With traditional generation, suppose each target-model iteration confirms one token. Generating 100 tokens then requires approximately 100 target-model iterations. With speculative decoding, if each iteration confirms an average of three tokens, the same output length can theoretically be produced with far fewer target-model iterations.
A simplified performance model is:
Traditional generation time ≈Target model single-step time × number of generated tokensSpeculative generation time ≈Draft model generation time+ Target model batch verification time+ Acceptance and scheduling overhead
Overall throughput improves when the draft model is sufficiently fast, the candidate acceptance rate is high, and verifying multiple positions with the target model is more efficient than performing many separate single-step calls.
For example, in a particular environment, ordinary autoregressive generation may run at approximately 40 tokens/s. After introducing speculative decoding, cache reuse, batched verification, and scheduling optimizations, measured throughput may approach 120 tokens/s.
This result means that each target-model computation confirms more tokens on average. It does not mean that every workload will consistently achieve a threefold improvement.
Performance numbers should therefore be treated as references for a specific configuration rather than universal conclusions. Actual results depend on the model pair, hardware, quantization method, context length, output content, sampling parameters, and other factors.
4. Key Metrics That Determine Speculative Decoding Performance
4.1 Candidate Acceptance Rate
The acceptance rate is the proportion of draft-model tokens that pass target-model verification. A higher acceptance rate generally makes speculative decoding more effective.
It is affected by factors such as:
- Whether the draft and target models were trained on similar data distributions;
- Whether they use the same vocabulary and tokenization method;
- Whether the task involves code, knowledge-based question answering, translation, or open-ended generation;
- Whether temperature, random sampling, repetition penalties, and other settings are aligned;
- Whether the draft sequence is too long.
Acceptance is often more stable for structured output, formatted text, and high-probability continuations. It may vary more significantly in highly creative generation tasks.
4.2 Average Accepted Length
Acceptance rate alone is not sufficient. You should also measure how many tokens are confirmed per iteration:
Average accepted length =Total confirmed tokens ÷ Number of speculative iterations
This metric more directly reflects the effectiveness of each target-model invocation. If only one token is accepted per iteration, generating multiple draft candidates may not provide a meaningful benefit.
4.3 Draft Model Overhead
Although the draft model is smaller, it still consumes compute and memory resources. If drafting takes too long, it can offset the savings achieved by reducing target-model computation.
The desired relationship is:
Draft model cost << Cost saved by the target model
If the draft model is too large or its cache management is inefficient, the system may reduce verification time while making the drafting phase slow enough to eliminate the overall gain.
4.4 Verification Batching Efficiency
When the target model verifies multiple positions, the implementation must make effective use of parallel hardware. If the runtime still executes the positions as separate single-token tasks, speculative decoding cannot deliver its full value.
An efficient implementation should consider:
- Whether verification positions can be combined into a batched computation;
- Whether the historical cache can be reused;
- Whether candidate branches cause additional memory copies;
- Whether the target model supports efficient incremental attention;
- Whether sampling and rejection logic remain on an efficient execution path.
5. Common Engineering Optimizations
5.1 Choose an Appropriate Draft Length
A longer draft is not always better. If the draft is too short, the reduction in target-model calls may be limited. If it is too long, later candidates are more likely to be wrong, and failed verification can introduce additional overhead.
In practice, draft length can be adjusted according to the task:
- Increase the candidate length moderately for highly regular text;
- Use shorter drafts for generation with high randomness;
- Reduce the draft length automatically when acceptance declines over multiple iterations;
- Gradually increase it again when acceptance remains high for an extended period.
5.2 Keep Sampling Strategies Consistent
If the draft and target models use different temperatures, probability cutoffs, or random sampling strategies, their candidate distributions may diverge, reducing the acceptance rate.
Speculative decoding therefore requires consistent inference configuration, not just a compatible model pair. In stochastic sampling scenarios, the verification logic must correctly follow the target model’s probability distribution to preserve output correctness.
5.3 Optimize Cache Management
Speculative decoding involves caches for both the draft model and the target model. Poor handling of cache updates, rollback, and reuse can lead to excessive memory copying.
A well-designed implementation should aim to:
- Preserve the original cache before verifying candidate tokens;
- Roll back only the necessary portion when a mismatch occurs;
- Commit accepted candidates to the cache incrementally;
- Minimize unnecessary tensor concatenation;
- Control cache growth for long contexts.
5.4 Reduce Scheduling Overhead
When each speculative iteration contains only a small number of candidates, scheduling overhead can become a bottleneck. The runtime should organize drafting, verification, sampling, and acceptance checks into a compact execution path and avoid frequent synchronization between the host and the accelerator.
The following issues deserve particular attention:
- Whether data is moved between devices too frequently;
- Whether conditional logic causes device synchronization;
- Whether input tensors are reconstructed unnecessarily;
- Whether memory is repeatedly allocated during generation;
- Whether fixed-shape buffers can be reused.
6. How to Benchmark Generation Speed Correctly
A single run is not sufficient to measure tokens/s. Use consistent inputs, output lengths, and repeated trials.
A basic benchmarking procedure is:
- Fix the model and inference configuration;
- Prepare prompts with similar lengths;
- Run several warm-up iterations so that initial loading does not distort the results;
- Test both ordinary autoregressive generation and speculative decoding;
- Record time to first token, steady-state generation speed, and total latency;
- Average the results across multiple runs and report the observed variation.
Common metrics include:
Time to first token =Time required to produce the first output tokenGeneration throughput =Number of output tokens ÷ Generation-phase timeEnd-to-end speed =Number of output tokens ÷ Total elapsed time
Generation throughput is useful for evaluating continuous output performance. End-to-end speed is closer to the user’s actual experience because it includes the full request lifecycle.
For interactive applications, time to first token is especially important. Users are often more sensitive to how long it takes for a response to begin than to the exact number of tokens generated per second afterward.
7. When Speculative Decoding May Not Be Suitable
Speculative decoding does not guarantee a significant improvement for every workload. Benefits may be limited when:
- The draft and target models differ substantially;
- The output is highly random;
- The temperature is high and candidate distributions are unstable;
- The context changes frequently, limiting cache reuse;
- The runtime does not efficiently verify multiple positions;
- The draft model itself has a relatively high execution cost;
- The output is so short that generation ends before the optimization can provide meaningful savings.
Before adopting this technique, validate it with representative production data instead of relying only on a theoretical speedup multiplier.
8. Conclusion
Speculative decoding uses the fast prediction capability of a small model to reduce the number of times a large model must execute token by token. Through a draft–verify–accept–continue workflow, it transforms a highly sequential generation process into one with more batch-oriented computation.
An increase from approximately 40 tokens/s to nearly 120 tokens/s generally indicates that candidate acceptance, target-model batch verification, cache reuse, and runtime scheduling are working well together. However, this result is not universal. Real performance must be measured against the specific models, hardware, context lengths, and sampling strategies in use.
For developers, the most important goal is not to focus on a single peak throughput number. A complete evaluation should consider time to first token, steady-state throughput, average accepted length, acceptance rate, memory usage, and output consistency. Speculative decoding becomes a practical inference optimization only when correctness, stability, and speed are balanced.
