Speculative Decoding for LLMs: A Practical Guide to Faster Inference

    This guide explains how speculative decoding accelerates large language model inference by separating draft generation from parallel verification. It covers why autoregressive decoding is memory-bound, how dynamic draft depth adapts to context uncertainty, and why single-request latency and concurrent throughput must be measured separately. You will also find a layered troubleshooting order for reproducing performance, plus configuration, observability, and fallback recommendations for production deployment.

    1. The Starting Problem: Why Autoregressive Decoding Dominates Inference Wait Time

    LLM inference is usually split into two phases. Prefill processes the input context in one pass and produces the first token. Decoding then generates tokens one by one through autoregression. Prefill is compute-intensive and can fully exploit the parallelism of matrix multiplication. Decoding, by contrast, produces only one token per step while moving all model weights from memory to the compute units, which makes it a typical memory-bound workload. With a single request running on a long context such as 32k, the attention portion adds further overhead, arithmetic intensity drops, and the accelerator spends most of its time waiting for data rather than computing.

    This leads to an engineering reality: decoding speed does not scale linearly with compute. To shorten the wait per token, there are only three options — reduce the weight volume moved at each step (quantization, sparsification), increase the effective output per step (speculative decoding, multi-token prediction), or hide the wait (higher concurrency, pipelined scheduling). Speculative decoding takes the second path, and it is currently the one with the least change to the model’s output distribution and the lowest engineering intrusiveness.

    2. Mechanism Breakdown: Draft Generation and Parallel Verification

    Speculative decoding splits one serial generation into two jobs: “guess” and “verify”:

    1. A draft model generates several candidate tokens consecutively at low cost, forming a speculative sequence.
    2. The target model appends this sequence to the context and computes the distribution at all positions in a single forward pass.
    3. Positions are compared one by one against an acceptance criterion, the longest matching prefix is accepted, and rejected positions are resampled from the target model’s distribution.

    The key is the second step: verification has the same compute shape as prefill and is parallel, so verifying k tokens costs roughly the same as verifying 1 token, while the draft phase costs far less than one full forward pass of the target model. As long as the accepted length is large enough, the overall result is a speedup. It is worth stressing that a proper acceptance criterion keeps the output distribution identical to the target model; the speedup comes from a change in execution shape, not from sacrificing generation quality.

    Draft-side quality sets the upper bound on the gain. The closer the draft distribution is to the target, the higher the acceptance rate; but an oversized draft model eats up the time saved. Choosing a draft model is therefore a balance between “staying close to the target distribution” and “being light enough itself,” which is exactly why draft models are trained specifically for a given target model.

    3. Dynamic Path Selection: Spending Compute Where Acceptance Is Likely

    Fixed-length speculation does not pay off in real workloads: high-entropy segments (reasoning turns, code branches, open-ended generation) naturally have low acceptance rates, so guessing more just wastes more; low-entropy segments (structured output, repeated templates, long-document continuation) tend to hit consecutively. Dynamic path selection lets the draft phase adaptively adjust speculation depth and path according to the uncertainty of the current context — going deeper in low-entropy regions and converging promptly in high-entropy ones — so limited draft compute goes where expected return is highest.

    Illustrative control logic:

    1. # Pseudocode: adapt speculation depth to uncertainty
    2. def draft_depth(state, base=4, max_depth=8, entropy_hi=1.2):
    3. h = estimate_entropy(state) # lightweight estimate of current context uncertainty
    4. if h < entropy_hi * 0.5:
    5. return max_depth # low entropy: deepen speculation
    6. elif h < entropy_hi:
    7. return base # medium entropy: keep the baseline
    8. else:
    9. return max(1, base // 2) # high entropy: converge fast, cut wasted drafts

    In practice, estimating entropy does not need to be expensive; lightweight signals such as the distribution entropy at a few positions of the draft model itself or top-k probability concentration are enough approximations. Decisions do not need to be made every step either — aggregating over a window is sufficient, so the control logic does not become a new bottleneck.

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

    The magnitudes from the original experiment are worth keeping as a methodology reference: on a target model with an 8-card accelerator and a tensor parallel degree of 8, a single request on a 32k low-entropy context decoded at about 288 tokens/s, roughly 3.4x native autoregression; at 64 concurrent requests, total throughput was about 609 tokens/s, about 45% higher than the native approach.

    The gap between these two numbers is not a contradiction but an inherent trait of speculative decoding:

    • With a single request, the parallel compute in the verification phase sits largely idle, so the “trade compute for latency” benefit is most visible.
    • Under high concurrency, the device is already filled by many requests, compute shifts from idle to scarce, and the extra draft and verification work starts competing with real requests, so the speedup ratio naturally falls back — while total throughput still stays positive.

    When evaluating a solution, always report single-request decoding speed, total throughput at the target concurrency, and the accepted-length distribution; looking at only one of them easily leads to wrong conclusions. A suggested observation table:

    Metric Meaning Use
    Single-request tokens/s Decoding speed after the first token Measures interactive experience
    Total throughput tokens/s Aggregate output at a fixed concurrency Measures resource efficiency
    Average accepted length Tokens accepted per verification round Locates draft quality issues
    Draft overhead share Draft time / total time Tells whether the draft is too heavy

    5. Bottleneck Isolation: A Layered Order for Reproducing Performance

    To reproduce validated performance in a real environment, rule out causes layer by layer, bottom-up:

    1. Hardware: confirm the accelerator model, memory capacity, and interconnect topology match; differences in inter-card bandwidth directly change tensor parallel efficiency.
    2. Runtime: confirm the parallel split, memory allocation strategy, and batching and scheduling parameters match, paying particular attention to how context length affects attention cache usage.
    3. Model: confirm weight precision and the version pairing between draft and target models; a draft/target version mismatch is a common cause of a sudden drop in acceptance rate.
    4. Data: confirm the evaluation context and concurrency model match; speedup ratios for low-entropy and high-entropy workloads can differ by several times.
    5. Software: confirm the inference framework version, operator implementations, and graph execution mode match, avoiding too many synchronization points that degrade verification back to serial execution.

    Change only one variable at a time, and record accepted length and timing at each layer, so performance differences can be attributed to a specific layer.

    6. Reuse and Production Recommendations

    Turning these capabilities into a one-click reusable inference setup usually takes three things. First, configuration: converge the draft model path, speculation depth bounds, concurrency and parallel degree, and context length into a single readable config. Second, observability: enable logging and alerting for accepted length, draft overhead, and tail latency by default, wired into a general-purpose logging service and monitoring/alerting category. Third, fallback: keep a native decoding switch and automatically degrade when the acceptance rate drops below a threshold, keeping tail latency under control.

    On the cloud, you can combine a container platform to host the inference service, object storage for models and configs, and a message queue to smooth request spikes, then observe tail latency through a general monitoring category — turning speculative decoding from a one-off experiment into an engineering capability that keeps iterating. For low-entropy-heavy scenarios such as AI coding tools and long-document question answering, gains are usually more pronounced; for high-entropy creative generation, set expectations on latency stability rather than a speedup multiple.