Speculative Decoding for LLM Inference Acceleration: How It Works and Performance Breakdown

    This article explains how speculative decoding speeds up large language model inference without changing the output distribution. It covers the memory-bandwidth bottleneck of autoregressive decoding, the three-stage mechanism of draft recall, parallel verification, and acceptance with rollback, plus a simplified speedup model and the engineering optimizations that matter in practice. Readers will also find practical recommendations and common pitfalls for measuring and deploying this technique.

    1. Background: Why LLM Inference Speed Gets So Much Attention

    When deploying large language models locally or in the cloud, the metric developers discuss most is generation speed, usually measured in tokens per second (tokens/s). Many users share the numbers they measured on different hardware, at different quantization precisions, and with different context lengths, but comparing raw numbers alone has limited value, because speed is affected by multiple factors such as memory bandwidth, batch size, sequence length, and sampling strategy. What really matters is which engineering techniques can significantly raise decoding throughput without changing the output distribution.

    The bottleneck of traditional autoregressive decoding is memory access rather than compute: for every token generated, all model weights must be moved from memory into the compute units once, and compute utilization is often very low. As a result, the industry has developed a general class of techniques: first “guess” several candidate tokens in a lightweight way, then verify them all in parallel with the large model in a single pass. If the guess is correct, it is accepted directly; if it is wrong, the computation is rolled back and redone. Structurally, this idea is highly similar to the recall-then-ranking pipeline used by search engines.

    2. Core Mechanism: Draft Recall and Parallel Verification

    The whole process can be broken into three stages.

    The first stage is recall. A draft model with far fewer parameters, or a lightweight prediction module based on the historical context, generates k candidate tokens in sequence. Its goal is not accuracy but high recall: including as much of what the large model would actually output as possible in the candidate set.

    The second stage is parallel verification. The candidate sequence is appended to the current context and passed to the target large model for a single forward pass, which yields the probability distributions at all k+1 positions at once. This is the key step: verification that originally required k sequential forward passes is compressed into one.

    The third stage is acceptance and rollback. Comparison proceeds position by position from the first one. If the sampled result falls on the candidate token, it is accepted; at the first mismatch, the sequence is truncated, and a token is resampled from the distribution the large model gives at that position as a correction. The logic is illustrated below:

    1. # Pseudocode: main loop of speculative decoding
    2. draft_tokens = draft_model.generate(context, k) # recall k candidates
    3. logits = target_model.forward(context + draft_tokens) # one parallel verification pass
    4. accepted = 0
    5. for i in range(k):
    6. if accept(sample(logits[i]), draft_tokens[i]):
    7. accepted += 1
    8. else:
    9. break
    10. new_tokens = draft_tokens[:accepted] + [sample(logits[accepted])]
    11. context = context + new_tokens

    Mathematically, as long as the acceptance test uses the standard form of rejection sampling based on the ratio between the target distribution and the draft distribution, the output distribution is exactly the same as sampling directly from the original model, which makes this a lossless acceleration. This is also what essentially distinguishes it from “switching to a smaller model” or “lowering precision”: the speedup does not come from a compromise in quality.

    3. Where the Acceleration Comes From: Breaking Down 40 tokens/s to Nearly 120 tokens/s

    The original text mentions optimizing from about 40 tokens/s to nearly 120 tokens/s, close to a threefold gain. This number is not mysterious and can be understood with a simplified model. Let the time of one target model forward pass be T, the time of one draft model pass be t, and the average accepted length per round be L. The speedup ratio is approximately:

    1. speedup ≈ L / (1 + k * t / T)

    This reveals three levers. First, increase the average accepted length L: the more closely the draft matches the target distribution, the greater the benefit. Second, reduce the t/T ratio: the draft model must be small or cheap enough. Third, control the number of candidates k: when k is too large, the verification gains are eaten up by the draft overhead, so there is a clear optimum. In practice, an accepted length between 2 and 4 already brings considerable gains, and stacking engineering optimizations on top to reach the threefold range is reasonable. It should be emphasized that the specific numbers depend heavily on model architecture, task type, and hardware, and should not be treated as a universal promise.

    4. Common Engineering Optimizations

    What really makes the difference is often the implementation details. Common industry practices include:

    • Hierarchical drafting strategies: use multi-layer structures or staged prediction to produce candidates and reduce invalid ones.
    • Tree-structured candidate organization: verify multiple candidate branches in one pass, isolate branches with attention masks, and improve the hit rate.
    • Key-value cache reuse: share the prefix cache between drafting and verification to avoid recomputing long contexts.
    • Dynamic candidate length: adaptively adjust k based on confidence, guessing more when confidence is high and less when it is low.
    • Batching and scheduling: merge multiple requests into batches and use continuous batching to improve overall throughput.
    • Quantization and operator fusion: lower the cost of moving weights and ease the memory-access bottleneck.

    When deploying in the cloud, these capabilities usually map to general product categories: container platforms host inference services, object storage holds model files, and logging services plus monitoring and alerting are used to observe first-token latency and throughput fluctuations. Baidu AI Cloud offers the same kind of general infrastructure capabilities in these scenarios, and the specific selection should be determined by load testing against your own workload.

    5. Practical Recommendations and Common Pitfalls

    First, do not look only at tokens/s. First-token latency, stability under long contexts, and throughput degradation under concurrency are equally important. Second, the draft model needs to come from the same source and distribution as the target model; pairing across model families often yields a very low acceptance rate and ends up slower. Third, when the sampling temperature is raised or the task leans toward open-ended generation, the accepted length drops, so measure per scenario. Fourth, always run a correctness regression to confirm the output distribution has not changed.

    In summary, the value of speculative decoding lies in turning the sequential memory-access bottleneck into an opportunity for parallel verification, using one forward pass to confirm multiple tokens. Once you understand the balance among accepted length, draft overhead, and candidate count, and layer on engineering techniques such as cache reuse and batching, you can achieve several-fold speedups while preserving generation quality. This is also one of the most practical and general technical paths for inference acceleration today.