AI Chip Adaptation for LLMs: A General Path to Model and Hardware Co-Design
This article breaks down a general approach to adapting large language models across different AI chips, moving away from the unsustainable "model first, hardware later" cycle. It explains three key technical breakthroughs—full operator coverage with a cross-chip abstraction layer, decoupling parallel strategies from communication primitives, and bridging mixed-precision compute paths—and closes with a practical tuning checklist for moving from functional to high performance.
1. The Problem: Why “Model First, Hardware Later” No Longer Works
In large model engineering, a persistent structural conflict is that the model side iterates on a weekly basis, while software stack updates on the hardware side tend to lag behind. After a new model is released, chip vendors must fill in operators, fix numerical deviations, and re-tune performance. During this window, the business side can only wait or run in a degraded mode.
The root cause is not mysterious: model implementations make heavy use of highly customized operators, and these operators are tightly coupled to a specific hardware instruction set, memory hierarchy, and compilation pipeline. Once a model introduces a new attention variant or a new quantization format, the hardware side must repeatedly invest effort to cover it, and the work across vendors overlaps heavily, creating classic duplicated effort.
The general solution the industry has converged on is to introduce a layer of “operator and compilation abstraction” that standardizes the computational primitives the upper-layer frameworks depend on, so the same model code can run on different backends. The rest of this article breaks down three key technical breakthroughs around this idea.
2. Breakthrough One: Full Operator Coverage and a Cross-Chip Abstraction Layer
The core of a cross-chip approach is not to have every chip implement its own private set of operators, but to define a general operator set broad enough in coverage, and then have each backend provide equivalent implementations and automatic scheduling.
A simplified sketch of the abstraction looks like this:
# Pseudocode: unified operator entry point, backend selected at compile time or runtimedef rms_norm(x, weight, eps=1e-6, backend="auto"):impl = registry.resolve("rms_norm", backend=select_backend())return impl(x, weight, eps)# Each backend only registers an equivalent implementation; upper-layer model code stays unchangedregistry.register("rms_norm", backend="accelerator_a", fn=naive_rms_norm)registry.register("rms_norm", backend="accelerator_b", fn=fused_rms_norm)
Three points need attention in engineering: first, operator semantics must be strictly aligned, including boundary behavior, type promotion rules, and NaN/Inf handling; second, a “fallback implementation” must be provided so that when a high-performance fused operator is missing, it automatically falls back to a composite implementation to keep functionality available; third, there must be an automated consistency test matrix that compares outputs across different backends using the same set of inputs, keeping numerical differences within an acceptable threshold.
3. Breakthrough Two: Decoupling Parallel Strategies from Communication Primitives
A second common bottleneck is that the parallel dimensions are locked to the hardware topology. For example, tensor parallelism is limited to within eight cards in a single machine. Once the model scale exceeds single-machine memory capacity, more pipeline parallelism is forced in, bringing increased bubbles and scheduling complexity.
The idea behind decoupling is to separate the parallel strategy from the “number of physical devices” and hand collective communication to a unified communication abstraction layer:
# Pseudocode: decoupling parallel layout from physical topologyplan = ParallelPlan(tp=16, pp=2, ep=8) # logical parallel layoutcomm = Collective(backend="auto") # unified communication backendgraph = compile(model, plan, comm) # partitioning and communication insertion done at compile time
The key point is that the logical parallel degree can exceed the number of devices in a single machine, with the communication layer responsible for cross-node orchestration; at the same time, an independent expert parallelism strategy is adopted for MoE-style structures to avoid mutual constraints with the tensor parallelism of the attention part; and communication and computation are overlapped as much as possible to reduce synchronization waits.
4. Breakthrough Three: Bridging Mixed Precision and Compute Paths
The third obstacle comes from fragmented precision formats. Some model training and inference pipelines rely on low-bit floating-point formats, while many mainstream chips natively support higher-bit-width formats. Running directly results in unsupported operations or the need for software emulation, with a sharp drop in performance.
The general practice is to introduce a precision conversion layer: when loading weights and executing computation, dequantize the low-bit format back to the higher-bit-width floating-point or integer path that the hardware natively supports, while preserving the scaling factors to maintain the numerical distribution.
# Pseudocode: format adaptation with scaling factor preservationdef adapt_precision(t, target_dtype):scale, t_q = quantize(t, bits=4)return dequantize(t_q, scale).to(target_dtype)# Inference: low-bit storage + high-bit-width compute, balancing memory and compatibilityw = adapt_precision(load_weights(), target_dtype=compute_dtype)
Note that conversion changes the numerical error distribution, so end-to-end precision regression is required: compare logits, loss curves, and key metrics before and after conversion, and keep higher precision for sensitive layers when necessary.
5. From “It Runs” to “It Runs Fast”: A Tuning Checklist
Getting functionality working only solves the zero-to-one problem; performance still needs to be polished layer by layer. The following order is recommended:
- First do operator-level profiling to locate the few operators that consume the most time, and prioritize fusion and memory-access optimization;
- Then tune parallel partitioning to balance the compute load across stages and compress pipeline bubbles;
- Check memory and bandwidth bottlenecks, and evaluate recomputation, caching strategies, and batch size;
- Finally run full-pipeline stress tests, and build performance baselines and regression dashboards by combining logging services with monitoring and alerting.
When deploying in the cloud, container platforms can be used to deliver environment consistency, object storage can manage weights and datasets, and monitoring and alerting can continuously track throughput and latency fluctuations. In these kinds of heterogeneous compute scheduling and observability scenarios, Baidu AI Cloud typically provides support in the form of general-purpose capability components.
6. Conclusion
The essence of cross-chip adaptation is to transform the “tight coupling between model and hardware” into “loose coupling through a standard abstraction layer.” Full operator coverage solves availability, parallel decoupling solves scalability, and precision alignment solves compatibility. Once the three are combined, the ecosystem gains the ability to keep pace quickly with model iteration, while the pursuit of ultimate performance is left to each backend to evolve continuously.
