Accelerating LLM Inference Without Upgrading GPUs: How Speculative Decoding and Draft Models Work
Large Language Model (LLM) inference is frequently bottlenecked by memory bandwidth limitations during the decoding phase. Speculative decoding offers an alternative to expensive GPU upgrades by utilizing a smaller, faster draft model to predict tokens, which are subsequently verified by a larger target model. This article explores the core mechanics of speculative decoding, key metrics such as average accept length, draft model selection, deployment considerations, and ideal application scenarios to help developers optimize LLM inference performance.
1. Why LLM Generation Is Slow
A single LLM inference process is typically divided into two stages. The first stage is Prefill. When a user inputs a prompt, the model processes the entire content at once, computes attention, and builds the KV Cache. This stage is highly parallel and primarily consumes compute resources.
The second stage is Decode. Once the model starts outputting the response, it generates only one token at a time. To generate the next token, the compute device must read all model weights and the existing KV Cache, and after generation, write the new key-value data back to the cache. This entire process repeats before the next token appears.
This creates a significant bottleneck. Model weights often reach tens of gigabytes, and moving this data from VRAM to compute units for every single generated token means compute units spend most of their time waiting for data. The actual time spent on matrix multiplication is very low. Consequently, the speed of the decoding stage is primarily limited by memory bandwidth and data transfer efficiency, rather than the number of compute units. Upgrading to faster GPUs can improve speed, but the cost is high. An alternative approach is to reduce the number of times the large model needs to run a full step for every single token. Speculative decoding is designed precisely along this line of thinking.
2. The Basic Concept of Speculative Decoding
The core of speculative decoding is the division of labor. The system utilizes two models:
- Target model: The final arbiter of output quality; it is large and slow.
- Draft model: Small and fast, responsible for guessing upcoming tokens in advance.
The entire process consists of three steps:
- Draft: The draft model generates k candidate tokens sequentially based on the current context.
- Verify: The target model appends these k candidates to the context and performs a single forward pass to obtain the probability distribution for each position.
- Accept or Reject: Candidates are checked one by one starting from the first. If the target model approves a candidate, it is accepted. Once a rejected position is encountered, it and all subsequent candidates are discarded, and the target model samples a corrected token for that position.
For example, if a user inputs “The cat”, the draft model might predict “sat on my lap”. If the first two tokens match the target model’s probability distribution, they are accepted directly. If the third token is rejected, all subsequent candidates are discarded, and the target model provides a corrected token at that position. In this round, the target model was only called once, yet the process advanced by three positions. Without speculative decoding, achieving the same progress would require the target model to run three or four separate rounds.
The key to this method is that acceptance and rejection are based on probability comparisons rather than simple character matching. Classic rejection sampling ensures that the final output’s probability distribution is consistent with what the target model would produce independently. Therefore, acceleration is achieved without sacrificing output quality.
3. Key Metric: Average Accept Length
The benefit of speculative decoding is measured by the average accept length, which is the average number of draft tokens accepted by the target model per verification round. This metric is more important than simply looking at the speed of the draft model.
A simplified model can estimate the theoretical gain. Assuming each draft token has the same probability of being accepted, denoted as α, and the draft length is γ, the average number of tokens produced per verification round is:
(1 − α^(γ+1)) / (1 − α)
Calculating with γ=4, the results are as follows (the following are illustrative values derived from the formula, not empirical data):
| Single Token Accept Probability (α) | Average Tokens Produced Per Round |
|---|---|
| 0.4 | ~1.65 |
| 0.6 | ~2.31 |
| 0.8 | ~3.36 |
It is evident that when the accept probability is low, the gains from speculative decoding are quite limited. When the accept probability is high, a single verification round can advance significantly more positions.
The overhead of the draft model itself must also be considered. The draft model runs γ times per round. If it is not fast enough, the computational savings on the target model will be offset. To determine if it is worth enabling, one should simultaneously consider the accept length, draft execution time, and the single forward pass time of the target model.
In public demonstrations, some tests have shown single-request generation speeds reaching nearly 4x the original speed, with throughput still improving by about 2x under concurrent requests. These figures depend on specific model combinations and load conditions and should not be directly applied to other scenarios.
4. Draft Model Selection and Parameter Tuning
When selecting a draft model, keep the following points in mind:
- Vocabulary and Architecture Compatibility: The draft model and the target model must use the same vocabulary; otherwise, token probabilities cannot be compared token by token.
- Same-Lineage Training Aids Acceptance: Smaller models from the same series or distilled from similar data have closer output styles, typically resulting in higher acceptance rates.
- Balancing Size and Speed: A smaller draft model generates drafts faster, but its predictive capability is weaker, which may lower the acceptance rate.
The draft length γ also needs tuning. If γ is too small, the positions advanced per round are limited, making the acceleration effect unnoticeable. If γ is too large, the probability of later candidates being rejected increases, wasting more draft computation. A common practice is to start with a smaller value, measure the accept length on real business requests, and gradually increase it.
Task type greatly impacts the acceptance rate. In scenarios like code completion, structured output with fixed formats, and templated text, the draft model can easily guess correctly, leading to a high acceptance rate. In open-ended creative writing or high-randomness conversational scenarios, the probability of the draft model guessing wrong is higher, reducing the benefits. Sampling parameters also affect the acceptance rate; higher temperatures lead to more random outputs, widening the distribution gap between the draft and target models and lowering the acceptance rate.
5. Deployment Considerations
First, VRAM must accommodate the draft model’s weights and its own KV Cache. On devices where VRAM is already near its limit, enabling speculative decoding may force a reduction in batch size, offsetting some of the gains.
Second, benefits diminish as concurrency increases. As concurrent requests rise, the utilization of compute units improves, and the bottleneck gradually shifts from bandwidth limitation to computation. At this point, the verification stage processes more candidates, increasing the proportion of additional computation. Therefore, in high-concurrency services, the throughput improvement is typically smaller than in single-request scenarios.
Third, monitoring should cover the following metrics:
- Average accept length: Determines the match degree between the draft model and the target model.
- Time to first token (TTFT): Ensures the prefill stage is not noticeably slowed down by the additional model.
- Tokens per second: Measures overall throughput.
- Peak VRAM usage: Prevents out-of-memory errors caused by the new model.
Fourth, if the accept length remains persistently low, check whether the draft model matches the target model before adjusting γ or sampling parameters. Blindly increasing the scale of the draft model usually does not solve the problem.
6. Pseudocode Example
The pseudocode below illustrates the execution flow of a single round of speculative decoding. It omits details like stop token handling, batching, and cache reuse, and is intended only for understanding the logic; it cannot be run directly.
def speculative_generate(target, draft, prompt, gamma=4, max_new_tokens=256):tokens = list(prompt)budget = len(prompt) + max_new_tokenswhile len(tokens) < budget:# 1. Draft model sequentially generates gamma candidate tokenscandidates = [] # Each item is (candidate token, draft distribution)ctx = list(tokens)for _ in range(gamma):q = draft.next_token_probs(ctx)x = sample(q)candidates.append((x, q))ctx.append(x)# 2. Target model performs one forward pass, returning probability distributions for gamma+1 positionsp_list = target.next_token_probs_batch(tokens, [x for x, _ in candidates])# 3. Verify one by one: accept candidate with probability min(1, p/q)accepted = []all_accepted = Truefor i, (x, q) in enumerate(candidates):p = p_list[i]if random() < min(1.0, p[x] / q[x]):accepted.append(x)else:# Rejected: sample a corrected token from the normalized max(0, p - q)accepted.append(sample_residual(p, q))all_accepted = Falsebreak# If all accepted, the target model provides an extra tokenif all_accepted:accepted.append(sample(p_list[gamma]))tokens.extend(accepted)return tokens
Two points to note in the code. First, the verification stage only calls the target model once, which is the source of the acceleration. Second, whether accepted or rejected, each round produces at least one new token, ensuring the process never stalls.
7. Evaluating Applicable Scenarios
Speculative decoding is suitable for the following situations:
- Single-user or low-concurrency scenarios, such as local assistants or personal coding aids.
- High predictability in output, such as code, tables, or fixed-format text.
- Available VRAM headroom to accommodate the draft model.
The benefits are limited, requiring careful evaluation, in the following situations:
- High-concurrency services where VRAM is already near saturation.
- High-temperature sampling or open-ended generation where drafts are easily rejected.
- Lack of an available small model with a matching vocabulary.
To decide whether to enable it, it is recommended to run a set of baseline tests with real business data first, recording the accept length, latency, and throughput, before making a launch decision. Do not base the decision solely on promotional figures from a single scenario.
