Speculative Decoding for LLM Inference Acceleration: How It Works

    This article explains why autoregressive LLM decoding is often bottlenecked by memory bandwidth rather than compute, and how speculative decoding addresses it through a draft-verify-resample loop. It covers the core mechanism, the three variables that determine the speedup ratio (acceptance rate, draft length k, and batching with GPU memory), practical deployment considerations, and common evaluation pitfalls. Teams will learn how to assess single-stream latency and concurrent throughput when bringing speculative decoding to production.

    1. Background: Why Generation Stalls at Token-by-Token Output

    When deploying a general-purpose large language model with billions of parameters locally or in the cloud, developers most often observe the same pattern: GPU memory usage is acceptable, but output speed stays in the range of tens of tokens per second. Discussions tend to focus on “which GPU model do I have,” “how many bits is the quantization,” or “how long is the context,” yet what actually determines single-request decoding throughput is usually not peak compute but memory bandwidth and the decoding structure itself.

    The essence of autoregressive decoding is serial dependency: the token at position t must be determined by the results of the preceding t tokens. This means that every generated token requires moving the entire set of model weights from GPU memory to the compute units once. With a small batch size, the arithmetic intensity of matrix multiplications is very low, so the hardware spends most of its time waiting on weights while the compute units sit idle. This is the so-called memory-bound regime, and it is the root cause of limited single-stream generation speed.

    Therefore, the right acceleration strategy is not “make a single forward pass faster,” but “make one weight transfer produce more tokens.” Speculative decoding is a representative approach developed along exactly this direction.

    2. Core Mechanism: A Small Model Recalls, the Large Model Verifies in One Pass

    The basic flow can be abstracted into a three-step loop of draft, verify, and resample:

    1. Use a much smaller draft model to autoregressively generate k candidate tokens.
    2. Concatenate the confirmed tokens with these k candidates into a sequence, and run one forward pass on the target large model to obtain distributions at k+1 positions in parallel.
    3. Validate the candidates one by one against an acceptance criterion, accept the longest matching prefix, and fill the first rejected position by resampling from the large model’s own distribution.

    The key is step 2: the large model’s computation over k+1 positions is parallel, so its cost is close to a single regular forward pass rather than k+1 passes. As long as the candidates are accepted, one weight transfer effectively buys back multiple tokens. The improvement mentioned in the original text, “from just over forty tokens per second to nearly one hundred and twenty,” is a direct illustration of this mechanism under an ideal acceptance rate: the speedup ratio is roughly equal to the average number of tokens accepted per round.

    It is worth emphasizing that this process keeps the output distribution unchanged in mathematical terms (when standard acceptance sampling is used), so what it accelerates is speed, not quality traded for speed. This is fundamentally different from directly replacing a large model with a small one.

    Illustrative pseudocode:

    1. prefix = prompt_ids
    2. while not done:
    3. draft = draft_model.generate(prefix, max_new_tokens=K) # Cheap recall
    4. cand = prefix + draft
    5. logits = target_model.forward(cand) # One parallel verification
    6. n = accept_length(logits, draft, prefix) # Position-by-position check
    7. prefix = cand[:len(prefix) + n]
    8. if n <= K: # Rejection occurred, resample to fill
    9. prefix.append(sample_from(logits[len(prefix)]))

    3. Three Groups of Variables That Determine the Speedup Ratio

    3.1 Acceptance Rate

    The acceptance rate is the most sensitive metric. The closer the draft distribution is to the target distribution, the longer the accepted length. The draft model usually needs training or distillation aligned with the target task; otherwise, domain shift will cause the acceptance rate to drop sharply.

    3.2 Draft Length k

    If k is too small, the parallelism of verification is not fully utilized; if k is too large, the rejected tail is all wasted computation and the draft stage is additionally lengthened. In practice, k is often set to a small single-digit number, combined with a dynamic strategy: probe with a longer draft after consecutive acceptances, and shrink quickly after consecutive rejections.

    3.3 Batching and GPU Memory

    Speculative decoding amplifies the usage and fragmentation of the KV cache, because each round must reserve space for the candidate sequence. When deploying on a general container platform or a model serving framework, continuous batching, paged cache management, request queuing, and timeout policies all need to be tuned together; otherwise, latency will fluctuate noticeably under high concurrency.

    4. Engineering Implementation Notes

    • Layered decoupling: Keep draft generation, verification, and sampling within clear module boundaries, making it easy to swap draft strategies and run A/B evaluations.
    • Observability: At minimum, collect average accepted length, draft hit rate, per-round latency, in-batch concurrency, and cache usage, and track tail latency with a monitoring and alerting system.
    • Elastic scaling: Inference services are typically made stateless and paired with load balancing and autoscaling, while a logging service is used to capture failed requests and parameter combinations.
    • Safe fallback: Keep an execution path that disables speculation, and automatically degrade when the acceptance rate falls below a threshold to avoid negative optimization.

    5. Common Misconceptions

    The first is treating the speedup ratio as a fixed constant, when in fact it varies dramatically with task type, temperature, and context length. The second is ignoring the impact of sampling parameters, since high randomness significantly reduces the acceptance rate. The third is testing only single requests while overlooking the throughput loss caused by the draft stage competing for compute under high concurrency. A sound evaluation should cover both single-stream latency and concurrent throughput, and be measured on real business corpora.

    6. Conclusion

    The value of speculative decoding lies in trading one expensive weight transfer for the output of multiple tokens, transforming memory-bound serial decoding into “parallel guessing plus verification.” For teams that want better response speed in their LLM applications, understanding the coupling among acceptance rate, draft length, and scheduling strategy is more meaningful than chasing a single hardware metric. On general cloud infrastructure such as Baidu AI Cloud, combined with general capabilities like container platforms, monitoring and alerting, and logging services, this kind of acceleration approach can be brought into production more smoothly.