Speculative Decoding for LLMs: How It Speeds Up Inference and How to Implement It

    This article explains how speculative decoding accelerates large language model inference by trading a single forward pass for multiple tokens. It covers the mechanism of draft generation and parallel verification, why the output distribution stays identical to standard autoregressive decoding, how dynamic draft length selection adapts acceptance rates across contexts, and what the reported single-concurrency and high-concurrency results mean in practice. It also provides a reusable rollout path and a list of common pitfalls to avoid.

    1. The Starting Problem: Why Autoregressive Decoding Needs Rewriting

    LLM inference has two phases: prefill and decode. Prefill can fully exploit the parallelism of matrix multiplications, but decode runs a complete forward pass for every single token, moving all weights from GPU memory into the compute units each time. The effective arithmetic intensity is extremely low. As a result, in single-concurrency scenarios the bottleneck is usually not compute but memory bandwidth, along with fixed overheads such as kernel launches and scheduling. The practical outcome: the longer the context and the lower the concurrency, the worse the GPU utilization, and the slower the perceived token streaming speed.

    Common engineering mitigations include quantization, operator fusion, KV cache optimization, and continuous batching. Most of them, however, optimize under the assumption that each token takes exactly one step, so their ceiling is limited. Speculative decoding takes a different angle: since the cost of one forward pass is dominated by weight movement, verifying multiple tokens in a single forward pass amortizes that fixed cost.

    2. Core Mechanism: Draft Generation and Parallel Verification

    Speculative decoding splits the decode process into two roles.

    • Draft model: small parameter count, lightweight structure. It generates several candidate tokens consecutively at low cost, forming a draft sequence of length roughly γ.
    • Target model: runs one forward pass over the draft sequence, obtains the probability distribution at every position in parallel, and then accepts or rejects position by position.

    Correctness of verification is the critical part. The distribution the target model produces at position i is computed under the assumption that all of the first i-1 tokens are draft tokens. The acceptance decision must therefore be based on the probability ratio, and a rejected position must be resampled from a corrected distribution. Only then is the final output distribution strictly identical to native autoregressive decoding. This is the precondition for the engineering community to adopt speculative decoding: it is lossless acceleration, not a trade of quality for speed.

    A schematic version of the core loop:

    1. draft = draft_model.generate(prompt, n=gamma) # low-cost consecutive drafting
    2. logits = target_model.forward(prompt + draft) # one forward pass, parallel verification
    3. accepted = 0
    4. for i, tok in enumerate(draft):
    5. r = random()
    6. if r < min(1, p_target[tok] / p_draft[tok]):
    7. accepted += 1
    8. else:
    9. # resample from the corrected distribution to stay unbiased
    10. emit(residual_sample(p_target, p_draft, i))
    11. break
    12. emit(sample(p_target, position=accepted)) # one extra token for free

    So the number of tokens actually produced per step falls between 1 and γ+1, and the speedup depends on the draft acceptance rate and on the cost of generating the draft itself.

    3. Dynamic Path Selection: Turning Acceptance Rate into a Tunable Variable

    The naive approach fixes γ at a constant. The problem is that context difficulty varies enormously: low-entropy segments such as code completion, structured output, and repeated templates see high acceptance rates, while open-ended reasoning and long chains of mathematical derivation see a clear drop. A fixed γ either wastes draft compute on hard samples or leaves speedup on the table for easy ones.

    Dynamic path selection makes γ and the draft depth a decision that varies with context state: based on the confidence distribution during drafting, entropy values, or historical acceptance statistics, it decides in real time whether to keep extending the draft or converge early and go to verification. The benefits are threefold:

    1. On easy samples, deepen the draft to raise tokens produced per step.
    2. On hard samples, converge quickly so ineffective drafts do not consume bandwidth and compute.
    3. Make overall behavior more stable and reduce tail-latency jitter for long-tail requests.

    In practice, a lightweight sliding-window statistic is usually maintained, with the recent acceptance rate used as a feedback signal, plus clamping to prevent γ from oscillating:

    1. gamma = clamp(gamma + lr * (recent_accept_rate - target_rate),
    2. gamma_min, gamma_max)

    4. Measured Results and How to Read Them

    On a single node with 8 GPUs and a tensor parallel degree of 8, using a 32k low-entropy context at single concurrency, decode speed reaches 288.2 tokens/s, about 3.41x native autoregressive decoding. Raising concurrency to 64 brings total throughput to 608.71 tokens/s, a 44.9% improvement over the native approach.

    The gap between these two numbers is worth noting. The 3.41x at single concurrency comes essentially from amortizing the bandwidth bottleneck, while the 44.9% at high concurrency is smaller because large batches already saturate GPU compute, and the draft model competes for the same compute resources, so marginal gains naturally shrink. The correct conclusion: speculative decoding is not a universal switch for every scenario. Low concurrency, long context, and low-entropy output are its sweet spot. When high-concurrency throughput is the constraint, prioritize batching and memory management optimizations first, then use speculative decoding as a supplement, controlling the extra overhead through dynamic draft length.

    5. A Reusable Rollout Path

    To reproduce this kind of setup reliably in a real environment, proceed as follows:

    1. Fix the baseline: record the native decode latency distribution (P50/P95), throughput, and memory usage as a reference.
    2. Localize layer by layer: check model precision and quantization configuration, runtime scheduling, communication and parallel strategy, and hardware interconnect bandwidth in turn, so software issues are not mistaken for hardware bottlenecks.
    3. Tune parameters: use acceptance rate and tokens per step as the core metrics, and sweep the γ bounds and draft model size rather than looking only at end-to-end speed.
    4. Verify consistency: compare output distributions with a fixed random seed to confirm the speedup introduced no quality drift.
    5. Package it as a service: converge draft generation, verification, and dynamic scheduling into a unified inference entry point, with monitoring, alerting, and logging to observe acceptance rate, queue length, and tail latency.

    6. Common Pitfalls

    • Assuming a smaller draft model is always better: too small lowers the acceptance rate, and the savings on draft cost are cancelled out by wasted verification.
    • Looking only at average speed: when low-entropy and high-entropy requests run together, the average hides tail-latency degradation.
    • Ignoring memory: the draft model and extra KV cache take up available GPU memory and may actually reduce maximum concurrency.
    • Taking the lossless premise for granted: if the acceptance decision or residual sampling is implemented incorrectly, output quality degrades silently, so regression evaluation must be in place as a safeguard.

    In summary, the value of speculative decoding is exchanging one verification for multiple tokens, amortizing fixed costs in bandwidth-bound scenarios, while dynamic path selection determines whether the mechanism keeps delivering gains under real traffic. Chaining baseline, metrics, consistency checks, and service packaging into a closed loop is what makes the speedup reproducible and operable.