Optimizing LLM Inference Throughput: A Practical Guide to Speculative Decoding

    This article explores how to optimize Large Language Model (LLM) inference throughput using speculative decoding. It covers standardizing performance metrics like tokens/s, the mechanics of draft model generation and target model verification, the trade-offs between acceptance rate and draft length, and key engineering considerations such as KV Cache management and batching. It concludes with actionable performance measurement and tuning recommendations for deploying speculative decoding effectively.

    In Large Language Model (LLM) inference services, tokens/s is one of the most frequently discussed metrics, yet it is not an isolated number. Single-request decoding speed, total system throughput, time to first token (TTFT), concurrent batch size, input/output length distribution, sampling parameters, and hardware configuration all significantly impact the final observed value. Therefore, when discussing “how many tokens/s,” a more professional approach is to first clarify the measurement criteria and then analyze the optimization opportunities. The core question worth exploring is: given the fundamental constraint of autoregressive decoding where tokens are generated sequentially, how can we reduce the number of sequential steps required by the target model through algorithmic and engineering techniques to increase the number of output tokens per unit time? Speculative decoding is a representative, general-purpose technical solution for this.

    1. Standardizing the Metric: What Does tokens/s Actually Measure?

    Inference speed can be divided into at least two levels: request-level and system-level. Request-level metrics focus on the output speed of a single request, commonly including TTFT, time per output token, and end-to-end output tokens/s. System-level metrics focus on the total throughput under fixed hardware and concurrent load, such as the total number of tokens generated by the system per second. These two metrics may improve simultaneously, but it is also possible for single requests to speed up while system throughput remains unchanged, or even decreases under high concurrency due to the extra computational cost of draft models.

    When measuring, variables must be controlled: model weights and quantization methods, input and output length distributions, concurrent request counts, batching strategies, sampling parameters, preheating adequacy, and cache enabling. Reporting only a peak tokens/s without explaining the load and configuration makes it difficult to reproduce and hard to determine if the optimization is actually effective. A more reasonable approach is to establish a baseline matrix: record results separately for low-concurrency low-latency scenarios, high-concurrency throughput scenarios, long-context scenarios, and short-output scenarios. Simultaneously, collect draft acceptance rates, target model verification counts, memory usage, and tail latencies.

    2. The Core of Speculative Decoding: Draft Model Recall, Target Model Verification

    The basic idea of speculative decoding can be compared to the “retrieve-and-verify” process in search systems: first, use a lower-cost draft model to generate several candidate tokens, and then let the target model verify these candidates in a single pass. Suppose the draft model generates γ candidate tokens at a time; the target model computes the distributions for these candidate positions plus the next one in parallel, resulting in γ+1 distributions. The candidate tokens are then compared one by one according to an acceptance rule: if a candidate is accepted, the next one is checked; once a candidate is rejected at a certain position, the target model’s distribution is used to sample a corrected token at that position, and all subsequent candidates are discarded. If all γ candidates are accepted, an additional token can be sampled from the target model’s final distribution.

    The benefit comes from “reducing the sequential decoding steps of the target model.” The target model originally needed to execute γ+1 sequential decoding steps. Now, by processing multiple candidate positions in a single verification forward pass, the computation resembles parallel processing of a sequence rather than multiple token-by-token decoding steps. Although the draft model consumes compute, its size is smaller and its per-step cost is lower. As long as the draft quality is good enough and the acceptance rate is high enough, the overall throughput can potentially increase by multiples. Under appropriate load and configuration, improving from tens of tokens/s to nearly a hundred tokens/s is not uncommon, but this is not a universal guarantee—actual results must be verified based on acceptance rate, hardware, and concurrency conditions.

    The pseudocode can be abstracted as follows:

    1. def speculative_decode(prompt, gamma, draft, target):
    2. prefix = prompt
    3. kv_draft = draft.init_kv(prefix)
    4. kv_target = target.init_kv(prefix)
    5. while not finished:
    6. candidates = draft.generate(prefix, gamma, kv_draft)
    7. target_logits = target.verify(prefix, candidates, kv_target)
    8. accepted = []
    9. for i, tok in enumerate(candidates):
    10. p_target = target_logits[i]
    11. if accept_rule(p_target, tok):
    12. accepted.append(tok)
    13. else:
    14. accepted.append(sample(p_target))
    15. break
    16. if len(accepted) == gamma:
    17. accepted.append(sample(target_logits[gamma]))
    18. prefix.extend(accepted)
    19. rollback_kv(kv_draft, kv_target, accepted)
    20. return prefix

    The pseudocode above omits probability correction details but illustrates the key workflow: draft generation, target verification, longest prefix acceptance, rejection position correction, and KV Cache rollback. When the acceptance rule is implemented correctly, speculative decoding can maintain consistency with the target model’s sampling distribution. If the acceptance rule is simplified for performance, the output quality and distribution deviation must be evaluated separately.

    3. Acceptance Rate and Draft Length: The Core Trade-off Between Benefit and Cost

    Let α be the single-token acceptance rate and γ be the draft length. The expected number of accepted tokens can be approximated as (1 - α^(γ+1)) / (1 - α). Intuitively, the higher the α and the more appropriate the γ, the more tokens a single verification pass can advance. However, increasing γ also raises draft generation and verification costs, and the probability of continuous acceptance for long candidates drops rapidly. Therefore, γ is not a case of “the larger the better” and requires dynamic adjustment. In engineering practice, γ can be adaptively selected based on recent acceptance rates, request types, and load conditions: moderately increase it when the acceptance rate is high, and shorten it when the acceptance rate is low to prevent invalid drafts from dragging down throughput.

    The quality of the draft model directly determines α. The draft model can be a smaller model of the same architecture, a quantized version, or a lightweight model obtained through distillation. If the differences between the draft and target models are too large in terms of vocabulary, tokenization, or sampling strategy, the acceptance rate will drop. Sampling parameters also affect the acceptance rate: at high temperatures or wide top-p values, the distribution is more scattered, and the probability of candidates being accepted usually decreases; greedy or low-temperature scenarios tend to achieve higher acceptance rates. Real-world systems should monitor the acceptance rate distribution rather than just looking at the average tokens/s.

    4. Key Engineering Points in System Implementation

    First is KV Cache management. The draft model and target model typically maintain their own caches; after verification, only the cache corresponding to the accepted prefix is kept, and positions after the rejection point must be rolled back or truncated. If the rollback implementation is inefficient, it will offset the speculative gains. Second is batching and scheduling. Speculative decoding is more likely to show its advantages in low-concurrency, low-latency scenarios. Under high concurrency, the target model’s compute may already be saturated, and the additional draft computation will compete for resources, requiring integration with continuous batching, priority scheduling, and length bucketing. Third is memory and bandwidth. The draft model adds extra weight and cache overhead, and parallel verification of multiple positions by the target model also changes memory access characteristics, necessitating an evaluation of whether the trade-off is worthwhile. Fourth is correctness and observability. You should record draft length, acceptance rate, rejection position distribution, verification counts, rollback latency, and tail latency to form a trackable performance profile.

    5. Performance Measurement and Tuning Recommendations

    When tuning, it is recommended to first fix the hardware and model configuration to establish a baseline; then enable speculative decoding to compare request-level latency and system throughput under low and high concurrency respectively; subsequently adjust the draft length, draft model size, quantization strategy, and batching parameters. Do not just look at the average tokens/s; also examine P95/P99 latency and acceptance rate stability. For long-context requests, the computation and cache pressure during the verification phase are higher and should be tested separately; for short-output requests, fixed overheads account for a larger proportion, and the benefits may be limited. Ultimately, business objectives should dictate the approach: if pursuing low single-request latency, prioritize optimizing acceptance rate and draft quality; if pursuing total system throughput, comprehensively evaluate the target model’s saturation level and resource allocation.

    Overall, the improvement in tokens/s is not the result of a single trick, but the combined effect of metric standardization, speculative decoding algorithms, draft quality, cache management, batch scheduling, and performance observation. Speculative decoding provides a general approach of “trading low-cost drafts for a reduction in the target model’s sequential steps.” However, only by incorporating acceptance rate, draft length, and system load into a unified evaluation can a stable, reproducible, and deployable throughput optimization solution be achieved.