Practical Guide to LLM Inference Acceleration: How Speculative Decoding Works

    This article explains why single-request decoding speed is hard to improve in large language models and how speculative decoding addresses the bottleneck. It breaks down the draft-and-verify workflow, the relationship between acceptance rate and speedup, the engineering optimizations required for stable throughput, and a practical performance evaluation methodology. Readers will learn how to tune speculative decoding and combine it with batching, KV cache management, and quantization.

    1. The Starting Problem: Why Single-Request Decoding Is Hard to Speed Up

    When people discuss inference speed for a large language model in the tens of billions of parameters range (for example, a 27B model), a common piece of community feedback is that single-request decoding only reaches a few dozen tokens per second. This number is not a sign of a broken implementation. It is a structural constraint of the autoregressive decoding paradigm itself.

    Autoregressive generation is inherently serial: token t cannot start until token t-1 has finished computing. During decoding, each forward pass produces only one useful token, yet it still has to move the entire set of weights from GPU memory into the compute units. For a 27B-class model stored in half precision, a single forward pass needs to read weights on the order of tens of gigabytes, while the amount of computation is comparatively small. The bottleneck here is not compute throughput but memory bandwidth — a classic memory-bound scenario.

    This leads to a key conclusion: simply increasing hardware compute delivers very limited improvement in decoding speed. The direction that actually works is increasing the number of tokens produced per weight movement. Speculative decoding is a general-purpose technique that works along exactly this axis.

    2. Core Mechanism: Draft Generation and Parallel Verification

    Speculative decoding is somewhat analogous to the recall-and-rerank two-stage structure of a retrieval system, but the goals differ: retrieval aims to shrink the candidate set, while speculative decoding aims to trade cheap guesses for an expensive opportunity to verify in parallel.

    One round can be broken into four steps:

    1. A much smaller draft model autoregressively generates k candidate tokens based on the current context.
    2. These k candidates are appended to the original context and passed to the target large model for a single forward pass, which yields output distributions at k+1 positions simultaneously.
    3. Positions are compared left to right, accepting the longest prefix that matches the large model’s distribution.
    4. If position i is rejected, a token is resampled from the large model’s actual distribution at that position, and the round ends.

    The speedup comes primarily from step 2. Work that originally required k serial forward passes is compressed into a single pass. Because the input sequence for that pass is longer, the scale of the matrix operations grows, hardware utilization actually improves, and the weight movement is amortized across multiple positions.

    It is worth stressing that standard speculative decoding is mathematically lossless: the accept/reject process combined with residual distribution resampling guarantees that the final output distribution is identical to that of the target model. What it accelerates is wall-clock time, not model capability, so there is no quality trade-off of the “small model making decisions for the large model” kind.

    Illustrative pseudocode:

    1. def speculative_decode(ctx, draft, target, k):
    2. draft_tokens = draft.generate(ctx, num=k) # cheap serial guesses
    3. logits = target.forward(ctx + draft_tokens) # one parallel verification of k+1 positions
    4. accepted = 0
    5. for i in range(k):
    6. if accept(logits[i], draft_tokens[i]):
    7. accepted += 1
    8. else:
    9. break
    10. next_token = sample_from(logits[accepted]) # resample at the rejection point
    11. return ctx + draft_tokens[:accepted] + [next_token], accepted

    3. Where the Gains Come From: Acceptance Rate vs. Speedup

    Let L be the average accepted length from the draft model (including the corrected token at the rejected position). Each loop then produces roughly L tokens while the large model runs only one forward pass. The ideal speedup approaches L; in practice it falls below L due to the overhead of draft generation itself, the extra memory reads during verification, and the fixed cost of sampling and comparison logic.

    The jump from roughly 40 tokens/s to nearly 120 tokens/s mentioned earlier is a direct illustration of this ratio: an approximately 3x improvement corresponds to an average accepted length near three. This range is common in practice, but it depends heavily on the task:

    • Low-entropy scenarios such as code completion, structured output, and fixed templates yield high draft hit rates and significant gains.
    • Open-ended creative writing and high-randomness sampling (large temperature, wide top-p) lower the acceptance rate and narrow the gains.
    • When k is set too large relative to the acceptance rate, the marginal cost of verification exceeds the serial overhead saved, resulting in a net regression.

    So the first tuning principle is not to set k as high as possible, but to find the balance point between acceptance rate and verification cost.

    4. Supporting Engineering Optimizations

    Speculative decoding is only one piece of the overall solution. Stable throughput also requires the following:

    Batching and scheduling. Real server workloads are concurrent, so continuous batching is needed to dynamically group requests, together with paged key-value cache management to reduce fragmentation. Within the same batch, different requests have different accepted lengths, which causes sequences to advance at uneven paces; the scheduler must support variable-length advancement and timely backfilling.

    Key-value cache consistency. When a draft is rejected, the key-value cache the target model computed for the wrong branch must be rolled back or isolated, otherwise it contaminates the subsequent context. A common engineering approach is to write to a temporary area first and commit only after verification passes.

    Draft-side cost control. The draft model should not be too large, or its serial overhead will eat the gains. Common practice is to choose a small model from the same family, or to adopt a self-speculative approach that reuses the large model’s own shallow representations and skips some layers to produce candidates.

    Sampling parameter alignment. The acceptance decision depends on the probability ratio between the target and draft models at the same position, so temperature, top-p, top-k, and related parameters must be semantically consistent on both sides; otherwise distribution equivalence is broken.

    Quantization and memory layout. Weight quantization reduces the amount of data moved, which directly benefits the memory-bound decoding stage. However, quantization error can affect the draft hit rate, so this should be measured rather than assumed.

    5. How to Evaluate Performance

    Do not describe speed with a single number. Record at least four dimensions:

    1. Single-request decoding speed (tokens/s), with input and output lengths fixed.
    2. End-to-end time to first token and overall latency, reflecting the interactive experience.
    3. Serving throughput (tokens/s or requests/min), measured at a fixed concurrency level.
    4. Average accepted length and acceptance rate, as the core observables for tuning.

    When testing, warm up first, fix the random seed, distinguish cold start from steady state, and stratify the input distribution (code, conversation, long documents) to avoid drawing global conclusions from a single case.

    6. Deployment Recommendations

    To reproduce this kind of acceleration in your own environment, the recommended path is: first establish a reproducible baseline measurement, then introduce speculative decoding and tune only two variables — k and draft model size — while watching the accepted-length curve; next layer on batching and cache optimizations; finally run stratified acceptance testing against your actual business input distribution. If building and tuning in-house is too costly, you can also use a general-purpose container platform, model serving offerings, and monitoring and alerting capabilities on the cloud to handle deployment and observability, keeping your focus on validating results.

    Overall, the leap from tens of tokens/s to over a hundred tokens/s does not come from faster single-point computation. It comes from a paradigm shift — trading cheap guesses for parallel verification — compounded with system-level optimizations such as batching, caching, and quantization. Understanding acceptance rate as the core variable is the shortest path to judging whether any acceleration approach is worth the investment.