A Practical Guide to Accelerating LLM Inference with Speculative Decoding
Speculative decoding speeds up large language model inference by pairing a lightweight draft model with parallel verification from the target model, converting serial token-by-token generation into batched candidate confirmation. This guide explains the core draft-and-verify mechanism, dynamic draft-path selection, key engineering considerations for deployment, representative performance numbers, and best practices for putting speculative decoding into production.
Why LLM Inference Needs Speculative Decoding
As large language models enter a stage of continuous iteration, training and inference form a closed loop through data generation, environment feedback, and parameter updates. Inference performance directly determines whether compute capacity can be converted into usable throughput.
The essence of autoregressive decoding is serial, token-by-token generation: producing each token requires a full forward pass, and each new token must wait for the previous one. This serial dependency means that in single-concurrency, low-entropy contexts, the decoding phase is often bottlenecked by memory access and scheduling overhead rather than raw compute, leaving hardware utilization well below capacity.
The key insight is that the decoding bottleneck is not insufficient compute—it is that “every step is spent waiting.” To speed things up, you must break the strict serialization and decouple generation from verification. Speculative decoding exists precisely for this purpose.
Core Mechanism: Draft Generation + Parallel Verification
Speculative decoding relies on two cooperating roles:
- Draft model: A smaller, faster model that “guesses” the next several candidate tokens.
- Target model: The actual large model, which verifies the draft’s candidate sequence in parallel in a single pass, confirming which tokens are acceptable and where recomputation must begin.
The benefit is intuitive: the draft phase uses low-cost compute to produce candidates, and the verification phase compresses N tokens—which would otherwise require N serial forward passes—into one parallel forward pass. As long as the draft’s hit rate is high enough, a single target-model forward pass can “release” multiple tokens, cutting the per-token waiting time.
Illustrative pseudocode:
def speculative_decode(target, draft, context, gamma=5):output = []while not done:# 1. The draft model proposes gamma candidate tokens in a rowdraft_tokens = draft.propose(context, num=gamma)# 2. The target model runs one parallel forward pass to get per-position distributionstarget_logits = target.forward(context + draft_tokens)# 3. Verify position by position, accepting the longest verifiable prefixaccepted = verify(draft_tokens, target_logits)output.extend(accepted)context = context + accepted# 4. If a token was rejected, the target model resamples one token as a fallbackif len(accepted) < gamma:context = context + [target.resample()]return output
It is important to emphasize that speculative decoding is lossless acceleration: the verification mechanism guarantees that the final output distribution is identical to the target model’s native autoregressive decoding. The draft model only affects “how accurately the model guesses,” not “whether the result is correct.”
Dynamic Path Selection: Making Drafts Smarter
Draft quality determines the upper bound of the achievable speedup. Fixed-length, fixed-strategy drafting suffers a noticeable drop in hit rate on complex contexts. The core idea of dynamic path selection is to adaptively decide “how many tokens to guess and how to guess them” based on the current context’s uncertainty—drafting aggressively in low-entropy (highly predictable) segments and shortening drafts in high-entropy segments to avoid wasted verification overhead.
In practice, three aspects matter most:
- Adaptive draft length: Use confidence or distribution entropy as a signal to dynamically adjust the number of candidates per round.
- Candidate pruning: Keep only high-probability paths to reduce unnecessary computation during target-model verification.
- Reusable packaging: Wrap dynamic path selection into a reusable inference solution so business teams can adopt it without modifying the model itself.
Engineering Deployment: Resources, Parallelism, and Consistency
Speculative decoding is not an isolated algorithm; it must coordinate with the runtime, parallelism strategy, and hardware:
- Parallel configuration: Under multi-GPU tensor parallelism (e.g., TP=8), you need to weigh whether the draft model shares memory with the target model or runs separately. The draft model should stay lightweight to avoid competing with the target model for parallel resources.
- Resource scheduling: Drafting and verification alternate in execution, so the scheduler should minimize bubbles between phase switches, keeping accelerators highly utilized during verification.
- Computational consistency: The verification phase must strictly align with the target model’s numerical path, ensuring losslessness is not broken by the parallel implementation.
- Observability: Use monitoring, alerting, and logging services to pinpoint bottlenecks layer by layer—across the model, runtime, software stack, and hardware. This is a prerequisite for reproducing verified performance.
Performance Snapshot (Illustrative)
In a configuration with one target LLM on a single 8-accelerator node with tensor parallelism set to 8, under a 32k low-entropy context at single concurrency, speculative decoding achieved a decoding speed of roughly 288 tokens/s—about 3.41× native autoregressive decoding. At 64 concurrent requests, total throughput reached about 608 tokens/s, roughly 44.9% higher than the native approach.
These results point to a clear pattern: the speedup is highest in low-entropy, single-concurrency scenarios, where draft hit rates are high and serial waiting is fully eliminated. As concurrency rises, parallel computation in the verification phase gradually saturates, and throughput gains converge—though they remain positive. Speculative decoding is therefore best suited to online inference workloads that are low-concurrency, long-context, and strongly predictable, while high-concurrency batch scenarios should be evaluated holistically alongside scheduling strategy.
Summary and Best Practices
By rewriting serial decoding into parallel candidate confirmation via “draft generation + verification,” and further raising hit rates with dynamic path selection, speculative decoding is an effective way to increase LLM inference speed and reduce per-token latency. When deploying it, we recommend:
- Piloting first on single-concurrency, low-entropy, long-context pipelines;
- Choosing a lightweight draft model with adaptive draft length;
- Ensuring numerical consistency in the verification phase to preserve losslessness;
- Using monitoring and logging to locate bottlenecks layer by layer, closing the loop of “training → inference → feedback.”
With support from general-purpose inference and containerization capabilities on platforms such as Baidu AI Cloud—including container services, monitoring and alerting, and logging—these optimization techniques can be deployed, observed, and iterated more smoothly, helping teams convert raw compute into measurable throughput gains.
