Accelerating LLM Inference on Domestic AI Chips: A Model-Hardware Co-Optimization Guide

    This article explains how model-hardware co-optimization turns theoretical chip peak performance into real inference throughput. It covers why single-chip TFLOPS rarely match business throughput, how prefill and decode phases differ in compute-bound versus memory-bound behavior, and which metrics to report for each stage. It then walks through operator fusion, memory layout tuning, expert parallelism and communication overlap, and a reproducible framework for measuring how close a deployment is to hardware limits. The goal is to help teams attribute performance gaps and reduce per-token inference cost without replacing hardware.

    1. Why Model-Hardware Co-Optimization Is the Key Variable for Compute Efficiency

    Over the past few years, most discussions about compute supply have focused on “stacking more cards”: more accelerators, higher-bandwidth interconnects, and larger clusters. But once model architectures stabilize and clusters scale into the thousands or tens of thousands of cards, marginal returns start to diminish. The reason is not mysterious. There is often a several-fold gap between a single card’s theoretical peak compute (TFLOPS) and actual business throughput. That gap does not come from a chip that is “not powerful enough”; it comes from a software stack that fails to fully unlock the hardware’s capabilities.

    Model-hardware co-optimization refers to the joint optimization of model architecture design with the underlying operators, memory hierarchy, and interconnect topology. It has three layers:

    • Operator layer: fusing many fine-grained operations into a few efficient kernel functions to reduce the back-and-forth movement of intermediate tensors;
    • Memory layer: aligning data layout and tiling strategies with the actual parameters of on-chip caches and high-bandwidth memory;
    • System layer: matching parallelism strategies (tensor parallelism, pipeline parallelism, expert parallelism) to interconnect bandwidth and topology.

    When all three layers are aligned, measured throughput converges noticeably toward the theoretical peak. The industry commonly uses “hardware peak utilization” as the metric, calculated as measured TFLOPS divided by the theoretical peak at a given precision. This step is the baseline for all subsequent optimization. Without a baseline, tuning is blind.

    2. Two-Phase Inference: Prefill and Decode Have Completely Different Load Characteristics

    To understand co-optimization, you must first accept one fact: large model inference is not one workload, but two.

    The prefill phase processes the input prompt and is compute-intensive. Matrix multiplications are large and arithmetic intensity is high, so it easily saturates compute. The bottleneck is usually compute and on-chip data supply.

    The decode phase generates output autoregressively token by token and is memory-intensive. Each step processes only one token, and weights and the KV cache must be repeatedly moved from memory. Arithmetic intensity is extremely low, so the bottleneck is usually memory bandwidth and capacity.

    This explains a common puzzle: why the same card running the same model can approach peak performance during prefill but achieve only a fraction of it during decode. It also explains why looking at a single throughput number is meaningless. A rigorous evaluation must report results by phase:

    1. # Illustration: recording phased performance baselines (pseudocode)
    2. metrics = {
    3. "prefill_tflops": measure(prefill_only, batch=B1, seq=S_in),
    4. "decode_tflops": measure(decode_only, batch=B2, kv_len=L),
    5. "peak_util_prefill": prefill_tflops / theoretical_peak(dtype),
    6. "peak_util_decode": decode_tflops / theoretical_peak(dtype),
    7. "mfu_note": "for the decode phase, use bandwidth utilization instead of compute utilization"
    8. }

    For the decode phase, a more appropriate metric is memory bandwidth utilization: measured effective bandwidth divided by nominal bandwidth. If this value is already near the ceiling, further operator optimization yields limited returns. The real path forward is to reduce the amount of data movement—for example, more aggressive KV cache compression, better batch scheduling, or offloading cold data to higher-level storage.

    3. Operator Fusion: Removing “Data Movement” from the Cost Equation

    Attention is where fusion delivers the most concentrated gains. Take multi-head attention as an example. A naive implementation explicitly materializes the attention matrix and then multiplies it by the value vectors, and the intermediate tensor can grow with the square of the sequence length. A fused implementation (commonly known in the industry as FlashAttention-style approaches) uses tiling and online normalization to keep intermediate results on-chip, avoiding writes back to memory.

    The benefits of fusion can be summarized in three points:

    1. Reducing global memory reads and writes, which directly eases bandwidth pressure;
    2. Lowering peak memory usage, making longer contexts and larger batches possible;
    3. Reducing kernel launch overhead, which is especially noticeable in short-sequence, small-batch scenarios.

    Beyond attention, the “element-wise multiply-add + activation + scaling” chain in the feed-forward network and the multiple read/write passes in normalization layers are also fusion candidates. To judge whether an operator is worth fusing, use a simple criterion: estimate its arithmetic intensity (the number of floating-point operations per byte of memory access). If it is significantly lower than the hardware’s “compute/bandwidth” ratio, the operator is memory-bound, and fusion and layout optimization will pay off far more than switching to a card with higher compute.

    Another class of high-value optimization comes from automatic tuning of matrix multiplication: for specific shapes and specific data layouts, search at compile time over tile sizes, pipeline depth, and register allocation strategies to generate specialized kernels. These methods deliver stable gains in serving scenarios with fixed shapes. In scenarios with highly dynamic shapes, they need to be paired with shape bucketing to avoid jitter caused by repeated compilation.

    4. Expert Parallelism and Communication: Bandwidth Is the Real Ceiling

    When a model uses a sparse expert architecture, tokens must be dispatched to different devices according to routing results and then aggregated across devices. These two steps are typical global communication, and their cost is determined by physical bandwidth and topology, not compute.

    Three key actions matter in practice:

    • Overlapping communication with computation: split dispatch/aggregation into small chunks and pipeline them with expert forward computation to hide communication latency;
    • Topology-aware routing: keep the same batch of tokens within a single node as much as possible to reduce cross-node hops;
    • Load balancing: routing skew makes individual devices become long tails, and overall throughput is held back by the slowest one.

    An easily overlooked detail is that the ceiling of communication optimization is set by the hardware’s physical bandwidth. When measured communication time already approaches the theoretical lower bound, continuing to make small tweaks at the algorithm level is inefficient. At that point, you should focus on reducing the communication volume itself—for example, lowering dispatch precision, merging small messages, or adjusting the dimension along which parallelism is split.

    5. A Framework for Approaching Hardware Peak Performance

    To judge whether you have “hit the limit,” you need a reproducible measurement process rather than scattered benchmark runs:

    1. Define the theoretical peak clearly: distinguish nominal compute across different numeric precisions, and avoid comparing a low-precision peak against high-precision measurements;
    2. Fix measurement conditions: record batch size, input and output lengths, KV cache length, parallelism degree, and whether graph capture is enabled;
    3. Report by phase: report compute utilization for prefill and bandwidth utilization for decode;
    4. Run ceiling comparison experiments: use pure-compute and pure-communication microbenchmarks to measure the achievable upper bound of the hardware under the current configuration, then compare against end-to-end results;
    5. Attribute the gap: determine layer by layer whether the gap comes from operator efficiency, scheduling bubbles, communication waits, or memory capacity constraints.

    An illustrative diagnostic output can be organized like this:

    1. [baseline] prefill util=0.86 decode bw_util=0.91
    2. [gap] bubble=0.07 comm_wait=0.05 kernel_eff=0.02
    3. [action] increase batch scheduling granularity / overlap communication / recheck tile sizes

    The value of this framework is that it turns “it feels faster” into “explainably faster” and clearly points to where to invest next.

    6. From Operator Efficiency to Inference Cost: The Transmission Path and Engineering Touchpoints

    Improvements in operator efficiency must ultimately show up in the cost per token. The transmission chain is clear: higher hardware utilization → fewer devices needed for the same throughput → higher output per unit time → lower cost per token. This chain also explains why market attention is extending from “scaling up inference” to “pretraining and large-scale training-inference at the super-node level”: only when the software stack can reliably approach the hardware ceiling will expanding cluster size avoid being diluted by inefficiency.

    On the engineering side, it is worth focusing on four general capabilities (all industry-standard categories, not pointing to any specific vendor): container platforms handle elastic scaling and fault isolation; object storage and message queues handle decoupling of data and tasks; logging services and monitoring alerts provide phased metrics and long-tail diagnosis; and CI/CD pipelines ensure operators and compilation artifacts can be rolled back.

    An executable minimal loop is: first establish a phased baseline, then fuse memory-bound operators, then handle communication overlap and load balancing, and finally use ceiling comparison experiments to confirm whether the remaining gap is worth continued investment. Proceeding in this order typically yields considerable throughput improvement without replacing hardware.

    7. Common Pitfalls

    • Looking at a single throughput number while ignoring phase differences and measurement conditions;
    • Continuing to chase compute utilization in the decode phase when the real bottleneck is bandwidth;
    • Scaling up parallelism without overlapping communication, so bubbles swallow the gains;
    • Frequently triggering compilation in dynamic-shape scenarios, causing latency jitter;
    • Lacking ceiling comparisons, making it impossible to tell whether optimization has approached the physical boundary.

    Conclusion

    The essence of model-hardware co-optimization is using software to convert a chip’s nominal capabilities into business throughput. Operator fusion solves data movement, memory layout solves cache hits, communication overlap solves waiting, and phased measurement solves attribution. With all four in place, measured performance naturally converges toward the peak, per-unit inference cost drops accordingly, and the value of domestic compute infrastructure finally rests on a solid technical foundation.