Multi-Chip LLM Inference: Operator Library Adaptation and Auto-Optimization Practices

    Adapting large language model (LLM) inference to multiple AI accelerator chips often faces the challenge of "operator gaps." This article explores a unified approach to multi-chip operator library adaptation and automatic optimization. It details how to establish a unified operator contract and compilation abstraction to cover 67 required operators across eight chip types. Key practices include rewriting complex operators like Top-K selection and FP8 matrix multiplication, implementing an automatic generation pipeline for production-grade kernels, optimizing end-to-end performance through C++ packaging, and building a comprehensive quality assurance and evaluation system. This path transforms multi-chip adaptation from repetitive manual labor into a reusable engineering practice.

    Multi-Chip LLM Inference: Operator Library Adaptation and Auto-Optimization Practices

    1. Problem Background: Multi-Chip Inference Bottlenecked by “Operator Gaps”

    Large language model (LLM) inference systems typically consist of model graphs, operator libraries, runtimes, communication libraries, and scheduling layers. When a model structure introduces new attention mechanisms, routing strategies, or low-precision quantization paths, the underlying operator libraries must be updated synchronously. Otherwise, the model cannot execute fully on the target chip. For solutions optimized only for a single hardware platform, adding new operators often relies on handcrafted kernels, platform-specific instructions, or proprietary extensions. However, production environments require the same model to run across various AI accelerators, leading to the typical “operator gap” problem.

    The difficulty is not just about “having the operator” but spans three levels. First, operator coverage must be complete: all 67 operators required by the target model must have executable implementations. Second, complex operators must maintain semantic consistency across chips, especially for scenarios involving indexing, masking, numerical errors, and low-precision accumulation, such as Top-K selection, sparse attention, Hadamard transform, and FP8 matrix multiplication. Third, single-operator performance and end-to-end throughput must be achieved simultaneously; otherwise, kernel-level gains will be offset by packaging layers, memory copies, and scheduling overheads.

    In this practice, the operator library achieved full operator coverage across eight types of chips by rewriting with unified compilation abstraction and tensor-level kernel language, eventually adapting to ten types of AI accelerators. This indicates that multi-chip adaptation should not start by “writing a separate set of kernels for each chip type.” Instead, it should first establish portable operator contracts and a unified implementation layer, followed by parameterized tuning for hardware differences.

    2. Overall Solution: Unified Operator Layer and Compilation Abstraction

    The overall solution can be summarized as “unified operator contract + unified compilation abstraction + platform-specific tuning.” First, define a unified interface for all 67 operators required by the target model, including tensor shapes, data types, layouts, precision strategies, dynamic shape constraints, and error code semantics. Second, rewrite operators based on a unified compiler and high-level tensor program abstraction, allowing the same kernel description to be adapted to different chips via backend compilation. Finally, translate portability into production performance through parameter search, kernel fusion, memory access optimization, and packaging layer refactoring.

    The key to this path is converging “hardware differences” into a few tunable parameters rather than spreading them across the business logic of each operator. For example, block size, vectorization width, shared memory usage, pipeline stages, reduction strategies, and index bit-widths can all serve as tuning parameters. Operator semantics, boundary handling, and numerical validation remain unified. This reduces multi-chip maintenance costs and makes automated regression and performance benchmarks comparable.

    In interface design, three points must be emphasized. First, dynamic shapes should be treated as first-class citizens to avoid repeated compilation triggered by batch or sequence length changes during production inference. Second, precision strategies must be explicitly declared, such as how FP8 inputs are accumulated, when to promote to higher precision, and how error thresholds are defined. Third, index-based operators must guarantee deterministic or at least reproducible boundary behavior, preventing unexplainable sorting differences in Top-K selection under tied scores. Only by fixing these contracts first can subsequent auto-generation and performance optimization have a stable foundation.

    3. Complex Operator Rewriting: From Top-K Selection to Five New Operators

    The target model continues the MoE architecture and introduces 5 new operators in attention mechanisms and quantization strategies. To enable execution directly across multiple chips, a tensor-level kernel language within a unified compilation stack was used to reimplement all 5 operators. Among them, Top-K selection is a typical high-difficulty operator: it includes local candidate filtering, cross-block merging, and handling tied scores, index passing, and dynamic K values. A portable implementation usually adopts a “block-level local Top-K + cross-block merge” strategy:

    1. # Pseudocode: Block merge strategy for Top-K selection
    2. def topk_selector(scores, k, block_size):
    3. partial = []
    4. for block in split(scores, block_size):
    5. local_values, local_indices = local_topk(block, k)
    6. partial.append((local_values, local_indices))
    7. values, indices = merge_topk(partial, k)
    8. return values, indices

    The advantage of this strategy is transforming large-scale global selection into multiple local selections plus a single merge, making it easy to map to the parallel reduction units of different chips. Implementation notes: the candidate count for local Top-K should be slightly larger than K to reduce the risk of missing elements during cross-block merging; index types must match the maximum tensor size; tied scores require defined stable sorting rules; small K and large K can use different kernel paths to avoid resource waste from a unified path.

    In addition to Top-K selection, sparse attention, Hadamard transform, and FP8 matrix multiplication are also key. Sparse attention requires handling irregular masks and block-sparse access, focusing on reducing invalid memory accesses and branch divergence. The Hadamard transform emphasizes regular butterfly operations and vectorization, focusing on register reuse and stride access. FP8 matrix multiplication must balance low-precision input, accumulation precision, and output scaling, focusing on tiled matrix multiplication, pipeline loading, and accumulator layout. In this practice, the single-operator performance of these 5 operators on mainstream GPU platforms outperformed handcrafted baselines or native acceleration implementations, proving that unified abstraction does not necessarily sacrifice performance. The key is designing tunable kernel structures tailored to operator forms.

    4. Auto-Generation Pipeline: From Naive Kernels to Production-Ready

    More noteworthy is the production application of auto-generated operators. Among the 5 operators mentioned, sparse attention, Hadamard transform, and FP8 matrix multiplication were produced by an auto-generation pipeline, marking the transition of auto-generated kernels from experimental validation to production inference. The basic process starts with an initial tensor program kernel and reference implementation. In each iteration, an agentic optimization system analyzes the current kernel’s performance bottlenecks and historical optimization data, automatically implements optimization strategies, and completes correctness validation and performance benchmarking, iterating continuously until the target performance is reached.

    For this pipeline to be truly usable, three engineering problems must be solved. First, the correctness closed-loop. Every candidate kernel must be compared against the reference implementation, covering random inputs, boundary shapes, extreme values, and low-precision error scenarios. Only versions passing threshold validation proceed to performance evaluation. Second, the performance feedback closed-loop. The system must record throughput, latency, memory usage, and compilation parameters before and after each optimization to avoid situations where “an optimization strategy is effective but offset by another bottleneck.” Third, the regression closed-loop. Auto-generated results must enter a versioned benchmark library to prevent performance regressions caused by subsequent compiler or tuning parameter changes.

    Results show that the auto-generation path can gradually approach or even surpass handcrafted baselines from naive implementations. Taking FP8 matrix multiplication as an example, it achieved about 2.47x the performance of the handcrafted baseline after multiple rounds of automatic optimization. In benchmark tests of 110 operators, the auto-generation pipeline achieved an approximately 99% generation correctness rate, and about 90.8% of operators exceeded a 100% speedup ratio. These data show that auto-generation is not a simple slogan of “replacing engineers” but rather precipitating engineers’ experience into a searchable, verifiable, and regressive optimization strategy library.

    5. End-to-End Packaging and Tuning: Preventing Call Overhead from Eating Operator Gains

    Comprehensive single-operator performance superiority does not necessarily mean faster end-to-end inference. In actual systems, parameter checking, dynamic dispatching, tensor conversion, and multiple small kernel calls in the Python packaging layer can offset kernel-level advantages. This practice refactored the call path through a C++ packaging layer, improving end-to-end performance by about 39%, and increased end-to-end inference throughput by up to about 11.2% compared to the reference implementation on specific high-end accelerator cards. This indicates that production inference optimization must adhere to a three-tier evaluation: “single-operator benchmark + subgraph benchmark + end-to-end benchmark.”

    The core of the C++ packaging layer is not simply replacing the language but reducing redundant work across language boundaries. A stable ABI C interface can expose operators, batch pass tensor descriptors, reuse memory pools and compilation caches, merge small operator calls, and schedule kernel launches on asynchronous streams. For example:

    1. extern "C" int fp8_matmul(
    2. void* out,
    3. const void* a,
    4. const void* b,
    5. const TensorDesc* desc,
    6. void* workspace);

    This interface exposes only the necessary descriptive information, avoiding high-level object parsing on every call. The workspace is managed uniformly by the runtime, reducing frequent allocations. Meanwhile, the parameter auto-tuning component can search block sizes, pipeline stages, and fusion strategies for different chips, shapes, and batches, caching the optimal configuration into the compiled output. End-to-end optimization also requires attention to operator fusion boundaries: too many small kernels increase launch overhead, while excessive fusion reduces reusability. Therefore, trade-offs must be made based on real model paths.

    6. Quality Assurance and Evaluation System

    Quality assurance for multi-chip operator libraries cannot stop at “just running.” It is recommended to establish four types of evaluation: correctness evaluation covering random inputs, boundary shapes, special values, and low-precision errors; performance evaluation covering single operators, typical subgraphs, and end-to-end tokens/s; stability evaluation covering long sequences, dynamic batches, and repeated executions; consistency evaluation covering numerical errors and index behavior across different chips. For index operators like Top-K selection, tied score handling rules and reproducibility requirements must also be defined.

    Evaluation data should be versioned and bound with compiler versions, tuning parameters, and packaging layer versions. After adding new operators or modifying kernels, tiered benchmarks are automatically triggered. Any change that improves single-operator performance but decreases end-to-end throughput should be flagged for review. Only by integrating “correctness, performance, stability, and portability” into the same regression system can multi-chip operator libraries transition from one-time adaptation to continuous delivery.

    7. Practice Suggestions and Conclusion

    To implement a multi-chip LLM inference operator library, it is recommended to follow this order: first fix operator contracts and precision semantics; then achieve full coverage implementation based on unified compilation abstraction; design separate kernel paths for complex operators like Top-K selection, sparse attention, and low-precision matrix multiplication; use the auto-generation pipeline to expand the optimization search space, backed by reference implementations and regression benchmarks; finally, compress end-to-end overhead through C++ packaging, memory pools, compilation caches, and parameter tuning. The metric for success should not be single-operator peak performance, but end-to-end throughput, latency stability, and regression costs of the target model across multiple chip types.

    Overall, the value of this practice lies in transforming “multi-chip adaptation” from repetitive manual labor into a reusable operator-layer engineering practice: unified abstraction ensures coverage, complex operator rewriting ensures semantics, auto-generation improves optimization efficiency, and packaging layer governance ensures end-to-end gains. For teams needing to deploy LLM inference across multiple AI accelerator chips, this path offers a strong general reference.