LLM Inference Throughput Optimization: A Practical Engineering Guide

    This guide explains how to systematically improve LLM inference throughput while controlling cost under fixed model and hardware constraints. It covers building a metrics framework across throughput, latency, and cost; understanding structural bottlenecks in prefill and decode phases; and applying engineering techniques such as continuous batching, context cache reuse, quantization, parallelism strategies, speculative decoding, and structured output constraints. It also addresses deployment choices, capacity planning, common pitfalls, and a step-by-step rollout path for balancing model quality, latency, and cost in production.

    1. Why Inference Throughput Became an Engineering Focus

    Once large language models moved into production, the team’s focus shifted from “can the model answer correctly” to “can the model answer correctly, reliably, cheaply, and predictably.” One notable pattern in the original discussion is that the capabilities of the same model generation are compared repeatedly across different dimensions, while what actually determines user experience is often not a leaderboard ranking but how many requests can be served per unit of time, whether tail latency is under control, and whether the cost per call is affordable.

    The cost structure of inference is completely different from that of training. Training is a centralized, batch-friendly, throughput-first workload; inference is a distributed, highly interactive workload constrained by both latency and throughput. A model that performs well only in offline evaluation can easily experience queuing, timeouts, and idle resources simultaneously under real traffic if it lacks supporting inference optimization.

    Therefore, this article does not discuss the capability ranking of any specific product. Instead, it abstracts the problem as: given a fixed model and fixed hardware, how to systematically improve inference throughput and control cost.

    2. Build the Right Metrics Framework First

    Many optimizations fail because the wrong optimization target is chosen from the start. It is recommended to break the metrics into three layers:

    • Throughput layer: output tokens per second, completed requests per second, and effective compute utilization per unit of time.
    • Latency layer: time to first token, inter-token interval, end-to-end completion latency, and P95/P99 tail latency.
    • Cost layer: cost per token, cost per request, hardware depreciation and power overhead, and hidden waste from idle rates.

    There is natural tension among the three. Simply increasing batch size can significantly boost throughput but raises tail latency; simply minimizing latency lowers hardware utilization and increases unit cost. A more reasonable engineering approach is to first determine the upper latency bound acceptable to the business, then push throughput as high as possible under that constraint.

    1. Constrained optimization objective:
    2. max throughput (tokens/s)
    3. s.t. P99 end-to-end latency <= business threshold
    4. GPU memory usage <= single-card capacity * safety factor
    5. cost per token <= budget cap

    3. Structural Bottlenecks in the Inference Process

    To optimize throughput, you must first understand what happens inside a single generation request. Autoregressive generation can be split into two phases, and their bottlenecks are completely different:

    1. Prefill phase: processes all input tokens at once; it is compute-intensive and mainly affected by compute power and matrix multiplication efficiency.
    2. Decode phase: generates token by token; each step reads all model weights and the growing context cache, making it memory-bandwidth-intensive.

    This explains a common confusion: why throughput stays low even when compute still looks idle. The reason is that the decode phase spends much of its time moving weights and cache data rather than computing. The corresponding optimization directions are therefore clear: reduce the amount of data movement, increase reuse of data movement, and merge data movement across different requests.

    In addition, the context cache grows linearly with sequence length. Long-context scenarios are more prone to a chain reaction of tight GPU memory, forced reduction in batch size, and declining throughput.

    4. Main Engineering Techniques for Improving Throughput

    4.1 Continuous Batching and Request Scheduling

    Traditional static batching requires a batch of requests to start and finish synchronously; short requests must wait for long ones, resulting in poor hardware utilization. Continuous batching allows requests to dynamically join or leave after each step, immediately handing freed slots to queued requests. Combined with priority scheduling, preemption, and recomputation strategies, it can significantly increase the effective batch size while maintaining latency constraints.

    4.2 Context Cache Reuse

    For repeated prefixes such as system prompts, long documents, and few-shot examples, caching their computation results avoids repeated prefill every time. Engineering-wise, you need to design cache keys, invalidation policies, and capacity eviction mechanisms, and pay attention to isolation requirements in multi-tenant scenarios.

    4.3 Quantization and Low-Precision Computation

    Weight quantization, activation quantization, or mixed precision can reduce GPU memory usage and bandwidth pressure, thereby allowing larger batch sizes. Note that quantization introduces accuracy loss, so you must build a regression evaluation set oriented to the business scenario and validate results level by level, rather than only looking at general leaderboard scores.

    4.4 Combining Parallelism Strategies

    • Tensor parallelism: splits single-layer computation across multiple cards, reducing single-card memory pressure but introducing communication overhead.
    • Pipeline parallelism: splits by layers to improve device utilization, requiring handling of pipeline bubbles.
    • Data parallelism: uses multiple replicas to carry traffic, suitable for horizontal throughput scaling.

    In practice, these are usually combined, and the split granularity is decided based on inter-card interconnect bandwidth. When interconnect bandwidth is insufficient, over-splitting makes communication the new bottleneck.

    4.5 Speculative Decoding and Draft Models

    A lightweight draft model first generates several candidate tokens, which are then verified in parallel by the main model; accepted tokens are adopted directly. When the draft hit rate is high, this can significantly reduce the number of forward passes of the main model. Its benefit depends heavily on the task distribution; when the output distributions of the draft and main models differ too much, it can degrade or even slow down, so the hit rate and net benefit must be measured in practice.

    4.6 Structured Output Constraints

    When the business requires fixed-format output, using syntax constraints to mask illegal tokens during decoding can reduce invalid generation and retries, indirectly improving effective throughput.

    5. Deployment Form and Capacity Planning

    Claims such as “extremely high generation speed from a single rack” should be viewed rationally: such numbers usually come from ideal measurements under a specific model size, specific input and output lengths, specific parallelism configuration, and specific quantization scheme, and cannot be directly extrapolated to arbitrary business scenarios.

    A more reliable approach is to build your own benchmark matrix:

    1. Suggested variable dimensions to cover:
    2. - Input length: short/medium/long context
    3. - Output length: short answer/long text
    4. - Concurrency: gradually increase from 1 to saturation
    5. - Batch strategy: compare with continuous batching on/off
    6. - Precision scheme: compare original precision with each quantization level
    7. Record: throughput, P50/P95/P99 latency, peak GPU memory, cost per token

    In terms of deployment form, self-built clusters and rented general cloud resources each have trade-offs. The former offers more controllable cost under long-term stable workloads but requires taking on operations, scaling, and failure handling; the latter offers better elasticity and is suitable for fluctuating traffic and rapid validation. A common compromise is “self-host the baseline load and elastically scale out for peak traffic.” Regardless of the form, logging services, monitoring alerts, and tracing should be in place to make throughput, latency, and error rate continuously observable metrics rather than relying on after-the-fact guessing.

    6. Common Pitfalls

    • Only looking at peak throughput: ignoring tail latency still leads to poor user-side experience.
    • Blindly increasing batch size: memory and scheduling overhead backfire, and throughput drops instead of rising.
    • Ignoring input and output length distribution: planning with a single average length inevitably leads to inaccurate capacity.
    • Equating leaderboard capability with service capability: model quality and inference efficiency are two independent dimensions that need to be validated separately.
    • Lacking regression evaluation: any quantization, parallelism, or scheduling change should undergo dual review of both quality and performance.
    1. Define the business latency upper bound and cost budget to form quantifiable acceptance criteria.
    2. Build a benchmark matrix to obtain the current system’s real throughput curve and saturation point.
    3. Prioritize low-risk, high-return items: continuous batching, cache reuse, and request merging.
    4. Then advance quantization and parallelism strategy adjustments, performing dual regression of quality and performance at each step.
    5. Build a capacity model to predict resource needs based on input and output length distribution, reserving elastic headroom.
    6. Improve the observability system, incorporating throughput, latency, and cost into daily dashboards and alerts.

    8. Conclusion

    Inference throughput optimization is not the victory of a single point technology, but the result of the combined effect of model structure, scheduling strategy, precision scheme, parallelism topology, and hardware conditions. Only by building the metrics framework correctly, locating bottlenecks accurately, and putting every change into a rollback-capable evaluation process can you achieve a sustainable balance among quality, latency, and cost.