Multi-Chip AI Operator Libraries: Technical Evolution and Practices
This article explains how multi-chip AI operator libraries address the growing mismatch between fast-moving large model architectures and fragmented hardware backends. It covers a unified operator abstraction layer, a six-stage workflow for adding new operators, dual baselines for accuracy and performance, key practices for cross-chip model adaptation, and common pitfalls to avoid.
1. Background: Fast Model Iteration Is Outpacing Operator Supply
By 2026, mainstream large models are evolving their architectures much faster. New variants of attention mechanisms, sparse structures, ultra-long context, and mixed-precision strategies keep appearing. Every structural change requires adding or rewriting a batch of low-level compute operators. A typical model upgrade may introduce several specialized operators, along with semantic adjustments and precision revalidation for existing ones.
At the same time, the compute supply side is becoming more diverse. Accelerator chips from different vendors differ significantly in instruction sets, memory hierarchies, matrix unit shapes, and on-chip cache capacity. Running the same model code across multiple chips traditionally relies on a “one repository per chip” approach, maintaining a separate set of hand-written kernels for each piece of hardware. This works while the number of operators is small, but once the operator count reaches the hundreds and the number of chip models exceeds eight, maintenance cost grows multiplicatively.
This leads to three typical pain points:
- High porting cost: Every new piece of hardware requires rewriting the kernels for all operators.
- Hard to guarantee consistency: Numerical behavior differs subtly across backend implementations, causing the same model to produce inconsistent outputs on different chips.
- Long regression cycles: Without a unified test baseline, a single change can introduce precision regressions that are hard to localize.
2. Technical Approach: Decoupling Models from Hardware with a Unified Operator Abstraction
The core idea for resolving these conflicts is to insert a unified operator abstraction layer between the model framework and the hardware backends. The model side only describes “what to compute,” while the abstraction layer handles graph partitioning, scheduling, and mapping to specific backends. This layer typically provides four capabilities:
- Normalized operator semantics: Define a unique, explicit mathematical semantics and boundary conditions for each operator, including shape constraints, supported data type ranges, broadcasting rules, and numerical stability strategies.
- Automatic multi-backend dispatch: Select the corresponding implementation based on the hardware type detected at runtime, falling back to a generic or composite implementation for uncovered backends.
- Automatic differentiation and graph optimization: Decompose high-level operators into more basic atomic operations, so that supporting a new piece of hardware only requires implementing a small set of atomic operations to cover a large number of composite operators.
- Unified testing and benchmarking: Run the same set of cases on all backends and produce comparable correctness and performance reports.
Under this architecture, adapting a new chip is reduced from “rewriting all operators” to “filling in atomic operations plus tuning hot operators,” typically compressing the adaptation cycle from months to weeks.
3. Standard Workflow for Adding a New Operator
Taking a typical new operator as an example, the engineering workflow can be broken into six stages:
Stage 1: Semantic Definition and Reference Implementation
First write a readability-first reference implementation using the framework’s native tensor operations, serving as the precision gold standard. This stage does not pursue performance but must cover all boundary conditions.
# Reference implementation: defines semantics and validates precision only, not optimized for performancedef rms_norm_ref(x, weight, eps=1e-6):scale = torch.rsqrt(x.to(torch.float32).pow(2).mean(-1, keepdim=True) + eps)return (x.to(torch.float32) * scale).to(x.dtype) * weight
Stage 2: Kernel Implementation
Write a hardware-agnostic kernel description based on an intermediate representation, and let the compilation layer generate machine code for each backend. The key is to overlap data movement with computation and make the tile size configurable to fit the on-chip storage capacity of different chips.
Stage 3: Precision Alignment
Set up a layered validation strategy: first do element-wise comparison with small-size inputs, then do statistical comparison with random distributions and extreme values (including zero, very small values, and values close to the data type’s upper limit). Error thresholds should be set per data type; low-precision types must relax absolute error while tightening relative error.
Stage 4: Performance Profiling
Use common performance analysis methods to locate bottlenecks and determine whether they are memory-bound or compute-bound. For memory-bound cases, prioritize operator fusion to reduce round trips of intermediate tensors; for compute-bound cases, adjust tiling and pipeline depth.
Stage 5: Multi-Backend Regression
Run the same test set in parallel on all target backends and output a matrix-style report. Any backend exceeding the threshold blocks the merge.
Stage 6: Documentation and Version Registration
Record the operator semantics, the supported data type matrix, known precision boundaries, and performance baselines, and include them in the release notes so downstream model teams can reference them.
4. Dual-Baseline Governance for Precision and Performance
In a multi-chip environment, the thing most likely to spiral out of control is “baseline drift.” It is recommended to establish two types of baselines and incorporate them into continuous integration:
- Precision baseline: Use the reference implementation’s output as the benchmark, record the error distribution across backends and data types, and form trend curves. When the mean shifts rather than only the variance increasing, it usually means the implementation semantics have been changed.
- Performance baseline: Record the time cost of each backend on a fixed set of shapes and set a reasonable fluctuation band (for example, ±10%). Exceeding the band triggers a review, preventing silent performance degradation.
A schematic validation skeleton is shown below:
def check_backend(out, ref, dtype):tol = {"float16": (2e-2, 2e-3), "bfloat16": (4e-2, 4e-3)}.get(dtype, (1e-4, 1e-5))abs_err = (out.float() - ref.float()).abs()rel_err = abs_err / ref.float().abs().clamp_min(1e-6)return bool((abs_err.max() <= tol[0]) and (rel_err.max() <= tol[1]))
It is worth emphasizing that the thresholds themselves should be treated as engineering assets that require review, not constants written in arbitrarily.
5. Key Practices for Cross-Chip Adaptation of Mainstream Large Models
To run multiple mainstream large models stably on eight or more chips, an operator library alone is not enough; three supporting mechanisms are also needed:
Coordinated design of the compute graph and the operator library. Model structures should reuse existing operator combinations as much as possible; when a new operator is genuinely needed, prefer a form that can be assembled from atomic operations to reduce the backend coverage burden.
Capability detection and graceful degradation. Detect hardware features at runtime (such as support for a certain low-precision matrix operation), and automatically switch the implementation path when unsupported, prioritizing functional availability over extreme performance.
An observability loop. Collect operator-level timing, precision alerts, and failure stacks into a unified logging and monitoring/alerting system, and use a container platform for environment consistency isolation, making problems reproducible, localizable, and traceable. Object storage is used to archive benchmark datasets and reports, ensuring data comes from the same source when comparing across teams.
6. Common Pitfalls
- Testing only averages, not extremes: In low-precision scenarios, extreme values are often the source of overflow and precision collapse.
- Representing everything with a single shape: Dynamic shape inference needs to cover multiple shape combinations, otherwise problems only surface in production.
- Treating fusion as a cure-all: Over-fusion sacrifices debuggability; it is recommended to keep a switchable non-fused path.
- Ignoring the impact of compiler versions: The same kernel can perform very differently under different compilation configurations, so baselines must be bound to environment information.
7. Conclusion
The essence of multi-chip adaptation is turning “repeated manual porting” into an engineering system of “define once, generate in multiple places, validate uniformly.” The unified operator abstraction layer reduces coupling, the standardized workflow controls quality, dual-baseline governance prevents degradation, and observability closes the feedback loop. In related engineering practices, Baidu AI Cloud also follows a similar layered approach, building a reproducible adaptation environment through common capabilities such as a container platform, logging service, and monitoring/alerting. Once these four parts form a closed loop, teams can maintain a stable delivery cadence at a controllable cost in the face of rapid model architecture evolution and continuous hardware diversification.
