Speculative Decoding in Practice: Accelerating Large Model Inference Across Multiple GPUs
This article explains how speculative decoding accelerates autoregressive inference by using a fast draft model and a target model for parallel verification. It covers acceptance probability, entropy, draft-model cost, concurrency, context length, dynamic candidate trees, KV-cache consistency, and key deployment considerations for an eight-GPU tensor-parallel setup.
1. Background: Why Autoregressive Decoding Is Slow
Large language models typically generate tokens one at a time. Each new token requires a complete forward pass, along with access to all model parameters and the historical KV cache. At larger parameter scales, this process is primarily limited by GPU memory bandwidth, while much of the GPU’s compute capacity remains underutilized. As a result, even capable hardware may deliver relatively low single-request generation speed, and user wait time increases roughly linearly with the response length.
As models evolve, training, data generation, and online inference form a continuous feedback loop. Inference performance is no longer an isolated metric: it interacts with resource scheduling, data management, and numerical consistency. Engineering teams must reproduce benchmark performance in real operating environments and identify bottlenecks across the model, runtime, software, and hardware layers. This is essential for turning model capabilities into a stable production service.
2. How Speculative Decoding Works
Speculative decoding divides generation into two roles:
- Draft model: A smaller and faster model that proposes k consecutive candidate tokens.
- Target model: The model ultimately used for serving, which evaluates the k candidates in a single batch and verifies them sequentially.
For each candidate position, the system accepts the token with probability:
[
\min(1, p{\text{target}} / p{\text{draft}})
]
If a token is rejected, the system resamples one from the corrected distribution, and all subsequent candidates in that draft are discarded. This design preserves the same output distribution as direct sampling from the target model. In other words, acceleration does not change the statistical characteristics of generation quality.
Let α represent the average acceptance rate of draft tokens, and let γ represent the draft length for each round. The average number of tokens produced per target-model invocation is:
[
\frac{1-\alpha^{(\gamma+1)}}{1-\alpha}
]
When α approaches 1, a single round can produce nearly γ + 1 tokens. In practice, the final speedup must also account for draft-generation latency and additional memory consumption, so the actual benefit must be measured under realistic workloads.
3. Four Factors That Affect Acceleration
1. Acceptance Rate and Text Entropy
The acceptance rate is the key variable determining the performance benefit. When text entropy is low, the next-token distribution is more concentrated, making it easier for the draft model to predict correctly.
Structured output, code completion, templated reports, and summaries of highly repetitive long documents are typically low-entropy scenarios. By contrast, creative writing and open-ended question answering have higher entropy, which can significantly reduce the acceptance rate.
2. Draft-Model Cost
The draft model must be sufficiently fast; otherwise, the draft-generation phase will consume most of the potential gain. The draft and target models must use the same vocabulary so that tokens can be compared individually. The closer their training distributions are, the higher the acceptance rate will generally be.
3. Concurrency
At low concurrency, the target model performs relatively little computation during each verification step, and memory access is the primary bottleneck. Speculative decoding can therefore provide a more visible benefit.
As concurrency increases, the existing batch may already fully utilize the compute units. Additional candidate tokens then compete for compute capacity, and the speedup decreases. For high-concurrency workloads, total throughput should be treated as the primary metric rather than single-request latency.
4. Context Length
Long contexts increase the amount of KV-cache data that must be read. At context lengths around 32K tokens, attention computation places substantial pressure on memory access, while parallel candidate verification also requires additional cache capacity.
Evaluation should use separate tests for fixed context lengths. Results from short-context workloads should not be directly applied to long-context scenarios.
4. Dynamic Path Selection and Candidate Organization
A fixed-length linear draft can perform inconsistently when the acceptance rate fluctuates. A common approach is to generate a candidate tree during the draft phase, branching into multiple candidate paths at key positions. The target model verifies the entire tree in one operation, and the system selects the longest accepted branch.
The number and depth of paths can be adjusted dynamically according to the recent acceptance rate. When the acceptance rate is high, the system can increase the depth. When it is low, the tree can be reduced. This helps balance verification cost against the number of tokens produced.
The main challenge is keeping the scheduling logic stable. Path switching must not break KV-cache consistency. After each acceptance decision, the system must correctly roll back the cache state of rejected branches.
The following pseudocode illustrates the control flow:
def speculative_step(target, draft, context, recent_acceptance_rate):depth = choose_depth(recent_acceptance_rate) # Adjust depth based on the recent acceptance ratecandidates = draft.propose(context, depth) # Generate candidate sequences with the draft modeltarget_probs = target.score(context, candidates) # Score candidates in parallel with the target modelaccepted = []for token, p_t, p_d in zip(candidates, target_probs, draft.probs):if random() < min(1.0, p_t / p_d):accepted.append(token)else:accepted.append(sample_correction(p_t, p_d)) # Resample from the corrected distributionbreakupdate_kv_cache(context, accepted) # Retain only the accepted portionreturn context + accepted
5. Deployment Considerations
For a deployment using eight identical GPUs with eight-way tensor parallelism, the following aspects require attention:
- Memory budget: Account for the target-model weights, the draft model, and the additional memory required for candidate verification and KV-cache management.
