LLM Inference Performance: A Practical Guide to Approaching Hardware Peak Throughput
This article explains why the Prefill stage often sets the throughput ceiling of a large language model inference stack, and how to measure real utilization against theoretical hardware peak. It covers three key levers for closing the gap—operator fusion, structure-specialized kernel instances, and precision/cast scheduling—along with a methodology for benchmarking peak utilization correctly, deployment caveats such as numerical regression and fallback paths, and the software-hardware co-design loop needed to make a ~98% peak ratio repeatable.
1. Why the Prefill Stage Sets Overall Throughput
In LLM inference serving, a single request is usually split into two phases: Prefill and Decoding. Prefill processes the entire input in one pass, with high computational density and high parallelism, which makes it a natural fit for saturating the hardware’s matrix compute units. Decoding generates tokens one at a time and is constrained much more by memory bandwidth and access efficiency.
A common pattern in practice: Decoding has the worst perceived latency, but what actually determines the per-device throughput ceiling and the cost efficiency of a cluster is usually whether Prefill can fully saturate the compute.
So one intuitive metric for whether an inference stack is “done right” is the ratio of measured compute to the hardware’s theoretical peak. When that ratio approaches the ~98% range, the compute units are essentially fully utilized, and the remaining questions are no longer “is it fast enough” but “are there still gaps in memory access, scheduling, and precision conversion.”
2. Three Key Levers for Approaching Peak
2.1 Operator Fusion: Fewer Intermediate Tensors and Memory Round Trips
In the attention compute path, normalization, positional encoding, the attention core, and type conversion are often split into separate operators. Every split adds another memory read/write and another kernel launch overhead. Fusing these steps into a single kernel can significantly reduce memory traffic and scheduling overhead, making it the most direct way to speed up Prefill. The typical gains from fusion come from three places: intermediate results stay in on-chip cache, the number of kernel launches drops, and data type conversion no longer consumes a separate pass of bandwidth.
2.2 Specialized Kernel Instances: Tailored to Model Structure
Attention head dimensions, hidden dimensions, and data type combinations vary widely across models. For compatibility, a generic kernel often cannot fully unroll loops or fix tile sizes at compile time. Generating specialized kernel instances for a specific structure (for example, specializing for a common configuration such as a head dimension fixed at 128) lets the compiler apply more aggressive vectorization and pipeline scheduling, and measured utilization is typically clearly higher than the generic path.
Illustrative pseudocode expressing the idea of “dispatching specialized instances by structural features”:
# Illustrative dispatch logic only, not a real APIdef select_kernel(model_type, head_dim, dtype):if model_type == "V41_LIKE" and head_dim == 128:return fused_norm_rope_attn_cast_kernel # fused kernel instancereturn generic_attention_kernel # generic fallback path
2.3 Orchestrating Precision and Type Conversion
Low-precision compute is already mainstream, but the timing of conversion matters. Placing the cast at the tail of the fused kernel and emitting the low-precision result only once avoids the back-and-forth of “compute in high precision, store in low precision, read back in high precision.” At the same time, keeping higher-precision accumulation in numerically sensitive stages such as normalization preserves output quality without sacrificing throughput.
3. How to Measure “Peak Utilization” Properly
- First confirm the definition behind the hardware’s theoretical peak (sparse/dense, precision type); figures under different definitions are not directly comparable.
- Use benchmark cases with fixed input length and fixed batch size to avoid interference from scheduling jitter.
- Record measured values for Prefill and Decoding separately; they are governed by different bottlenecks, and looking at them combined leads to misjudgment.
- Check whether memory-side metrics (bandwidth utilization, cache hit rate) and compute-side metrics are healthy at the same time; looking at only one can easily lead to the wrong conclusion.
4. Deployment Notes
First, fused kernels must come with numerical consistency regression, comparing error bounds layer by layer, to prevent “faster but wrong.” Second, specialized instances cause build artifacts to grow, so a tradeoff is needed between image size and startup latency. Third, the fallback path cannot be omitted; unsupported structural features must degrade smoothly. Fourth, performance conclusions must be tied to a specific hardware and software stack version—talking about peak without the environment is meaningless.
5. Ecosystem View: The Software-Hardware Co-Design Loop
High utilization is never a single-point optimization; it is the result of aligning four things: model structure, kernel implementation, the compiler toolchain, and hardware characteristics. When the model side is willing to adjust operator boundaries for a specific hardware structure, the hardware side provides ample compute and bandwidth, and the middle layer can automatically generate specialized kernels, a ~98% peak ratio becomes a reproducible engineering result rather than a one-off tuning accident. For platform providers, turning this capability into containerized inference services with monitoring, alerting, and logging support is what turns optimization experience from “individual skill” into “infrastructure the whole team can reuse.”
