Speculative Decoding in Practice: Faster LLM Inference Without Quality Loss

    Speculative decoding speeds up large language model inference by using a small draft model to propose tokens and the target model to verify them in parallel, without changing the output distribution. This article explains how it works, why it is lossless, how to choose and train a draft model, how to tune draft length dynamically, and what engineering details and metrics matter for real-world deployment.

    1. Where the Decoding Bottleneck Lies

    Large language models generate text one token at a time, and each token requires a full forward pass. The computation per step is small, leaving most of the GPU’s compute idle. The real bottleneck is the speed of moving model weights from memory to the compute units—in other words, memory bandwidth. As a result, single-request decoding speed is usually far below the hardware’s compute ceiling.

    Adding concurrency improves total throughput, but each request’s decoding speed drops. Interactive scenarios are sensitive to both time-to-first-token and per-token output speed, and these two goals are hard to optimize simultaneously.

    2. How Speculative Decoding Works

    The core idea can be summarized in one sentence: let a small model guess and a large model verify, turning serial token-by-token generation into batched verification.

    The workflow has three steps:

    1. Draft generation: The draft model autoregressively generates k candidate tokens. Because the draft model is small, this step takes far less time than the target model would need to generate k tokens.
    2. Parallel verification: The target model takes the k candidate tokens as input, and a single forward pass yields the output distribution at every position. Verifying k tokens costs roughly the same as generating one token, since the GPU processes these positions in parallel.
    3. Accept or roll back: The system checks positions from front to back. Draft tokens that match the target model’s distribution are accepted. At the first rejected position, all subsequent drafts are discarded, and the target model samples a corrected token at that position.

    A single verification pass produces at most k+1 tokens, which is the upper bound when every draft is accepted. Actual gains depend on the acceptance rate—the proportion of draft tokens the target model accepts.

    The acceptance rate can be estimated with a simple formula. Assuming each draft token is accepted with probability a, positions are independent, and the draft length is k, the average number of tokens produced per verification is (1−a^(k+1))/(1−a). With a = 0.8 and k = 4, this gives roughly 3.36, meaning each forward pass yields about 3.4 tokens on average. This estimate assumes i.i.d. acceptance; in real text, the acceptance rate fluctuates by position and content.

    3. Conditions for Losslessness

    The key mechanism is accept-reject sampling. As long as tokens are accepted or corrected according to the standard criterion, the final output distribution is identical to direct autoregressive decoding with the target model. This distinguishes speculative decoding from lossy acceleration methods such as quantization or distillation.

    Two caveats apply. First, the sampling implementation must strictly follow the accept-reject criterion—do not casually replace it with a threshold. Second, engineering factors such as floating-point error, the order of kernel computations, and batching behavior can introduce small differences. Run output-consistency checks before deployment: for example, verify that greedy decoding produces exactly the same output under both approaches, and compare token distributions over a large sample set with a fixed seed under stochastic sampling.

    4. Choosing and Training a Draft Model

    A draft model must satisfy three requirements. It must be small enough that draft generation time is negligible. It must be accurate enough—close to the target model’s distribution—to achieve a high acceptance rate. And it must be stable, performing consistently across texts of different lengths and domains.

    Using a generic small model directly as the draft model often yields a low acceptance rate. A more effective approach is joint training: while training the target model, optimize the draft model so its distribution approaches the target’s. In practice, the draft model can learn from the target model’s output distribution—for example, by distilling from the target model’s logits as soft labels. Losses from the draft model should not backpropagate into the target model’s parameters, or they may degrade the target model’s quality. Training data should cover the real length distribution and domain texts of your workload.

    There is no universal rule for draft model size. A common starting point is one-tenth to a fraction of the target model’s parameter count, then adjusted based on measured acceptance rates and per-step latency.

    5. Dynamic Draft Length

    A fixed draft length is not always optimal. Repetitive text, such as code and templated content, has high acceptance rates and benefits from guessing more tokens. High-entropy text, such as creative writing, has low acceptance rates, so extra draft tokens are mostly discarded and waste compute.

    Dynamic path selection adjusts draft depth based on text difficulty. Below is a common implementation approach; the specific thresholds should be calibrated with your own data.

    • Signal source: Use the acceptance rate over the most recent rounds as the primary signal, since it directly reflects the payoff. The output distributions from target model verification can also be used to compute entropy as a measure of uncertainty at the current position, and this computation can reuse results already produced during verification.
    • Adjustment rule: Increase draft length when the acceptance rate exceeds one threshold, and decrease it when it falls below another.
    • Edge cases: When entropy stays persistently high or the acceptance rate stays persistently low, reduce the draft length to 1 or disable speculation entirely, falling back to standard decoding to avoid overhead.

    The payoff of such strategies depends on the distribution of your workload’s text. Under mixed workloads, track historical hit rates per request or session rather than using a single global configuration.

    6. Engineering Considerations

    1. Parallelism and deployment: Large models typically require tensor parallelism to fit weights in memory and achieve sufficient bandwidth utilization. Deploy the draft model on the same set of devices as the target model to avoid cross-node communication eating into the gains.
    2. KV cache management: During verification, reuse the KV cache of the confirmed prefix directly and compute increments only for new candidate tokens. Recomputing the prefix on every verification pass would wipe out the benefits. On rollback, correctly truncate the cache entries corresponding to rejected drafts.
    3. Overhead of control policies: Entropy computation and threshold checks should reuse existing outputs rather than performing large-scale statistics on every step.
    4. Enabling the feature: Mainstream inference frameworks usually offer speculative decoding configuration options, such as specifying the draft model, the draft length cap, and whether to adjust it dynamically. Configuration names and supported features vary by framework, so consult your framework’s documentation and release notes before rollout.

    7. How to Measure the Gains

    Before rollout, run an A/B comparison with real production traffic and track at least the following metrics:

    • Single-request decoding speed: Reflects the experience at low concurrency.
    • Total throughput at high concurrency: Reflects cost at scale.
    • Time to first token: Draft generation and verification add overhead; confirm it has not degraded noticeably.
    • Acceptance rate distribution: Break down by length, domain, and task type to identify scenarios with low gains.
    • Output consistency: Compare outputs with a fixed seed.

    When reporting results, always state the hardware model and count, the sizes of the target and draft models, the draft length settings, and the distributions of batch size and request length. Some reports claim several-fold speedups at single-request concurrency, but such numbers depend on the specific test environment and can vary widely on different hardware or workloads. Speedup figures without disclosed test conditions should be treated as directional references only; rely on your own business benchmarks.

    8. Summary and Next Steps

    Speculative decoding uses a small model to propose candidate tokens and the target model to verify them in parallel, reducing serial token-by-token latency without changing the output distribution. Its benefits depend on the draft model’s acceptance rate, the draft length strategy, and deployment conditions.

    Start with a small-scale pilot on a low-risk service, recording the acceptance rate and single-request decoding speed. Then use the grouped data to decide whether to enable dynamic draft length and whether to invest in joint training of the draft model.