Speculative Decoding for Faster LLM Inference: Open-Source Practice and an 85% Speedup

    This article explains how speculative decoding speeds up large language model inference and what it takes to run it in production. It covers why autoregressive decoding bottlenecks on memory bandwidth and KV Cache reads, the three main draft-model approaches and how to choose between them using accepted length versus draft overhead, the four capabilities a training and evaluation framework needs, and the key engineering details before launch, including dynamic draft length, batch scheduling, KV Cache management, numerical consistency, and observability. It closes with practical guidance for deploying on the cloud. Reported results include roughly 50% higher throughput and latency improvements above 80% in specific scenarios.

    1. Why LLM Inference Needs Speculative Decoding

    Autoregressive generation in large models is inherently sequential at the token level: for every new token, the entire existing context must pass through a forward pass again. This creates a typical resource mismatch—memory bandwidth and KV Cache reads become the bottleneck, while compute units sit largely idle. The smaller the batch size and the longer the context, the more pronounced this waste becomes.

    The core idea of speculative decoding is to “draft first, verify later”: a lightweight draft model proposes several candidate tokens in one shot, and the target LLM then performs a single parallel forward pass to verify whether those candidates are acceptable. Because verification is parallel, one target model call can confirm multiple tokens. This increases the average output per forward pass by several times while mathematically preserving the output distribution.

    A recently open-sourced inference acceleration solution and its companion training framework, from a cloud vendor, delivered roughly 50% higher throughput in production, with latency improvements exceeding 80% in specific scenarios. These results are not magic; they come from stacking three things together: a high-acceptance-rate draft model, an efficient verification kernel, and sensible batch scheduling. Setting aside the specific product, this article discusses the general technical path behind it.

    2. Three Main Approaches to Speculative Decoding

    In engineering practice, draft sources generally fall into three categories, each with trade-offs:

    • Standalone small model: Train a draft model with far fewer parameters than the target model. It is general-purpose and simple to implement, but faces two-tokenizer and distribution-alignment issues, and its acceptance-rate ceiling is lower.
    • Feature-level autoregression: Use the target model’s intermediate hidden states as input to build a lightweight autoregressive head that predicts subsequent features step by step. It naturally shares the representation space with the target model, usually achieving a higher acceptance rate. A representative idea is the common multi-layer feature draft structure.
    • Parallel multi-step prediction: Predict draft tokens at multiple positions in a single forward pass (tree-structured or chain-structured), reducing serial draft overhead to a constant and being friendlier to hardware utilization. However, it requires an additional training objective to enforce multi-step consistency.

    The key selection metric is not “how fast the draft model is,” but the ratio of accepted length to draft overhead. A drafter that takes 0.5ms but accepts only 1.2 tokens on average is often worse than one that takes 2ms but accepts 2.8 tokens on average.

    3. What a Training and Evaluation Framework Should Provide

    A usable draft model training framework typically needs to cover four stages:

    1. Data preparation: Sample and generate corpus from the target model, retaining the prompt, output, and the target model’s intermediate hidden states. It should support streaming writes and sharding to avoid holding the full dataset in memory.
    2. Draft model implementation: Pluggable draft head structures, with support for feature caching, KV reuse, and multi-step prediction heads.
    3. Training pipeline: A weighted combination of distillation loss and autoregressive cross-entropy, plus mixed precision, gradient checkpointing, and tensor/pipeline parallelism.
    4. Evaluation scripts: Offline reporting of acceptance rate, average accepted length, and draft time share; on the online side, integration with load-testing tools to observe throughput and P99 latency.

    A schematic training objective can be written as:

    1. # L_draft = α * CE(draft prediction, target model output) + β * L_distill(hidden state alignment)
    2. loss = alpha * cross_entropy(draft_logits, target_tokens) \
    3. + beta * mse_loss(draft_hidden, target_hidden.detach())

    Here, the beta term aligns the draft head with the target model’s representations and is key to improving the acceptance rate; the alpha term ensures language modeling correctness. In practice, it is recommended to warm up with hidden-state alignment first, then introduce the token-level loss to avoid early gradient conflicts.

    4. Key Engineering Details Before Going Live

    • Dynamic draft length: Adaptively adjust the number of speculation steps based on context confidence; shorten the draft when confidence is low to reduce wasted verification overhead.
    • Batch scheduling coordination: Speculative decoding amplifies per-request compute usage, so it must work with continuous batching strategies to prevent throughput regression under high concurrency.
    • KV Cache management: Draft and verification share the prefix cache; on rollback, cache entries for invalid branches must be correctly trimmed.
    • Numerical consistency: The verification stage must strictly use the target model’s sampling rules, otherwise the output distribution changes.
    • Observability: Bring accepted length, draft share, and verification batch utilization into monitoring and alerting to pinpoint the causes of diminishing returns.

    5. Deployment Recommendations on the Cloud

    For engineering deployment, a container platform can host the inference service and provide elastic scaling, object storage can hold training shards and draft model weights, a message queue can decouple data sampling from training jobs, and log services plus monitoring and alerting can close the observability loop. Baidu AI Cloud offers a fairly complete combination of these general capabilities, making it easier for teams to focus on the algorithm and tuning itself.

    6. Conclusion

    The upper bound of speculative decoding’s gains is determined by the acceptance rate, and the lower bound by the verification kernel and scheduling. The path to more than 50% throughput improvement is clear: first establish a trustworthy offline evaluation baseline, then iterate on the draft structure, and finally run online load tests and tune dynamic strategies.