Speculative Decoding: How Draft Models Speed Up Local LLM Inference
Speculative decoding uses a small, fast draft model to propose candidate tokens that a larger target model then verifies in a single forward pass. This lets local LLM inference advance several positions per step while producing exactly the same output distribution as the target model alone. This article explains why decoding is fundamentally memory-bandwidth bound, how the draft-and-verify loop works, why rejection sampling preserves output quality, why the average acceptance length is the metric that really matters, how to choose a good draft model, and the practical tradeoffs around batching, memory, and KV cache management.
Why LLMs “Load Themselves” One Token at a Time
A single large-model inference can usually be split into two phases: prefill and decode.
- Prefill phase: After the user submits a prompt, the model processes the entire input in parallel, computes attention relationships, and writes them into the KV cache. This phase processes a large number of tokens at once. It is compute-intensive and is mainly limited by the GPU’s raw compute.
- Decode phase: Once generation begins, the model falls back to sequential mode and can only produce the next token at a time.
The problem lies precisely in the decode phase. To generate each new token, the GPU must read the entire set of model weights, along with the existing KV cache, in full from memory. Once the computation finishes, it writes the newly generated key-value pairs back into the cache, then repeats the whole routine for the next token.
This means that for a model whose weights run into tens or even hundreds of gigabytes, generating a single token requires moving a complete dataset between memory and the compute units. What determines speed here is often no longer how many compute cores the GPU has, but rather memory bandwidth and data-transfer efficiency. The decode phase is essentially a memory-bandwidth-bound process: the compute units sit idle while the data is stuck in transfer. This is the root cause of why a large model “pushes out one character at a time” during local inference.
The Idea Behind the Draft Model: Guess First, Verify Later
The core insight of speculative decoding is to outsource the easily predictable parts of the decode phase to a smaller, faster model.
Suppose the input prompt is “The cat.” A very small draft model can predict a candidate fragment such as “sat on my lap” in a row. After that, the large target model only needs to run a single forward pass over these candidate tokens to verify, all at once, whether they are “acceptable.”
- If the first few tokens match the target model’s probability distribution, the entire prefix is accepted directly;
- As soon as it hits the first token that does not match, that token and every candidate after it are discarded, and the target model resamples one token to fill the gap from a corrected distribution.
In this way, work that previously required the target model to run three or four rounds of sequential decoding can now, with a chance, be compressed into a single verification step. The draft model may be small, but the cost of generating candidates is far lower than the cost of the target model repeatedly reading its full set of weights, and the speedup comes from exactly this difference.
Below is a schematic of the core flow to help illustrate the division of labor between the steps:
# Speculative decoding core flow (illustrative, not a specific implementation)def speculative_decode(target, draft, prompt, gamma=4):# Prefill: process the prompt once and build the KV cachestate = target.prefill(prompt)output = []while not done(output):# 1) Draft model proposes gamma candidate tokens in a rowdrafts, draft_probs = draft.propose(state, gamma)# 2) Target model runs "one" forward pass over the candidates to get per-position probabilitiestarget_probs, new_state = target.forward(drafts, state)# 3) Verify token by token: accept the matching prefix, correct at the first mismatchaccepted = 0for i, tok in enumerate(drafts):r = uniform(0, 1)if r < min(1.0, target_probs[i][tok] / draft_probs[i][tok]):output.append(tok) # accept this draft tokenaccepted += 1else:# Sample from the residual distribution max(0, p_target - p_draft), normalizedoutput.append(sample_residual(target_probs[i], draft_probs[i]))break# 4) If all drafts are accepted, sample one extra "free" token from the target distributionif accepted == gamma:output.append(sample(target_probs[gamma]))state = new_statereturn output
The Verification Mechanism: Why Output Quality Never Drops
Here is the most elegant part of speculative decoding: it does not change the quality of the output; it changes the path taken to reach the same result.
Strictly speaking, the verification stage uses rejection sampling:
- For each draft token, decide whether to accept it with probability
min(1, p_target / p_draft); - If it is rejected, sample a replacement token from the residual distribution
max(0, p_target − p_draft)after normalization.
It can be rigorously proven that, after this accept/correct logic, the distribution of the tokens produced is exactly identical to running the target model directly. In other words, only the “how we get there” is accelerated, not “where we arrive.” This is the rigorous meaning of the statement that “output quality is still guarded by the same model”—no matter how poor the draft model is, a wrong guess is simply rejected and never pollutes the final answer.
More Drafts Do Not Always Mean More Speed
Speculative decoding may look like a “free lunch,” but the metric that actually determines success or failure is the average acceptance length—the average number of draft tokens the target model accepts per round.
- If the draft model guesses 4 tokens at a time and 3 of them are accepted, a single large-model computation advances several positions, giving a significant speedup;
- If the draft model guesses wrong frequently, the target model can only keep rejecting and correcting. On top of the computation itself, it also has to bear the extra overhead of generating the drafts, so the net gain can even be negative.
So the key is not how long the draft is, but how accurate it is. Generating too many tokens in one draft (enlarging the draft window) causes the marginal acceptance rate to drop sharply and can slow things down overall; a draft window that is too small, on the other hand, struggles to amortize the cost of a single target-model forward pass. In practice, you need to strike a balance between “draft length” and “acceptance rate.”
How to Choose a Good Draft
The choice of draft model directly determines the acceptance rate. There are usually three approaches:
- An independent small model: Use a small-parameter model with the same vocabulary, domain, and style as the draft writer. The closer the two models’ training data and distributions, the higher the acceptance rate; if they differ too much, the acceptance rate will be very low.
- A built-in multi-token prediction head: Some model architectures train lightweight prediction modules on top of the existing weights, avoiding the overhead of maintaining a second model separately.
- Lookup-based / self-drafting strategies: Use N-gram frequencies or the model’s own shallow-layer structure to generate candidates, requiring no additional model, which suits scenarios where no suitable small model is available.
Beyond the draft model itself, sampling parameters such as temperature and top-p also significantly affect the acceptance rate: the more “deterministic” the sampling (lower temperature, more greedy), the more likely the drafts are to be endorsed by the target model, and the higher the speedup ratio; high-temperature, exploratory sampling, by contrast, lowers the acceptance rate.
Practical Considerations
- Batching and concurrency: Speculative decoding gives a clear speedup for a single request, but under high concurrency the extra draft forward passes consume compute, so the throughput improvement is usually smaller than for a single request and must be evaluated against the actual workload.
- Memory and bandwidth: The draft model itself also occupies memory; when memory on a single card is tight, you must weigh “loading one more small model” against “leaving room for the KV cache.”
- KV cache management: During verification, draft tokens are briefly written into the cache and must be correctly rolled back when rejected. An incorrect cache state will pollute subsequent generation, so implementation must be handled with extra care.
- Mainstream framework support: Today many mainstream inference frameworks and local inference engines already have speculative decoding built in. When using it, prefer their proven implementations over writing your own sampling and rollback logic from scratch.
Suitable Scenarios and Boundaries
Speculative decoding does not change the model, does not swap the hardware, and does not sacrifice quality—it only reorganizes how tokens are generated. It is therefore especially well suited to local single-card deployments, interactive dialogue, and latency-sensitive scenarios such as code completion. Its boundaries are equally clear: if the draft model is severely mismatched to the task distribution, or the workload is dominated by high-concurrency throughput, the speedup gains will shrink noticeably.
In summary, speculative decoding offers a pragmatic path: under the decode bottleneck imposed by limited memory bandwidth, it uses a lightweight draft model to “scout ahead” so that the expensive large model can “make the final call in one concentrated pass,” trading an almost zero quality cost for a several-fold speedup in local inference. Understanding the average acceptance length, draft selection, and cache rollback are the prerequisites for putting this technique to good use.
