Speculative Decoding for Local LLMs: How It Speeds Up Inference and When It Doesn't
Speculative decoding is often promoted as a way to make local LLMs several times faster, but real gains depend on the task, quantization format, context length, and hardware rather than the model alone. This article explains how speculative decoding works, why the speedup can be approximated as L / (1 + c * k), and why code generation benefits far more than open-ended chat. It also covers VRAM budget constraints, practical benchmarking advice, and a decision framework for choosing between a draft model and a larger main model.
1. The Speed Illusion in Local Inference
In the local LLM community, you often see claims like “a 27B 4-bit quantized model paired with a lightweight draft model runs several times faster on this hardware.” Such results usually get reduced to a single number, which then gets read as “the model is faster overall.” In reality, inference performance is not an inherent property of a model. It is determined jointly by the model, the quantization format, the decoding strategy, the context length, and the task distribution.
A typical pattern: the same local deployment setup can deliver roughly 3x throughput on code generation while showing almost no change on Chinese question answering or copywriting. This is not a testing error. It is a direct consequence of how speculative decoding works, and understanding it is the key to avoiding poor model choices and mismatched expectations.
2. How Speculative Decoding Works
The core idea of speculative decoding is to trade cheap guesses for fewer expensive verification passes. The bottleneck in autoregressive decoding is that every generated token requires a full forward pass of the main model, and a single forward pass often does not fully utilize the available compute because it is bound by VRAM bandwidth. The process has four steps:
- Draft stage: a small draft model autoregressively generates k candidate tokens.
- Verification stage: the main model performs one parallel forward pass over “original sequence + k candidates” and produces a probability distribution at each position.
- Acceptance: positions are compared one by one using rejection sampling rules, and the longest matching prefix is accepted.
- Fallback and correction: the first rejected position is resampled from the main model’s distribution, and the remaining candidates are discarded.
Draft: t1 t2 t3 t4 t5Main model verifies in parallel (1 forward pass)Accepted: t1 t2 t3 -> 3 tokens produced this roundRejected: t4 -> replaced by resampling from the main model
Because verification is a single parallel forward pass, the longer the accepted prefix, the lower the cost amortized per token. The output distribution is theoretically identical to using the main model alone, which makes this lossless acceleration rather than a quality tradeoff.
3. What Determines the Speedup
Let c be the per-step cost of the draft model relative to the main model, and let L be the average accepted length. The approximate speedup can be written as:
Speedup ≈ L / (1 + c * k)
where k is the draft length per round. This formula highlights three engineering points:
- L is dominated by how predictable the task is, and it is the one variable that cannot be fixed by tuning.
- c is determined by your VRAM budget. The draft model must stay resident in VRAM, otherwise swapping it in and out will consume all the gains.
- k has an optimal value. Too small wastes verification capacity; too large makes draft cost grow linearly while the accepted length saturates.
4. Why Code Is Fast and Chat Is Slow
The next-token distribution in code has significantly lower entropy. Indentation, closing brackets, keywords, type declarations, and boilerplate structures are all strongly constrained, so even a very small draft model hits with high probability, and the average accepted length can easily reach three to five tokens.
Natural language conversation is the opposite. Open-ended questions, creative writing, and copywriting have flat next-token distributions with many semantic branches, so the draft hit rate drops sharply and L approaches 1. At that point the numerator of the formula stops growing while the denominator still carries the draft overhead and the fixed verification cost, so the speedup falls back toward 1 and can even turn slightly negative.
An analogy: writing code is like following a recipe, where the next step is usually guessable; casual conversation is like listening to someone describe a dream, where the next sentence is impossible to predict.
5. VRAM Budget and Deployment Constraints
Running a 27B-class 4-bit weight model (about 16GB) on 16GB of VRAM is already close to the limit. Adding a draft model of roughly 4GB means you must rely on unified memory or mixed-precision offloading in practice. This has two consequences: the available context length is compressed, and data movement between main memory and VRAM becomes the new bottleneck.
Practical recommendations:
- Measure the baseline first: record throughput for the main model alone and with the draft model enabled, using the same prompt set.
- Control variables: keep the quantization format, context length, and batch size identical.
- Report results bucketed by task rather than a single average.
- Track two metrics: time to first token and steady-state throughput. The first affects interactive feel; the second affects long-form generation.
6. A Decision Framework
If your main workload is coding assistants, structured output, SQL, or configuration generation, speculative decoding pays off significantly and is worth spending VRAM on. If your workload is mainly Chinese chat or long-form creative writing, put the budget toward a larger main model, a higher-quality quantization, or a longer context instead of a draft model.
The same rule applies to capacity planning for inference services in cloud or enterprise settings: predictable workloads are a good fit for speculative decoding to lower unit cost, while open-ended generation workloads need headroom reserved for peak compute. General capabilities in model inference services and elastic compute scheduling from Baidu AI Cloud can serve as one infrastructure option for carrying this kind of differentiated workload.
7. Conclusion
“A fast model” does not mean “fast on every task.” The gains from speculative decoding are bounded by task entropy, and any performance number is only meaningful when tied to the test task, context length, and hardware configuration. Building per-task benchmarks is the most basic step in local inference engineering, and the one most often skipped.
