Speculative Decoding for LLM Inference: Engineering Practices and Real-World Throughput Gains
Speculative decoding (also known as draft-and-verify decoding) is one of the most effective techniques for accelerating large language model inference without sacrificing output quality. This article explains why autoregressive decoding is memory-bound, how speculative decoding converts idle GPU compute into real throughput, what factors determine the achievable speedup, and which engineering optimizations are needed to turn theory into measurable results—such as lifting decode speed from roughly 40 to nearly 120 tokens/s on a single GPU serving a 27B-class model.
Speculative Decoding for LLM Inference: Engineering Practices and Real-World Throughput Gains
Start with a Familiar Question: Is Your Inference Speed Good Enough?
When deploying LLMs in the tens-of-billions parameter range on local or private hardware, “how many tokens per second can we generate” is usually the first metric developers look at. Take a consumer or entry-level professional GPU running a 27B-class model as an example: without any optimization, decode speed typically lands around 30–50 tokens/s. That’s tolerable for offline batch processing, but in interactive scenarios like chat or code completion, the latency is noticeable.
Is there a way to double or even triple throughput without degrading generation quality? Yes. One of the most mature and widely adopted approaches is speculative decoding (also called speculative sampling or draft-and-verify decoding). Engineering teams have combined this technique with a series of supporting optimizations to push decode speed from about 40 tokens/s to nearly 120 tokens/s. This article breaks down how the technique works, the key implementation details, and the optimizations that make it effective in production.
Why Autoregressive Decoding Is Slow
To appreciate the value of speculative decoding, you first need to understand where the bottleneck is. LLM generation is autoregressive: for every token produced, the model runs a full forward pass over all previous tokens’ context (usually held as a KV cache), outputs the next token’s probability distribution, samples a result, and starts the next round.
A key hardware characteristic comes into play here: the decode phase is a classic memory-bound workload. Generating each token requires reading the entire set of model weights from GPU memory, while the actual matrix computation is tiny—only one token is processed at a time, leaving compute units largely idle. In other words, GPU compute capacity is severely underutilized during decoding.
This leads to a simple but powerful idea: since a single forward pass takes roughly the same time regardless of input length (within a small batch range), why not “compute multiple tokens at once” and amortize the memory bandwidth cost? Speculative decoding is built exactly on this insight.
How Speculative Decoding Works: Draft First, Verify Later
A Recall-Then-Verify Structure, Much Like a Search Engine
Speculative decoding resembles a search engine’s architecture and consists of two stages:
Stage 1: Draft generation. A small auxiliary model (the draft model) autoregressively generates n candidate tokens at very low cost. Because the draft model is small and its forward passes are fast, generating these n tokens takes far less time than a single forward pass of the target model. The candidates may be wrong, but the odds of “guessing right” are surprisingly good—much of natural language is patterned and low-entropy, which small models handle well.
Stage 2: Parallel verification. The n candidate tokens are appended to the current context, and the target model performs a single forward pass that computes probability distributions for all n+1 positions simultaneously. Verification then proceeds from the front: each draft token is accepted if it matches the target model’s own sampling result at that position. At the first mismatch, the token and all subsequent draft tokens are rejected; the target model’s own output is used at that position, and a new draft-verify cycle begins from there.
In the worst case, all n draft tokens are rejected—but you still get one correctly generated token from the target model, so nothing is lost. In the best case, all n drafts are accepted, producing n+1 tokens from a single forward pass. The expected speedup depends on the draft acceptance rate.
Losslessness in Theory
A common concern: does “guessing” with a small model alter the target model’s original output distribution? It does not. Standard speculative decoding uses a rejection-sampling correction: a draft token is accepted with probability min(1, p_target(x) / p_draft(x)); on rejection, a replacement token is sampled from the normalized residual distribution norm(max(0, p_target - p_draft)). It can be proven that the resulting output distribution is exactly identical to plain autoregressive sampling with the target model. The speedup is therefore “lossless”—this is what distinguishes speculative decoding from approximation techniques such as distillation or quantization.
What Determines the Speedup
Acceptance Rate Is Everything
The overall speedup is roughly proportional to the average number of draft tokens accepted per round. The acceptance rate depends on:
- Distribution alignment between draft and target models: When the two models come from the same family (e.g., different sizes in the same series), they share a tokenizer and stylistic tendencies, and acceptance rates are significantly higher. Mismatched tokenizers make candidate token sequences impossible to align directly and should be avoided in practice.
- Draft length n: Too small, and the amortization benefit is limited; too large, and the acceptance probability of later draft tokens decays exponentially while verification cost grows. In practice, n is usually set to 3–8, often with an adaptive strategy.
- Task type: Low-entropy tasks such as code generation, templated text, and structured output can reach acceptance rates of 70%–90%; open-ended creative writing and complex reasoning see noticeably lower rates.
- Sampling temperature: Lower temperatures sharpen the distribution and increase draft hit rates; with greedy decoding, tokens can even be compared exactly.
The Cost of the Draft Model
Smaller isn’t always better. A draft model that’s too small accepts too few tokens; one that’s too large spends too long generating drafts. As a rule of thumb, a draft model with 1/10 to 1/50 of the target model’s parameters is a reasonable range. Another option is the “self-drafting” approach: use the target model’s early layers, optionally with a small prediction head, to produce drafts, avoiding the need to maintain two separate models.
Verification Overhead
Verification lengthens the input sequence, increasing attention computation and KV cache reads and writes. With large n or high concurrency, verification can shift from memory-bound to compute-bound, yielding diminishing returns. Tuning n therefore requires real measurements on your actual hardware.
Supporting Engineering Optimizations
Turning a theoretical speedup into a measured 40 → 120 tokens/s takes more than the algorithm alone. Several engineering optimizations typically work together:
- Efficient KV cache management: When drafts are rejected, the cache entries for rejected tokens must be rolled back. Implementations should avoid frequent memory allocations and copies; paged memory management schemes work well here.
- Operator fusion and graph optimization: The draft model’s multi-step small computations incur heavy kernel launch overhead. Operator fusion and graph capture can substantially cut the fixed cost of the drafting phase.
- Compatibility with batching: Under high concurrency, batching already saturates compute, and speculative decoding’s marginal benefit shrinks. You need to balance the two dynamically based on workload characteristics, potentially switching strategies at different concurrency levels.
- Combining quantization with speculative decoding: Weight-quantizing the target model further reduces bandwidth pressure and is orthogonal to speculative decoding; stacking the two often yields nearly multiplicative speedups. Be aware, though, that quantization-induced precision loss can indirectly lower the acceptance rate.
- Adaptive draft length: Adjust n online based on historical acceptance rates—shortening drafts in high-entropy passages and extending them in low-entropy ones is an effective way to squeeze out the last bit of performance.
How to Benchmark and Evaluate
For developers who want to reproduce this kind of speedup in their own environments, a practical evaluation process looks like this:
- Fix a representative set of test prompts (covering chat, code, and long-form generation) and compare end-to-end tokens/s with speculative decoding on and off, using identical sampling parameters;
- Track three metrics—average draft tokens accepted per round, the draft phase’s share of total time, and the verification phase’s share—to locate bottlenecks;
- Grid-search over n, draft model size, and temperature to find the optimum for your hardware and workload;
- Re-test under realistic concurrent load to confirm that fallback strategies behave correctly under high load.
Conclusion
Speculative decoding converts the compute idling during decode into real throughput through its elegant draft-then-verify structure, while mathematically guaranteeing an unchanged output distribution. It is one of the highest-ROI techniques in the current LLM inference optimization toolbox. The jump from 40 tokens/s to 120 tokens/s doesn’t come from any single trick—it comes from the systematic interplay of algorithm choice and engineering detail. For teams focused on inference efficiency, deeply understanding the technique and tuning it for your own workload is far more valuable than chasing any specific number. When deploying inference services on cloud platforms, it’s also worth pairing them with standard container platforms and monitoring/alerting capabilities to build a continuous performance observability system, so optimization gains remain measurable and reproducible.
