Engineering Practices for Pushing LLM Inference Performance Toward Hardware Peak

    \$\$This article explains why approaching hardware peak utilization is a systems-level engineering outcome rather than a single tuning trick. It clarifies key definitions such as theoretical peak, utilization, and the distinct bottlenecks of the Prefill and Decode stages, then walks through four practical levers: operator fusion, memory hierarchy and bandwidth governance, shape specialization and new hardware adaptation, and parallelism aligned with hardware topology. It also covers the software-hardware co-design feedback loop and provides a reusable performance acceptance template, helping developers assess how far their inference service is from peak and where to optimize next.

    \$\$## 1. The Problem: Why “Approaching Peak” Reflects Overall Engineering Capability

    In discussions of large model inference performance, a frequently cited metric is “hardware peak utilization.” It measures the ratio between the floating-point throughput actually achieved and the chip’s theoretical peak. When results such as “the Prefill stage reaches over 90% of hardware peak” appear, what truly deserves attention is not the number itself, but the full set of conditions that must hold simultaneously behind it: whether the compute-to-memory-access ratio is matched, whether operators are decomposed finely enough, whether intermediate tensors repeatedly travel back and forth to GPU memory, and whether parallel partitioning aligns with the hardware topology.

    In other words, high utilization is not “tuned” through a single-point technique. It is the combined result of system design, operator implementation, memory hierarchy management, and scheduling strategy. From a general technical perspective, this article abstracts a transferable methodology that helps developers determine, on any compute platform, “how far my inference service is from peak, and what to change next.”

    2. Clarifying the Definitions First: Peak, Utilization, and Two-Stage Inference

    2.1 Two Meanings of Theoretical Peak

    Before discussing utilization, the denominator must be defined. There are two common conventions: one is the nominal compute of dense matrix multiplication (usually expressed as multiply-add throughput at a specific precision); the other is a higher nominal value that includes sparse acceleration. Mixing conventions makes cross-platform comparison meaningless. The rigorous approach is to state clearly in the report the precision, matrix size, whether sparsity is counted, and the measurement tool and warm-up strategy.

    2.2 The Essential Difference Between Prefill and Decode

    Autoregressive inference has two stages with completely different bottlenecks:

    • Prefill: processes the entire input at once, with large matrix sizes and high arithmetic intensity. It is compute-bound and naturally more likely to approach compute peak.
    • Decode: generates only one token per step, with matrices degenerating into tall, thin shapes and low arithmetic intensity. It is memory-bandwidth-bound, and utilization is usually significantly lower than Prefill.

    Therefore, “Prefill reaching over 90% while Decode is around 80%” is a normal pattern consistent with physical laws, not an optimization failure. Understanding this avoids misallocating optimization effort to the wrong stage.

    3. The First Lever to Approach Peak: Operator Fusion

    3.1 Why Fusion Works

    A naive implementation splits normalization, positional encoding, attention, and type conversion into multiple independent operators. Each additional operator boundary adds another write and read of intermediate tensors to and from GPU memory. In memory-bound scenarios, these round trips are often the main overhead. The core benefit of fusion is to keep intermediate results in on-chip cache or registers, compressing multiple memory accesses into one.

    A typical fused attention pre-processing flow can be illustrated as follows (pseudocode, expressing only the fusion idea):

    1. # Unfused: multiple round trips to GPU memory
    2. x = norm(x)
    3. x = apply_rope(x, pos)
    4. q, k, v = split(x)
    5. o = attention(q, k, v)
    6. out = cast(o, dtype=compute_dtype)
    7. # Fused: norm + rope + attention + cast completed inside a single operator
    8. out = fused_norm_rope_attention(x, pos, dtype=compute_dtype)

    3.2 The Cost and Boundaries of Fusion

    More fusion is not always better. It brings increased register pressure, code branch explosion, and reduced maintainability. A more robust engineering criterion is to prioritize fusing segments that are “memory-intensive with fixed logic” (normalization, positional encoding, type conversion), keep readable implementations for parts with variable logic, and use benchmarks to confirm the benefit is positive.

    4. The Second Lever: Memory Hierarchy and Bandwidth Governance

    Optimizing the Decode stage is almost equivalent to bandwidth governance. Actionable general techniques include:

    • KV cache compression and quantization: reduce the number of bytes that must be moved per step;
    • Paged cache management: reduce fragmentation and redundant copies;
    • Batching and continuous batching: amortize the cost of weight reads with higher concurrency;
    • Data layout alignment: align access patterns with cache lines and memory channels to avoid cross-channel penalties.

    To judge whether this layer needs attention, a simple estimate can be used: divide the minimum bytes of weights and cache that must be read per generated token by the measured bandwidth to obtain a theoretical lower bound. If the measured time is far above this lower bound, the bottleneck lies in scheduling or layout rather than physical bandwidth.

    5. The Third Lever: Shape Specialization and New Architecture Adaptation

    5.1 Specialized Instantiation Rather Than General Kernels

    General kernels often carry many branches and conservative tiling strategies to cover all shapes. When the model structure is stable (for example, the attention head dimension is fixed at a common value), instantiating a kernel specifically for that shape can remove branches, fix loop bounds, and improve vectorization efficiency. This is also a common reason why “utilization jumps after a new model version is adapted to new hardware”: it is not that the hardware became stronger, but that the kernel was finally specialized for this shape and this hardware together.

    5.2 A Checklist for New Hardware Adaptation

    When facing a new architecture chip, it is recommended to proceed in the following order:

    1. Precision and numerical consistency regression to ensure reproducible results;
    2. Confirm the memory access path (cache, channels, alignment);
    3. Benchmark key operators one by one to locate the weakest link;
    4. Apply fusion and specialization only to the weakest link;
    5. Run end-to-end stress tests, observing utilization and tail latency changing together.

    6. The Fourth Lever: Parallelism Strategy and Topology Alignment

    The partitioning of tensor parallelism, pipeline parallelism, and expert parallelism must match interconnect bandwidth and topology. Partitioning too finely introduces frequent communication; partitioning too coarsely causes load imbalance. The general principle is to place partitions with heavy communication within high-bandwidth domains, place partitions with light communication across domains, and decide partition granularity based on measured communication proportion rather than intuition.

    7. The Ecosystem Perspective: How the Software-Hardware Co-Design Loop Forms

    A clear trend in recent years is that adaptation between the model side and the hardware side is moving from “post-hoc porting” toward “co-design”: model teams publish operator implementations and adaptation records, and hardware teams optimize compilation and operator libraries accordingly, forming a verifiable loop. For adopters, this means “adaptation maturity” should be included as an evaluation dimension when selecting, including whether there is an officially maintained operator path, whether there are reproducible performance report conventions, and whether the community can provide shape specialization support. When deploying in the cloud, general capabilities such as container platforms, image repositories, monitoring and alerting, and log services can be combined to connect adaptation versions, benchmark results, and online metrics, forming a sustainable performance baseline for regression.

    8. A Reusable Performance Acceptance Template

    It is recommended that teams fix an acceptance template to avoid “it feels faster”:

    • Environment: chip model, driver and compiler stack versions, precision;
    • Convention: definition of theoretical peak, whether sparsity is included;
    • Segmented metrics: Prefill throughput and utilization, Decode throughput and utilization;
    • Stability: number of warm-ups, number of repetitions, variance;
    • Regression: difference from the previous version and attribution conclusions.

    9. Conclusion

    Approaching hardware peak is never the credit of a single technique, but the product of the chain “clear definitions — bottleneck localization — fusion and specialization — topology alignment — continuous regression.” Looking at Prefill and Decode separately, calculating memory access and compute separately, and binding optimization actions to the weakest link is the correct way to make high utilization explainable, reproducible, and maintainable.