Speculative Decoding for LLM Inference: How It Achieves Nearly 3x Throughput Gains
This article explains why autoregressive LLM inference is limited by memory bandwidth and how speculative decoding works: a small draft model proposes several tokens, and the target model verifies them in one forward pass. It covers the engineering details needed for deployment, including KV cache rollback, rejection sampling, adaptive draft length, and batching trade-offs, and identifies the workloads that benefit most.
1. Why LLM Inference Is Naturally Slow
Many discussions about large language model applications eventually raise the same question: how many tokens per second can your model generate? One reported measurement shows an open-source model of roughly 27 billion parameters reaching about 40 tokens/s under a conventional deployment. With a carefully designed optimization scheme, the same setup reached nearly 120 tokens/s. The technique behind this gain is speculative decoding, which applies an idea similar to the recall and re-ranking stages of search engines. This article covers its principles, engineering implementation, and tuning practice.
To understand the acceleration method, we first need to identify the bottleneck. Mainstream large language models generate text autoregressively. For each token, the model runs one full forward pass over the sequence generated so far, predicts the next token, appends it to the input, and repeats.
Generating N tokens therefore requires N sequential full forward passes. Each pass reads all model weights from GPU memory, while the arithmetic itself takes relatively little time. This is a typical memory-bound workload: much of the GPU’s compute sits idle while time goes to moving weights.
Put differently, if one forward pass could produce several tokens, the cost of reading the weights would be spread across all of them. This is where speculative decoding starts.
2. The Core Idea: Guess First, Then Verify
Speculative decoding resembles the recall-and-ranking pattern in information retrieval. It has two steps.
Step 1: Draft. A much smaller model, called the draft model, has very low inference cost. It guesses n candidate tokens in a row. Because the small model is fast, this step takes little time. However, the draft model is less capable, so some of its tokens may be wrong.
Step 2: Verify. The n candidate tokens are concatenated into one sequence and passed to the target model in a single forward pass. Because the Transformer processes positions in parallel, the target model produces predicted distributions for n+1 positions in one pass. The system then compares the draft and target predictions from the beginning. If the target model’s prediction at a position matches the draft token, the token is accepted and the next position is checked. When a mismatch occurs, the target model’s prediction replaces the draft token at that position. All draft tokens after it are discarded, and the next round of drafting starts from the mismatch point.
The key insight is that verifying n tokens costs about the same as generating one token, since both take one forward pass. As long as the draft hit rate is high, a single pass can produce several tokens net. When the sampling scheme is designed correctly, speculative decoding produces output distributions that are theoretically equivalent to those of the target model generating token by token. The speedup does not sacrifice output quality.
3. Why Throughput Can Rise from 40 to 120 tokens/s
Suppose the draft model correctly guesses k tokens per round on average. Then each forward pass of the target model yields k+1 tokens on average. When k stays around 2 to 3, overall throughput rises to nearly 3x. The measured increase from 40 to nearly 120 tokens/s matches this theoretical expectation.
The gain depends mainly on three factors:
- Alignment between the draft and target models. Both models must share exactly the same vocabulary. The closer the draft model’s output distribution is to the target’s, the higher the acceptance rate. In practice, a smaller variant from the same model family is often used as the draft model.
- Choice of draft length n. If n is too short, the benefit of parallel verification cannot be fully realized. If n is too long, more of the draft is discarded and wasted. A value between 4 and 8 is commonly suitable, and n can be adjusted dynamically based on recent acceptance rates.
- Overhead of the draft model. A smaller draft model yields a larger relative gain in the verification stage. However, a draft model that is too small will have a lower acceptance rate, so the team must balance speed against accuracy.
4. Key Engineering Details
1. Keeping the KV Cache Consistent
Speculative decoding alternates between two models, so KV cache management is a key engineering challenge. When draft tokens are partially rejected, the target model’s KV cache entries for the discarded positions must be rolled back precisely. Otherwise, stale data remains in the cache. A common implementation pattern looks like this (illustrative pseudocode):
while not finished:draft_tokens = draft_model.generate(context, n=N)logits = target_model.forward(context + draft_tokens)accepted = verify(draft_tokens, logits)context.extend(accepted)rollback_kv_cache(target_model, keep_len=len(context))
2. Matching the Sampling Strategy
The verification stage cannot rely on simple greedy comparison in general. The industry-standard approach is speculative rejection sampling. Each draft token is accepted with a probability based on the ratio of the two models’ distributions. When a token is rejected, a replacement is resampled from the corrected residual distribution. This guarantees that the output distribution matches direct sampling from the target model. For pure greedy decoding, the process reduces to a simple token-by-token comparison.
3. Adaptive Draft Length
A fixed n is not optimal. At runtime, the system can track the average accepted length over the most recent rounds and adjust n accordingly. It lengthens the draft when acceptance is high and shortens it when acceptance is low, which avoids wasted computation.
4. Interaction with Batching
Speculative decoding delivers the largest gains in interactive, low-concurrency, single-request scenarios such as chat. In high-concurrency batch inference, GPU compute is already saturated, so the gains shrink. In those cases, teams should evaluate whether to enable it alongside general optimizations such as continuous batching, quantization, and paged KV cache memory management.
5. Use Cases and Deployment Recommendations
Speculative decoding is particularly suitable for the following scenarios:
- Low-latency interactive applications, such as intelligent Q&A and code completion, where per-user generation speed matters.
- Memory-bandwidth-limited deployments, where the speedup depends on the hardware’s ratio of memory bandwidth to compute.
- Tasks with predictable output, such as formatted output and code generation, where draft acceptance rates are naturally higher.
Before adopting the technique, measure the draft acceptance rate and end-to-end speedup on an offline evaluation set. After confirming the gains, route production traffic to the system. Keep monitoring the latency distribution through logging and alerting to catch long-tail issues.
6. Summary
Speculative decoding uses a small model to draft and a large model to verify. It turns the serial bottleneck of autoregressive generation into parallel verification, delivering a several-fold inference speedup without quality loss. It reflects a simple but important principle in LLM systems optimization: instead of having an expensive model handle every step, let a cheaper model do the routine work first, then have the stronger model check the result. For teams struggling with inference speed, this is an optimization path worth trying first.
