Speculative Decoding: How Draft Models Speed Up Local LLM Inference
This article explains how speculative decoding accelerates local large language model inference without changing hardware or sacrificing output quality. It covers why autoregressive decoding is bound by memory bandwidth rather than compute, how a small draft model proposes candidate tokens that the target model verifies in a single forward pass, and why the technique remains lossless under a proper sampling strategy such as rejection sampling. It also introduces average acceptance length as the key performance metric, explains the trade-off behind choosing the speculation length (gamma), and outlines practical engineering considerations including draft model selection, combining speculative decoding with quantization and continuous batching, and where the biggest gains appear. A pseudocode walkthrough makes the accept-or-reject loop concrete.
Introduction: The Same Model, Several Times Faster
Imagine two identical inference setups: the same machine, the same model weights, the same prompt. The only difference is that one side also has a small “draft model” attached. The usual outcome is that one side has already finished the entire answer while the other is still trickling out tokens one at a time. Without swapping GPUs or applying further quantization to the main model, this gap has nothing to do with hardware. It comes from a change in how tokens are generated.
The technique behind this speedup is speculative decoding (also called speculative sampling or draft-and-verify decoding). It is gradually being adopted by mainstream inference frameworks, and the draft model has become an optimization that is hard to avoid when deploying large models locally. In some tested scenarios, this combination pushes single-request generation speed to several times the baseline; even under higher concurrency, overall throughput still improves noticeably. Let’s start from the fundamentals.
1. Why LLMs Keep Loading Themselves One Token at a Time
To understand where the speedup comes from, first look at what is actually slow during inference.
A single LLM inference run typically has two phases:
- Prefill: Once the user submits a prompt, the model processes the entire input in parallel, performs the concentrated attention computation, and builds the KV Cache. This phase ingests a large number of tokens at once and is compute-intensive, mainly bounded by GPU compute throughput (for example, matrix multiplication throughput).
- Decode: Once generation begins, the model enters an autoregressive loop in which each step produces exactly one token.
The problem lies in the decode phase. To generate the next token, the hardware must: read all model weights plus the existing KV Cache → compute → write the newly produced keys and values back into the cache. Then, to generate the token after that, the whole cycle repeats.
A model’s weights can be tens or even hundreds of gigabytes, and every single token requires shuffling that data back and forth between memory and compute units. At that point, speed is no longer determined by how many compute cores the GPU has, but by memory bandwidth — how fast data can be moved. This is the “memory wall” effect: compute is plentiful, but the data cannot be fed in quickly enough, so the chip simply waits.
Because the decode phase is memory-bound rather than compute-bound, a large amount of compute capacity typically sits idle within each forward pass. That is precisely where speculative decoding finds its opportunity.
2. The Core Idea: A Small Model Proposes, the Big Model Verifies in One Pass
The reasoning behind the draft model is straightforward: hand the easy-to-predict work to a smaller, faster model, while the genuinely difficult parts that need a quality guarantee remain the call of the original large model.
A concrete example: the user inputs “The cat,” and the draft model might predict several tokens in one go, such as “sat on my lap.” Rather than regenerating these tokens one by one, the large model checks all the candidate tokens together with a single forward pass:
- If the leading tokens fall within the target model’s accepted probability distribution, they are accepted directly.
- As soon as one token at some position is rejected, all subsequent candidates are discarded, and the target model generates a corrective token at that position.
A path that might previously have required three or four autoregressive rounds now has a chance to be compressed into a single verification. The draft model is small, so producing these candidates costs far less than repeatedly reading the full weights of the large model over multiple rounds. In short: trade a small amount of draft-model compute for a large amount of redundant memory traffic in the large model.
3. Verification Is Lossless: Why Quality Doesn’t Drop
Many people worry that letting a small model “make suggestions” will degrade output quality. It won’t — provided the implementation is correct.
Speculative decoding has a key property: under a sound sampling strategy (for example, the classic speculative sampling rejection sampling scheme), the final output distribution is exactly the same as sampling token by token directly from the target model. In other words, the draft model only determines how fast the guesses are, never whether the answers are right. Whether a candidate is accepted is decided by the target model’s own probability distribution. If the draft guesses well, compute is saved; if it guesses poorly, execution falls back to the original path. Quality is always backstopped by the main model.
The following pseudocode makes one round of this loop clear:
def speculative_step(target_model, draft_model, prefix, gamma):# 1) Draft model autoregressively generates gamma candidate tokens and their probabilitiesdraft_tokens, draft_probs = [], []ctx = prefixfor _ in range(gamma):prob = draft_model.next_token_probs(ctx)tok = sample(prob)draft_tokens.append(tok)draft_probs.append(prob[tok])ctx = ctx + [tok]# 2) Target model verifies in parallel: one forward pass yields probabilities for all positionstarget_logits = target_model.forward(prefix + draft_tokens)# 3) Accept or reject left to right, one position at a timeaccepted = 0for i in range(gamma):p = prob_softmax(target_logits[i])q = draft_probs[i]r = min(1.0, p[draft_tokens[i]] / q) # acceptance probabilityif random() < r:accepted += 1else:break# 4) If all tokens are accepted, add one extra token; otherwise resample at the rejected position# Then emit the accepted tokens together with the corrective tokenreturn accept_and_resample(target_logits, accepted, draft_tokens)
In this code, the genuinely expensive target-model forward pass happens only once, yet it verifies up to gamma positions. Compute is better utilized, memory traffic is amortized, and speed naturally improves.
3.1 Average Acceptance Length: The Metric That Decides the Payoff
Speculative decoding may look like a free lunch, but what actually determines the size of the gain is a metric called average acceptance length — how many draft tokens the target model accepts on average per round.
- If the draft proposes 4 tokens and 3 are accepted, one large-model computation advances generation by several positions at once, and the speedup is substantial.
- If the draft guesses wrong frequently, the target model must keep rejecting and correcting. Not only are no costs saved, but the extra compute for the draft model and the verification overhead are added on top, so the benefit is heavily diluted — and in some cases throughput can even get worse.
The speedup ratio of speculative decoding therefore depends heavily on how well the draft model and target model are aligned: the closer the two are in style and the better their domains match, the higher the draft hit rate, the longer the average acceptance length, and the more pronounced the final speedup.
4. Longer Drafts Don’t Automatically Mean Faster: The Speculation Length Trade-off
A common intuitive mistake is to assume that since guessing more earns more, writing a longer draft (increasing gamma) must be better. It isn’t. There is a “sweet spot” that requires balancing.
- Speculation length too short: each round advances only a few positions, and verification overhead is repeatedly amortized over a handful of tokens, so the acceleration potential goes unused.
- Speculation length too long: hit rates at later draft positions typically drop (errors accumulate and the context becomes more uncertain), so a large number of candidates are rejected and thrown away. Both the draft model’s generation cost and the verification cost rise, and overall performance can actually get slower.
Average acceptance length does not grow linearly with draft length; there is a point of diminishing marginal returns. In engineering practice, the right draft length usually has to be found empirically for the specific model and task rather than simply maximized. That is why writing a longer draft does not necessarily make things faster.
5. Key Engineering Considerations
To actually put speculative decoding to use, a few things need to be handled at the system design level:
- Choosing the draft model: the draft model should ideally come from the same family as the target model, share the same vocabulary, or be alignment-trained, and its size is typically a fraction of the target model’s — often one to two orders of magnitude smaller. Hit rates are higher when the domains are closely related (both code, or both Chinese conversation, for instance).
- Combining with quantization and batching: speculative decoding addresses the memory-bandwidth bottleneck in the decode phase, while techniques such as quantizing weights and continuous batching optimize from different angles. A sensible combination can amplify the gains further, but watch out for the draft model’s own memory and compute overhead eating into the main benefit.
- Where it applies: the gains are usually most visible in single-request, low-concurrency, latency-sensitive scenarios (local interactive question answering, intelligent code completion, for example). It is especially worthwhile at low concurrency when the task is highly aligned with the draft model. Conversely, gains shrink noticeably when batching has already saturated compute, or when the draft and target models are badly mismatched.
- Observability and tuning: in production, keep monitoring metrics such as average acceptance length, generation latency, throughput, and memory usage, and use them to dynamically adjust draft length and draft model choice. Such capabilities can be carried by general-purpose infrastructure such as elastic compute, model inference services, and monitoring and alerting, forming a closed loop of “load test — observe — tune.”
Conclusion
The value of speculative decoding is that it does not touch the model itself; it redesigns how tokens get generated. A small, fast draft model fills the compute gap left by the target model during decoding, turning generation that was bound by memory bandwidth into efficient progress of “verify many positions in one pass.” For developers, this means local inference experiences can improve by multiples without changing hardware and without sacrificing output quality. Understanding the trade-off between average acceptance length and speculation length, and picking the right draft model, is what makes this free lunch genuinely worth eating.
