Speculative Decoding for LLMs: A Practical Guide to Faster Inference

    This article explains how speculative decoding accelerates large language model inference by replacing token-by-token generation with a draft-and-verify pipeline. It covers why autoregressive decoding is slow, how draft models and parallel verification work, how dynamic draft length selection balances cost and acceptance, and why single-request latency and multi-request throughput must be measured separately. It also outlines how to package the approach into a reusable platform capability and how to troubleshoot performance layer by layer in real environments.

    1. The Starting Point: Why Autoregressive Decoding Needs to Be Reworked

    LLM inference has two phases: prefill and decode. Prefill can make full use of parallel compute, but decode is constrained by its inherently serial, token-by-token generation. Every token requires a complete forward pass, and the memory access and scheduling overhead cannot be amortized. When the context grows to around 32k tokens, the memory pressure from attention is amplified further. At low concurrency, compute utilization often stays low, and users experience “fast first token, slow afterward.”

    So the core of inference optimization is not pushing single-GPU compute to the limit, but changing the scheduling paradigm of “one token at a time.” Speculative decoding is a representative approach along these lines.

    2. How It Works: Draft Generation and Parallel Verification

    Speculative decoding splits decoding into two roles:

    • Draft model: lightweight and low-latency, responsible for proposing several candidate tokens in a row.
    • Target model: large and high-precision, responsible for verifying the candidate sequence with a single parallel forward pass.

    The key to the verification phase is the word “parallel.” Instead of advancing token by token, the target model concatenates the candidate segment into one sequence and runs a single forward pass, then compares the probability distribution at each position to decide whether to accept, truncate, or roll back. Because one forward pass can confirm multiple tokens, the end-to-end number of steps drops significantly, while the output distribution remains consistent with the target model’s own decoding. This is the premise that makes the technique widely adoptable.

    The flow can be abstracted as:

    1. # Pseudocode: main loop of speculative decoding
    2. draft_tokens = draft_model.propose(prefix, k=4) # Draft: propose k tokens in a row
    3. accepted = target_model.verify(prefix, draft_tokens) # Target: verify in one parallel pass
    4. prefix = prefix + accepted
    5. if len(accepted) < k:
    6. prefix = prefix + target_model.sample_next(prefix) # On rollback, add one token

    What really determines the gain in engineering practice is the acceptance rate: the more accurate the draft, the more tokens each verification confirms on average. But if the draft model is too heavy, its own latency eats into the gain. The balance point between the two is the entire difficulty of draft model design.

    3. Dynamic Path Selection: Let the Draft Be as Long as It Should Be

    A fixed-length draft strategy is not cost-effective under real workloads. For high-entropy, reasoning-heavy segments, a long draft is almost certain to be rejected, wasting draft compute; for templated, low-entropy segments, a short draft wastes verification opportunities. Dynamic path selection lets the draft phase adaptively adjust the speculation length and branching based on the uncertainty of the current context: extend the draft chain in low-entropy regions, converge quickly to a short draft in high-entropy regions, or even fall back to ordinary decoding. This makes an online trade-off between “draft cost” and “acceptance gain.”

    From an engineering perspective, this brings three direct benefits:

    1. More stable tail latency: high-entropy segments no longer incur wasted draft overhead, and jitter on long-tail requests converges.
    2. Lower compute cost: fewer wasted forward passes in the draft phase, and more effective tokens produced per unit of power.
    3. Easier reuse: the strategy is externalized as configuration, so it can be switched without changing the target model weights.

    4. Performance: Measure Single-Request Latency and Concurrent Throughput Separately

    The most common misjudgment in inference optimization is summarizing all gains with a single metric. In practice, at least two sets of numbers matter:

    • Single-request decode speed: measures interactive experience. With the target model, 8 accelerator cards, a tensor parallelism degree of 8, and a typical 32k low-entropy context, the draft-plus-parallel-verification approach can raise single-request decode speed to around 288 tokens/s, roughly 3.4x native autoregressive decoding.
    • Aggregate throughput at concurrency: measures resource efficiency. Under the same configuration at 64 concurrent requests, total throughput is around 608 tokens/s, about 45% higher than the native approach.

    The difference between the two sets of numbers reveals the mechanism. At low concurrency, the bottleneck is memory access and serial waiting, so speculative decoding delivers the largest gain. At high concurrency, the system is already near compute saturation, and the gain comes mainly from less wasted scheduling and a higher share of effective computation, so the improvement shrinks but remains substantial. Capacity planning must make clear whether the goal is “preserve latency” or “preserve throughput,” since the two correspond to different concurrency limits and draft length settings.

    5. Turning It into a Reusable Solution: From Script to Platform Capability

    An inference optimization that succeeds once is still missing the “reusable” step before it is production-ready. It is best to consolidate the solution into three layers:

    • Configuration layer: parameters such as draft length, dynamic thresholds, parallelism, and context length are externalized and delivered according to business profiles.
    • Runtime layer: decoupled from the container platform and model serving framework, with the draft model and target model scaling independently so they do not drag each other down.
    • Observability layer: integrated with logging and monitoring/alerting to collect metrics such as acceptance rate, draft time share, tokens confirmed per step, and queueing latency, forming a baseline for continuous regression.

    In cloud environments such as Baidu AI Cloud, these capabilities typically map to general categories: a container platform handles elastic scaling, object storage keeps model and configuration versions, and monitoring/alerting handles baselines and anomaly detection, turning a one-off tuning into an engineering asset that can be canaried and rolled back.

    6. Locating Bottlenecks Layer by Layer: Making Performance Reproducible in Real Environments

    After a new model goes live, “paper performance that cannot be reproduced” is common, and the root cause is often not the model itself. The recommended approach is to troubleshoot in four layers:

    1. Model layer: tokenizer consistency between draft and target, numerical precision, and weight version.
    2. Runtime layer: batching strategy, memory fragmentation, and whether parallel communication has become a serialization point.
    3. Software layer: scheduling queues, request batching windows, and timeout and retry policies.
    4. Hardware layer: inter-card interconnect bandwidth, thermal throttling, and slow nodes caused by single-card failures.

    Only with a fixed evaluation set and fixed concurrency gradients for regression can “occasionally faster” become “stably deliverable.”

    7. Conclusion

    The value of speculative decoding lies not in any isolated number, but in reshaping decoding from serial waiting into a schedulable “draft-verify” pipeline. Dynamic path selection gives this pipeline adaptive capability, and the configuration-driven, observable, rollback-capable engineering wrapper is what makes the gains actually land in production. For developers, mastering this approach means mastering a general way to keep extracting inference performance across continuously evolving models and hardware.