Speeding Up Local LLM Inference Without Upgrading GPUs: Speculative Decoding
The speed bottleneck in Large Language Model (LLM) inference often lies not in GPU compute power, but in the token generation process itself. This article explains how Speculative Decoding accelerates generation without modifying hardware or compressing the model. It covers the memory bandwidth bottleneck during token-by-token generation, the core mechanism of Speculative Decoding using draft and target models, how to evaluate the speedup, and practical steps for local deployment.
1. The Problem: Memory Bandwidth Bottleneck in Token-by-Token Generation
LLM inference is typically divided into two phases.
- Prefill Phase: The model reads the user’s prompt in one go, computes attention in parallel, and builds the KV Cache. This phase processes a large number of tokens, and performance is primarily limited by compute capacity.
- Decode Phase: The model generates output tokens one by one. For every token generated, it must read all model weights and the existing KV Cache, perform the computation, and write the new key-value pair back to the cache. This process repeats for the next token.
The bottleneck in the decode phase is memory bandwidth. A large model’s weights can occupy tens of gigabytes of VRAM. Every time a token is generated, this data must be transferred from VRAM to the compute units. Since the computation required is relatively small compared to the data transfer, the GPU’s compute power often sits idle. Consequently, memory bandwidth dictates how many tokens can be generated per second.
This explains a common phenomenon: upgrading to a more powerful GPU does not necessarily yield a noticeable improvement in single-request generation speed. Reducing the amount of data transferred per token, or reducing the number of full forward passes required, brings direct benefits. Speculative Decoding tackles the problem from the latter direction.
2. The Basic Concept of Speculative Decoding
Speculative Decoding splits the generation process into two roles:
- Draft Model: A small, fast model responsible for predicting multiple candidate tokens at once.
- Target Model: The final quality arbiter, responsible for verifying the candidate tokens.
The workflow is as follows:
- The draft model continuously generates $k$ candidate tokens based on the current context.
- The target model concatenates the context with these $k$ candidates and performs a single forward pass to obtain the probability distribution for each position.
- The candidates are checked sequentially from left to right. Tokens that match the target model’s distribution are accepted. If a token is rejected, it and all subsequent candidates are discarded, and the target model samples a corrected token at that position.
- If all $k$ candidates are accepted, the target model can provide an additional token at the final position.
Taking “The cat” as an example. The draft model might predict “sat on my lap”. The target model evaluates these positions in a single forward pass. If “sat” and “on” are accepted but “my” is rejected, this round yields three confirmed tokens (two accepted candidates plus one corrected token), while the target model only performed a single full forward pass. Without Speculative Decoding, generating the same three tokens would require three full forward passes.
The key to this mechanism is correctness. When using Rejection Sampling rules, the acceptance and correction probabilities are designed to ensure that the final output distribution matches that of generating tokens one-by-one using only the target model. The draft model only affects speed, not output quality. The draft’s quality determines “guessing accuracy,” while the verification step ensures the result is “correct.”
Below is simplified illustrative code, omitting engineering details like batching and KV Cache reuse:
def speculative_step(target, draft, prefix, k):# 1. Draft model autoregressively generates k candidate tokens and records their probabilities qcandidates, q_probs = draft.generate(prefix, k)# 2. Target model performs one forward pass to get probabilities p for k+1 positionsp_probs = target.forward(prefix + candidates)output = []for i, tok in enumerate(candidates):accept_prob = min(1.0, p_probs[i][tok] / q_probs[i][tok])if random.random() < accept_prob:output.append(tok)else:# Rejected: sample a corrected token from the normalized residual distribution max(0, p - q)output.append(sample_residual(p_probs[i], q_probs[i]))return prefix + output# All accepted: target model samples an extra token at the last positionoutput.append(sample(p_probs[k]))return prefix + output
3. How to Measure Acceleration Performance
The gains from Speculative Decoding depend on two variables. The first is the acceptance rate, $\alpha$, which is the probability that a single candidate token is accepted by the target model. The second is the draft cost ratio, $c$, which is the time ratio of the draft model generating one token to the target model performing one forward pass.
Given a draft length of $k$, the average number of tokens produced per round is:
$E = (1 - \alpha^{(k+1)}) / (1 - \alpha)$
The time per round is approximately $(1 + k \cdot c)$ times that of a single target model forward pass. Thus, the theoretical speedup ratio is:
Speedup Ratio $\approx E / (1 + k \cdot c)$
$E$ can be viewed as a theoretical estimate of the average acceptance length, equaling the average number of accepted draft tokens per round plus the one token provided by the target model.
The table below uses $c = 0.1$ and $k = 4$ to compare results across different acceptance rates:
| Acceptance Rate $\alpha$ | Avg. Tokens Produced Per Round | Theoretical Speedup |
|---|---|---|
| 0.5 | 1.94 | 1.38 |
| 0.7 | 2.77 | 1.98 |
| 0.9 | 4.10 | 2.93 |
These values are derived from formula estimates and are ideal cases, not accounting for additional overhead in verification and sampling; actual speedup is usually slightly lower. Increasing the acceptance rate from 0.5 to 0.9 roughly doubles the speedup, indicating that a draft model that “guesses accurately” is the core driver of performance gains.
The near 4x speedup for single requests mentioned in literature and public demos usually requires both a high acceptance rate and low draft cost. Specific numbers depend on the model combination, task type, and hardware environment, and should not be directly applied to other scenarios.
4. More Draft Tokens Do Not Always Mean Faster Speeds
Increasing $k$ introduces two competing effects. While the maximum number of tokens that can be accepted in a single pass increases, the total cost of the draft model also rises. Furthermore, later candidates are more likely to be rejected, causing the acceptance rate to drop.
Taking $\alpha = 0.7$ and $c = 0.1$ as an example:
| Draft Length $k$ | Avg. Tokens Produced Per Round | Theoretical Speedup |
|---|---|---|
| 2 | 2.19 | 1.83 |
| 3 | 2.53 | 1.95 |
| 4 | 2.77 | 1.98 |
| 5 | 2.94 | 1.96 |
| 6 | 3.06 | 1.91 |
| 8 | 3.20 | 1.78 |
Under these assumptions, $k = 4$ is optimal; increasing $k$ further actually reduces the gains. The optimal $k$ is task-dependent: scenarios with high acceptance rates can utilize a larger $k$, while those with low acceptance rates should use a smaller $k$. In practice, parameters should be selected through testing rather than defaulting to a large value.
5. Practical Factors Affecting Acceptance Rate
- Model Alignment: The draft model and target model must use the same vocabulary and tokenization method, otherwise tokens cannot be aligned. Combinations of models from the same family but different sizes typically achieve higher acceptance rates. If the draft model’s data distribution closely matches the target model’s, their divergence will also be reduced.
- Task Type: Code completion, structured data, templated text, and repetitive paragraphs are highly predictable and yield high acceptance rates. Open-ended creative writing and brainstorming requiring diversity result in lower acceptance rates.
- Sampling Parameters: Higher temperatures lead to more dispersed probability distributions, widening the gap between draft and target distributions and lowering the acceptance rate. If the business requires deterministic output, greedy decoding offers simpler verification rules and more stable acceptance rates.
- Concurrency Scale: As concurrency increases, batching improves compute unit utilization, which may decrease the single-request speedup ratio, though overall throughput may still improve. For high-concurrency services, evaluate performance using both throughput and tail latency.
6. Implementation Steps for Local Deployment
- Check Compatibility: Confirm that the draft and target models share the same vocabulary and that your inference environment supports Speculative Decoding options. Refer to the official documentation of your specific tool for exact configuration names.
- Estimate VRAM: The draft model’s weights and its own KV Cache will consume additional VRAM. If VRAM is tight, choose a smaller draft model or reduce the maximum context length.
- Measure Acceptance Rate: Run representative samples from actual business use cases and count the number of accepted draft tokens per round to determine the average acceptance length. Illustrative code:
def measure_avg_accepted(run_speculative, samples):accepted_total, rounds_total = 0, 0for prompt in samples:stats = run_speculative(prompt) # Returns a list of accepted draft token counts per roundaccepted_total += sum(stats)rounds_total += len(stats)return accepted_total / rounds_total
- Tune and Compare: Under different $k$ values and sampling temperatures, measure single-request latency, overall throughput, and output quality respectively. Select the combination that offers the highest gains while meeting business requirements.
- Monitor in Production: Continuously log acceptance rates and latency in the production environment. Acceptance rates may drop if the load or business content changes, requiring timely parameter adjustments.
If the inference service is deployed in the cloud, you can use container platforms for resource orchestration, employ monitoring and alerting to track latency and throughput metrics, and configure auto-scaling based on load. These are standard operational practices and operate independently of Speculative Decoding itself.
7. Applicability and Boundaries
Speculative Decoding is well-suited for the following scenarios: large target models, latency-sensitive single requests, memory bandwidth bottlenecks, and cases where the draft model can be well-matched with the target model.
Scenarios with limited benefits include: large-batch offline tasks (where compute units are already near saturation), extremely low VRAM availability, significant divergence between draft and target models, and highly random output tasks.
Conclusion: The core of Speculative Decoding is using a small model to handle prediction and a large model to centralize verification. While ensuring the output distribution remains unchanged, it transforms token-by-token memory access overhead into a single computation with multiple verifications. Understanding the trade-off between acceptance rate and draft cost is key to determining whether it can deliver tangible benefits in local or private deployments.
