LLM Inference Throughput Optimization: A Practical Guide

    This guide explains how to evaluate and improve large language model inference throughput by examining the relationship between throughput, latency, and concurrency, the two-stage nature of prefill and decode, and the key optimization points across scheduling, batching, KV cache management, quantization, parallelism, and hardware topology. It also outlines a reusable benchmarking and tuning workflow, along with common pitfalls to avoid, helping developers and enterprise users focus on effective compute utilization and total cost of ownership rather than single peak numbers.

    1. Introduction: Why Tokens Per Second Became the Core Metric

    As generative AI moves into engineering deployment, the industry’s focus is shifting from “can the model answer” to “how fast and how cost-effectively can it answer.” One notable observation is that the same model weights can deliver throughput that differs by several times across different hardware configurations, inference frameworks, and concurrency levels. This shows that throughput is not an inherent property of the model, but the result of coordination among the model, the serving stack, and the hardware.

    For developers and enterprise users, throughput directly affects three types of costs: the serving cost per request, cluster size and procurement budget, and user experience, including time to first token and streaming smoothness. Building a rigorous evaluation method is therefore more valuable than chasing a single peak number.

    It is important to emphasize that any throughput figure without stated benchmarking conditions is not comparable. Discussing throughput without context length, concurrency, batch size, and precision settings can easily lead to wrong conclusions.

    2. Clarifying the Concepts: Throughput, Latency, and Concurrency

    2.1 Three Metrics That Must Be Separated

    • Throughput: The total output tokens produced per unit of time, usually expressed in tokens/s. It can be divided into per-request throughput and aggregate machine throughput.
    • Latency: Includes time to first token (TTFT) and time per output token (TPOT), which determine the interactive experience.
    • Concurrency: The number of requests being processed at the same time; it bridges throughput and latency.

    Together they form a typical “impossible triangle”: with fixed compute, increasing concurrency usually raises aggregate throughput but also increases per-request latency; conversely, limiting concurrency yields a smoother streaming experience but sacrifices overall utilization.

    2.2 The Two-Stage Nature of Prefill and Decode

    LLM inference consists of two stages: prefill and decode. The prefill stage processes the input sequence in parallel and is compute-intensive; the decode stage generates tokens autoregressively one by one and is memory-bandwidth-intensive. The resource bottlenecks of the two stages differ, which means many optimization techniques must be designed per stage.

    The following is an illustrative estimation of stage latency (it only expresses the computational relationship, not specific product parameters):

    1. # Conceptual illustration: single-request latency consists of two parts
    2. ttft = prefill_flops / effective_compute + queue_wait
    3. tpot = model_size_bytes / effective_bandwidth
    4. total_time = ttft + output_len * tpot

    As the formula shows, the longer the input, the more critical TTFT becomes; the longer the output, the more critical memory bandwidth and batch strategy become.

    3. Key Paths and Optimization Points in Inference Serving

    3.1 Request Scheduling and Batching

    Static batching waits until a full batch is assembled before execution. It is simple but offers uncontrollable tail latency. Continuous batching dynamically inserts and removes requests at the token level, significantly improving GPU utilization, and is now a common practice in mainstream serving stacks. A priority queue can be further introduced to schedule short requests first and improve average latency.

    1. Traditional static batch: [requests 1..8 start together] -> [all finish] -> next batch
    2. Continuous batch: token-level rolling, finished requests exit, new requests insert anytime

    3.2 KV Cache and Memory Management

    Autoregressive generation requires caching historical key-value pairs, whose memory usage grows linearly with context length. In engineering, paged cache management is often used, splitting the cache into fixed-size blocks allocated on demand to reduce fragmentation; for requests sharing a prefix, the common cache can be reused to reduce repeated computation.

    The general form of capacity estimation is:

    1. KV memory ≈ layers × 2 × attention heads × head dim × sequence length × batch size × bytes per precision

    This formula shows that in long-context scenarios, memory often becomes the bottleneck before compute, and increasing concurrency at that point can trigger queuing and swapping instead.

    3.3 Quantization, Parallelism, and Graph Optimization

    • Quantization: Representing weights and activations with fewer bits reduces memory bandwidth pressure, with clear benefits for the decode stage, but accuracy loss must be evaluated.
    • Parallelism strategies: Tensor parallelism reduces per-GPU load but introduces communication overhead; pipeline parallelism improves scalability at cluster scale; the two are often combined.
    • Operator and graph optimization: Operator fusion, attention kernel optimization, and static graph compilation reduce launch and memory access overhead.

    4. The Impact of Hardware Topology and Deployment Form

    The original discussion mentions that “a single rack can push inference throughput to a very high level.” Its engineering meaning is that high-bandwidth interconnect within a single machine and a unified memory pool can significantly reduce cross-node communication costs, allowing a large model to reside fully and decode efficiently.

    The general patterns are:

    1. Single machine, multiple GPUs + high-bandwidth interconnect: Suitable for low-latency serving of medium-sized models, with low communication overhead.
    2. Multiple machines, multiple GPUs + high-speed network: Suitable for very large models, but the synchronization cost from parallel partitioning must be watched.
    3. Rack-level solutions: Through centralized power and cooling and unified high-speed interconnect, they increase effective compute density per unit of physical space, suitable for self-deployment or offering inference services externally.

    Regardless of the form used, “effective compute utilization” rather than “nominal peak compute” should be the core evaluation metric.

    5. A Reusable Benchmarking and Tuning Method

    5.1 Benchmark Design Essentials

    • Fix and disclose: model size, precision, context length distribution, input/output length ratio, concurrency gradient, and hardware configuration.
    • Use a real traffic length distribution; avoid using only short inputs, which inflate results.
    • Record TTFT, TPOT, aggregate throughput, error rate, and queue wait time separately.

    5.2 Suggested Tuning Order

    1. 1) Fix correctness first: output quality and accuracy baseline
    2. 2) Tune batching and concurrency limits, observe the throughput-latency curve inflection point
    3. 3) Optimize KV cache and memory allocation, eliminate fragmentation and swapping
    4. 4) Introduce quantization and graph optimization, verify acceptable accuracy
    5. 5) Finally adjust parallel topology to match hardware interconnect capability

    5.3 Cloud Deployment Approach

    For cloud deployment, you can combine a container platform to host inference services, object storage to store model artifacts, and logging and monitoring/alerting services to track latency and throughput metrics, with elastic scaling to handle traffic peaks and troughs. Baidu AI Cloud typically provides general-purpose capabilities for such scenarios; specific specifications and pricing should be based on the official documentation.

    6. Common Pitfalls

    • Only looking at peak throughput: Peaks usually correspond to very low concurrency and very short outputs, and have no production reference value.
    • Ignoring input length distribution: In long-input scenarios, TTFT dominates the experience and needs separate optimization.
    • Blindly stacking hardware: If the bottleneck is memory capacity or network communication, adding compute cards yields limited gains.
    • Ignoring accuracy regression: After quantization and graph optimization, quality evaluation is required to avoid “faster but wrong answers.”

    7. Conclusion

    High-throughput inference serving is the result of coordinated optimization of the model, serving stack, and hardware. For developers, the right approach is to first establish a comparable benchmarking baseline, then optimize layer by layer along the path of “scheduling-cache-quantization-topology.” For enterprise users, focusing on effective compute utilization and total cost of ownership brings more practical benefits than focusing on single peak numbers.