Speculative Decoding: How to Accelerate LLM Inference by Up to 3x
This article examines the memory-bandwidth bottleneck in autoregressive LLM decoding and explains how speculative decoding uses a low-cost draft stage plus parallel verification to increase the number of tokens produced per forward pass without changing the final output distribution. It reviews key engineering trade-offs such as draft model cost, draft length, acceptance rate, batch size, and tokenizer/sampling consistency, and it discusses benchmarking methodology and complementary optimizations including KV cache reuse, quantization, continuous batching, and paged attention.
Speculative Decoding: How to Accelerate LLM Inference by Up to 3x
1. A Common Question: How Fast Can a Large Model Actually Run?
In many developer communities, a familiar question comes up: “What is the inference speed of a model with tens of billions of parameters on your hardware in tokens/s?” This seemingly simple question involves model size, memory bandwidth, batching strategy, quantization precision, decoding algorithms, and other dimensions.
Consider a common high-end single-GPU environment. For a dense model with close to 30B parameters, in an autoregressive decoding scenario with batch size 1, pure forward computation often reaches only 30–50 tokens/s. The reason is straightforward: every generated token requires moving hundreds of billions of parameters from memory to the compute units once. The compute units are largely idle, and the bottleneck is memory bandwidth—a state known as memory-bandwidth bound.
Is there a way to break this bottleneck? Yes. One of the most elegant and effective approaches is speculative decoding. In practice, this technique can raise decoding speed from about 40 tokens/s to nearly 120 tokens/s, delivering close to 3x acceleration while keeping the generated results exactly consistent with the original model and causing no accuracy loss. The following sections break down the technique from principles to engineering details.
2. Why Autoregressive Decoding Is So Slow
The standard autoregressive decoding process is serial:
Step 1: input prompt → forward pass → get token_1Step 2: input prompt + token_1 → forward pass → get token_2Step 3: input prompt + token_1 + token_2 → forward pass → get token_3……
Each generated token requires a full forward pass. For large models, the time of a single forward pass is mainly determined by parameter reading time:
time per token ≈ total bytes of model parameters / effective memory bandwidth
For example, a 27B-parameter model stored in FP16 takes about 54GB. If effective memory bandwidth is 2TB/s, the theoretical lower bound per token is about 27ms, corresponding to about 37 tokens/s—which closely matches the measured 40 tokens/s.
The key insight is this: since the bottleneck is moving parameters, if each forward pass can produce multiple tokens at once, the bandwidth cost is amortized and speed can increase substantially. Speculative decoding does exactly this.
3. Core Principle: Drafting + Parallel Verification
The idea behind speculative decoding is similar to the “recall—rerank” architecture in search engines: a very low-cost module quickly produces candidates, and an authoritative module confirms them in batches.
The process has two stages:
Stage 1: Draft stage. A very small draft model—typically only 1/20 or even 1/50 the size of the large model, or a model-free approach such as n-gram or retrieval-based drafting—autoregressively guesses the next n tokens. Because the draft model is tiny, this step costs almost nothing.
Stage 2: Verify stage. The n candidate tokens are concatenated into the input at once, and the large model performs a single parallel forward pass, producing its own probability distributions at those n positions, that is, outputs for n+1 positions. Then the candidates are checked one by one:
- If the large model accepts the draft token at a position according to the acceptance criterion, checking continues to the next position.
- Once the first rejected position is found, all subsequent draft tokens are discarded, and a correct token is resampled from the large model’s distribution at that position.
Mathematically, as long as the acceptance criterion is designed correctly—for example, using the classic speculative sampling rejection sampling formula—the final output sequence has exactly the same probability distribution as direct token-by-token decoding with the large model. This is lossless acceleration.
In the worst case, all n draft tokens are rejected, but at least one token generated by the large model itself is still produced, so there is no net loss of “a wasted round.” In the best case, one forward pass confirms n+1 tokens. When draft quality is high, each large-model forward pass can confirm 2–4 tokens on average, raising overall throughput from 40 tokens/s to 100+ tokens/s.
4. Key Engineering Factors Affecting Speedup
Whether a 3x speedup can be achieved in practice depends on a series of careful engineering trade-offs:
1. Draft model choice and cost. The draft model must be small enough; otherwise, the drafting overhead consumes the gains. Common approaches include training a small-parameter model with the same vocabulary, reusing some layers of the large model with a small prediction head (self-speculative decoding), or using retrieval-based drafts from historical context. The single-forward time of the draft model should generally be kept within 5% of that of the large model.
2. Trade-off in draft length n. If n is too small, verification parallelism is insufficient. If n is too large, the acceptance probability of later tokens drops exponentially, wasting compute. In practice, n is often set to 4–8, and more advanced implementations dynamically adjust n based on recent acceptance rates.
3. Acceptance rate is the core metric. Acceptance rate depends on how closely the draft model’s distribution matches that of the large model. In highly patterned scenarios such as code generation and formatted output, acceptance rates can exceed 80%, producing excellent speedups. In open-ended creative scenarios, acceptance rates may be only around 50%, reducing the benefit accordingly.
4. Impact of batch size. The benefit of speculative decoding is closely related to batch size. When the batch is large, the large model’s forward pass has already shifted from memory-bandwidth bound to compute-bound. In this case, the extra computation from parallel verification competes for throughput, and the benefit of speculative decoding shrinks or even becomes negative. It is therefore best suited to low-concurrency, low-latency scenarios such as single-user chat and local assistants.
5. Consistency of vocabulary and sampling parameters. The draft model and the large model must share the same vocabulary, and sampling parameters such as temperature and top-p must be incorporated into the acceptance criterion; otherwise, losslessness is broken.
5. How to Benchmark Inference Speed Scientifically
Returning to the question “What tokens/s are you getting?”, it is advisable to standardize the measurement methodology before giving meaningful numbers:
- Specify the hardware model, memory capacity, and quantization precision (FP16 / INT8 / INT4).
- Specify batch size, input length, and output length.
- Distinguish time to first token (TTFT) from steady-state decode speed (the inverse of time per output token, TPOT).
- Report the average over multiple runs and note whether acceleration methods such as speculative decoding are enabled.
An illustrative test script outline is as follows:
import timedef measure_decode_speed(generate_fn, prompt, max_tokens=256, repeat=5):speeds = []for _ in range(repeat):start = time.perf_counter()output, n_tokens = generate_fn(prompt, max_tokens=max_tokens)elapsed = time.perf_counter() - startspeeds.append(n_tokens / elapsed)return sum(speeds) / len(speeds)
Only when the methodology is consistent can speed data from different developers be compared.
6. Other Optimizations That Can Stack with Speculative Decoding
Speculative decoding is not an isolated optimization. It is often combined with the following techniques to further improve inference performance:
- KV cache reuse: avoids recomputing attention for historical tokens and is standard in inference frameworks.
- Quantized inference: compresses weights to INT8 or INT4, directly reducing bandwidth requirements and multiplying the effect of speculative decoding.
- Continuous batching: dynamically schedules requests under high concurrency to improve overall throughput.
- Paged attention-style memory management: reduces memory fragmentation and supports larger batches.
In cloud deployment scenarios, general container platforms, monitoring and alerting, and logging services can also be combined to continuously observe latency, throughput, and GPU utilization of inference services and to enable elastic scaling, balancing cost and user experience.
7. Conclusion
Discussions about large-model inference speed are essentially a trade-off among memory bandwidth, parallelism, and algorithm design. Speculative decoding uses a clever design—a small model drafts, and a large model verifies in parallel—to increase the output of a single forward pass from one token to multiple tokens without sacrificing any generation quality. It enables a leap from about 40 tokens/s to nearly 120 tokens/s. Understanding its principles, acceptance rate, and engineering trade-offs, together with quantization, batching, and other methods, is essential for answering the question “How fast can your model run?” and for building efficient, stable LLM inference services.
