LLM Inference Acceleration: How Speculative Decoding Boosts Throughput

    This article explains why autoregressive LLM inference is often bottlenecked by memory bandwidth rather than compute, and how speculative decoding turns sequential generation into a recall-and-verify process. It covers the core workflow, a performance model centered on acceptance rate, key engineering details such as KV cache consistency and sampling correctness, trustworthy benchmarking practices, common pitfalls, and a practical rollout order for improving throughput in production.

    1. Background: Why LLM Inference Stays Slow

    When deploying large language models locally or in the cloud, the metric developers discuss most is tokens generated per second. In single-GPU tests, many teams see only a few dozen tokens/s, even though theoretical compute suggests much more is possible. Understanding this gap starts with the constraints of autoregressive decoding.

    Autoregressive generation is strictly sequential: the computation for token t depends on the result of token t-1, so it cannot be parallelized within the same sequence. For a large model, every token requires moving all weights from memory to the compute units once. The bottleneck is therefore usually memory bandwidth and weight loading, not floating-point throughput. This is why “plenty of compute but slow output” is so common.

    Real throughput is also affected by context length, KV cache growth, batch size, quantization, sampling strategy (greedy, temperature, top-p), and the scheduling policy of the serving framework. A single isolated tokens/s number rarely reflects the true capability of the system.

    2. Core Idea: Reframe Generation as “Recall + Verify”

    The approach described in the original source belongs to a class of acceleration techniques known as speculative decoding. The intuition is similar to a retrieval system: a low-cost “draft” step guesses several future tokens at once; the target large model then verifies those candidates in a single parallel pass; if verification succeeds, the whole segment is accepted, and if it fails, generation restarts from the first incorrect position.

    The key insight is that the time difference between computing one token at a time and computing n+1 tokens in parallel is far smaller than n times. The bottleneck is weight movement, not arithmetic volume. Compressing a long chain of small sequential computations into a few batched verification passes significantly reduces total time, while the output distribution can still remain mathematically identical to the target model (with the correct acceptance/rejection sampling rules).

    The main flow in pseudocode:

    1. # draft: lightweight draft model; target: target large model
    2. prefix = prompt
    3. while not finished:
    4. guesses = draft.generate(prefix, n) # low-cost recall of n candidates
    5. probs = target.forward(prefix + guesses) # verify n+1 positions in parallel
    6. k = accept_length(probs, guesses) # find the longest matching prefix
    7. prefix += guesses[:k] + [sample(probs[k])] # accept k, then add 1

    In this structure, the real driver of gains is the expected value of accept_length, i.e., the acceptance rate.

    3. Performance Model: Why Acceptance Rate Is the Only Lever

    The speedup can be roughly understood as: average tokens produced per loop iteration divided by the time per loop iteration. The numerator is determined by the acceptance rate; the denominator is determined by draft cost, batched verification cost, and KV cache management overhead.

    • Acceptance rate near 1: nearly every iteration takes all n candidates, and throughput can improve several times;
    • Very low acceptance rate: the draft work is wasted, and verification plus rollback costs make things slower;
    • Draft model too large: each draft becomes expensive, offsetting the gains;
    • Draft model too small: candidate quality drops and the acceptance rate collapses.

    Tuning is therefore not as simple as “increase n.” The goal is to make the draft distribution as close as possible to the target distribution. Common practices include using a small model from the same family as the draft, distilling or fine-tuning the draft to align its style, building domain-specific prompt templates, and dynamically adjusting n for long-context scenarios.

    4. Key Engineering Details

    1. KV cache consistency. During verification, the cache must be written for all n+1 positions at once; on rollback, the cache for the rejected portion must be truncated correctly, otherwise subsequent generation becomes semantically corrupted. This is the most bug-prone area.
    2. Correctness of sampling rules. If strict distributional equivalence is required, an acceptance criterion with probability correction is needed rather than simple string comparison; if only usable quality is required, approximate matching is often used in practice for simpler implementation, but its bias should be made explicit.
    3. Batching and scheduling. In serving scenarios, different requests have different acceptance lengths, causing idle slots within a batch. Continuous batching, dynamic batching, and timeout policies are needed to avoid throughput dropping under high concurrency.
    4. Quantization and memory. Weight quantization directly eases the bandwidth bottleneck and stacks well with speculative decoding; KV cache quantization, however, needs careful evaluation of precision loss.
    5. Long-context decay. The longer the context, the harder it is for drafts to hit, so n and rollback thresholds should vary with length.

    Illustrative parameter sweep logic:

    1. for n in (2, 4, 6, 8):
    2. for draft_size in ("tiny", "small"):
    3. metrics = benchmark(n, draft_size, prompts=sample_set)
    4. print(n, draft_size, metrics.tokens_per_s, metrics.accept_rate)

    5. How to Run Trustworthy Performance Evaluations

    Comparisons are only meaningful under a consistent setup. It is recommended to fix and record: hardware model and memory bandwidth, quantization precision, context length, batch size, sampling parameters, input/output length distribution, and the distinction between warmup and steady state. Report at least three numbers: steady-state tokens/s, time to first token, and average acceptance length. Reporting only peak throughput can easily mislead decisions.

    Ablation studies are also necessary: a baseline with speculative decoding disabled, changing only n, changing only draft size, and changing only quantization, each measured for marginal gains, to avoid attributing the combined effect of multiple optimizations to a single one.

    6. Common Pitfalls

    • Assuming larger n is always better: increasing n raises per-iteration cost and lowers marginal acceptance;
    • Using results from different tasks to validate each other: acceptance rates vary widely across code, dialogue, and long-document summarization;
    • Ignoring cache handling on the rollback path, causing occasional duplication or truncation;
    • Reusing single-request optimal parameters under high concurrency;
    • Treating speedup as a quality improvement, when it only changes speed and not the output distribution (with a correct implementation).

    7. Deployment Advice and Cloud Practice

    To reliably gain throughput in production, proceed in the order “quantize first, then align the draft, then optimize scheduling.” At the infrastructure level, container platforms can provide elastic scaling, object storage can distribute model weights, and logging and monitoring with alerts can track acceptance rate, in-batch idle rate, and memory usage. General capabilities from Baidu AI Cloud can serve as one foundation option for hosting such inference services.

    Overall, the value of speculative decoding is trading one cheap “recall” for one expensive “batched verification,” converting a sequential bottleneck into parallel throughput gains. Understanding acceptance rate as the core variable, together with quantization, batching, and rigorous evaluation, is what moves the experience from a few dozen tokens/s to a steady-state level several times higher.