Optimizing Large Language Models for Domestic AI Chips: A Model-Hardware Co-Design Guide
This article presents a practical methodology for model-hardware co-optimization to improve inference efficiency on domestic AI chips. It explains how to diagnose whether a bottleneck is compute-bound, memory-bound, communication-bound, or scheduling-bound, outlines a general workflow for adapting fused operators to a new hardware backend, and separates prefill and decode workloads for targeted tuning. It also covers the infrastructure implications of pushing operator efficiency toward hardware peak and provides a deployment checklist centered on cost per token rather than peak FLOPS.
1. Why Model-Hardware Co-Design Is the Key Variable for Compute Efficiency
As the compute supply landscape diversifies, simply adding more accelerator cards delivers rapidly diminishing marginal returns. In real workloads, how well the model structure, operator implementations, communication topology, and hardware characteristics match each other often determines end-to-end throughput more than the hardware’s nominal peak. Model-hardware co-design means the model side and the compute side are designed together at the operator, memory-hierarchy, parallelism-strategy, and scheduling levels, rather than being optimized independently and then stitched together.
A set of self-measured results from the source material is representative: a certain fused attention operator reached over roughly 90% of the hardware peak under a specific configuration; decode-phase throughput was slightly lower than prefill-phase throughput; and a general matrix multiplication and an expert-parallel communication library approached the compute ceiling and the physical bandwidth ceiling, respectively, under specific test configurations. The methodology behind these numbers is more worth borrowing than the numbers themselves.
2. Locating the Bottleneck: Compute-Bound or Memory-Bound First
The most common mistake in performance tuning is attributing all inefficiency to “poorly written operators.” The rigorous approach is to establish a diagnostic framework first:
- Compute-bound: the operator has high arithmetic intensity, and the performance ceiling is determined by floating-point throughput;
- Memory-bound: low arithmetic intensity, with the ceiling determined by memory bandwidth;
- Communication-bound: in distributed settings, synchronization wait time is too high, and the ceiling is determined by interconnect bandwidth and topology;
- Scheduling-bound: kernel launch overhead, too many synchronization points, and load imbalance cause idle spinning.
The diagnostic logic can be sketched as pseudocode:
def diagnose(layer_profile, hw):ratio = layer_profile.flops / max(layer_profile.bytes, 1) # arithmetic intensityif ratio > hw.flops / hw.bandwidth:return "compute_bound", hw.flopsif layer_profile.comm_ratio > 0.3:return "comm_bound", hw.interconnect_bwreturn "memory_bound", hw.bandwidth
Only after identifying the source of the ceiling do subsequent actions make sense: for compute-bound cases, prioritize operator fusion and lower precision; for memory-bound cases, prioritize data-layout rearrangement and cache reuse; for communication-bound cases, prioritize overlap and topology-aware scheduling.
3. A General Methodology for Adapting Fused Operators
Attention is a typical multi-stage computation: projection, scaling, masking, softmax, and weighted summation. If each step is implemented as a separate kernel, intermediate results are repeatedly written back to memory, and memory overhead quickly consumes the compute gains. The core idea of fusion is to keep intermediate values in on-chip storage and reduce round trips.
When adapting to a new hardware backend, it is recommended to proceed in this order:
- Numerical-semantics alignment: define the mask padding value, the softmax numerical-stability strategy, and accumulation precision to avoid precision regressions caused by implementation differences;
- Tiling-strategy design: determine tile sizes based on memory capacity and on-chip cache size, balancing parallelism and data reuse;
- Layout and vectorization: unify the in-memory arrangement of tensors so that load paths are contiguous and strided access is reduced;
- Pipelining and overlap: split load, compute, and write-back into a multi-stage pipeline to hide latency;
- Regression validation: compare element by element against a reference implementation across multiple shapes and precision levels.
It is worth emphasizing that more fusion is not always better. Excessive fusion sacrifices the schedulable space for registers and cache, which can instead lower occupancy. A reasonable criterion is that the memory savings from fusion must exceed the parallelism loss caused by the drop in occupancy.
4. Prefill and Decode: Two Workload Types to Optimize Separately
The prefill phase has high parallelism and is a typical compute-intensive scenario; the optimization focus is blocked matrix-multiplication efficiency and operator-fusion coverage. The decode phase processes only a small number of new tokens per step and must repeatedly read weights and the key-value cache, making it a typical memory-intensive scenario; the optimization focus is cache management, batch aggregation, and quantization-based compression.
The evaluation system must therefore be tiered:
- Prefill: observe tokens processed per unit time and compute utilization;
- Decode: observe per-step latency, cache hits, and bandwidth utilization;
- End-to-end: observe the joint distribution of time to first token and output tokens per second.
Reporting both workload types as a single average is the most common measurement error in practice.
5. The Engineering Meaning of Approaching Hardware Peak
When operator efficiency rises from 60% to over 90%, the result is not a linear-proportion gain for the whole machine, but a “reduction in the number of cards required for the same throughput.” This has far-reaching implications for infrastructure planning: a lower per-token inference cost means the same budget can support a larger-scale online service. At the same time, efficiency gains make large-scale training and inference in a supernode form factor more feasible, creating a positive loop between model-capability iteration and compute investment.
Supporting architectural measures include: high-speed interconnect and topology-aware scheduling, high-density cooling solutions such as liquid cooling, tiered storage and data-loading pipelines, and an observability system spanning from the operator level to the service level (metric collection, log aggregation, tracing, and alerting). These are general capability categories, and specific implementations should be selected based on your own environment.
6. Deployment Checklist
- Have you established performance baselines and ceiling models segmented by workload type;
- Have fused operators passed regression across multiple shapes and precisions;
- Is communication effectively overlapped with computation, and is topology perceived by the scheduler;
- Do you have end-to-end observability from hardware metrics to business metrics;
- Do you use cost per token rather than peak compute as the final evaluation metric.
7. Conclusion
The essence of model-hardware co-design is turning “hardware peak” into “business-usable throughput.” When the model side and the compute side are designed together at the system level, operator efficiency, communication efficiency, and scheduling efficiency improve in tandem, and the value-assessment logic for domestic compute infrastructure shifts from pure scale expansion toward continuous optimization of efficiency and cost.
