Adapting Large Language Models to Chinese AI Chips: Engineering Practices and Technical Challenges

    Deploying large language models on Chinese-developed AI chips requires more than basic model compatibility. This article examines operator support, numerical precision, quantization, inference engines, and compiler integration. It also outlines a staged adaptation workflow, performance optimization priorities, and troubleshooting practices for reliable single-device and distributed inference.

    1. Background: Why Adapt LLM Inference to Chinese AI Chips?

    As large language models have grown from billions to trillions of parameters, compute capacity, accelerator memory, and interconnect bandwidth have become major deployment constraints. At the same time, more organizations are exploring Chinese-developed AI chips as a way to build inference infrastructure with greater control over their hardware and software stack.

    Three factors drive this interest:

    1. Supply chain resilience: Fluctuations in general-purpose GPU availability encourage organizations to evaluate alternative compute platforms. The availability and maturity of Chinese AI chips are key considerations.
    2. Cost optimization: Techniques such as quantization and sparsity can make these chips cost-effective for certain inference workloads.
    3. Policy and compliance: Some industries have specific requirements for data residency and control over compute infrastructure. In these settings, locally developed hardware and software may be necessary.

    However, getting a model to run on a chip is very different from serving production workloads reliably and efficiently. This article breaks down the engineering work needed to bridge that gap.

    2. Core Challenges in Model Adaptation

    2.1 Operator Compatibility

    Although many LLMs share a decoder-only Transformer architecture, implementation details can significantly affect operator compatibility:

    • Attention variants: Grouped-query attention (GQA), multi-head latent attention (MLA), and sliding-window attention require corresponding kernel implementations in the inference engine.
    • Normalization layers: RMSNorm and LayerNorm differ in their implementation details and numerical precision requirements.
    • Activation functions: Composite activations such as SwiGLU benefit from fused operators. Without fusion, they introduce additional memory reads and writes.

    A common engineering approach is to validate a minimal execution path first, such as a single-layer forward pass. Next, compare numerical outputs layer by layer, then perform end-to-end validation.

    Numerical comparisons typically examine per-tensor absolute and relative errors. For example:

    1. def check_tensor(ref, out, atol=1e-3, rtol=1e-2):
    2. diff = (ref - out).abs()
    3. assert torch.allclose(ref, out, atol=atol, rtol=rtol), \
    4. f"max diff: {diff.max().item()}"

    2.2 Precision and Quantization Trade-offs

    LLM inference commonly uses reduced precision. FP16 and BF16 are mainstream baselines, while INT8 and INT4 quantization can further reduce resource costs. Support for these formats varies across Chinese AI chips, so adaptation must account for several factors:

    • BF16 support: If a chip lacks native BF16 support, switching to FP16 can change numerical behavior relative to the trained model and may require recalibration.
    • Quantization compatibility: Combinations of weight quantization, including per-channel and group-wise schemes, and activation quantization must match the characteristics of the chip’s integer compute units.
    • KV cache precision: For long-context workloads, KV cache storage precision directly affects memory consumption and achievable throughput.

    2.3 Inference Engines and Compiler Stacks

    A common approach is to use a unified inference framework to abstract hardware differences, with chip-specific compute backends underneath. Most adaptation work falls into three areas:

    1. Operator development and fusion: Implement high-performance kernels for hotspots such as attention and general matrix multiplication (GEMM), making effective use of on-chip memory and vector processing units.
    2. Graph compiler optimization: Validate the correctness of passes such as constant folding, operator fusion, and memory planning on the target hardware.
    3. Scheduling: Prefill is generally compute-intensive, while decoding is generally memory-access-intensive. The two phases require different batching and scheduling strategies.

    3. A Typical Adaptation Workflow

    A structured adaptation process usually consists of five stages.

    Stage 1: Align the Environment and Dependencies

    Verify compatibility among chip drivers, runtimes, and compiler toolchain versions. This step is easy to overlook but is a frequent source of failures.

    Stage 2: Convert Model Weights

    Convert training-exported weights, often stored in a safe, sharded format, into a format supported by the inference engine. This stage also includes adapting tensor layouts and performing quantization calibration where needed.

    Weight layout conversion serves a similar purpose to layout changes such as NHWC versus NCHW: it arranges data to match the execution backend’s requirements.

    Stage 3: Validate Single-Device Functionality

    Start with small batches and short sequences to verify the generation workflow. Then gradually increase context length and concurrency.

    Stage 4: Tune Performance

    Focus on three metrics:

    • Time to first token (TTFT)
    • Time per output token (TPOT)
    • Throughput

    Typical optimization techniques include:

    1. - Enable continuous batching to improve utilization through dynamic batching.
    2. - Schedule prefill and decode separately to reduce interference.
    3. - Use paged KV cache management to reduce accelerator memory fragmentation.
    4. - Use sparse or sliding-window attention for long sequences where supported by the model.

    Stage 5: Deploy Across Multiple Devices

    Very large models require partitioning across accelerators, using combinations of tensor parallelism, pipeline parallelism, and expert parallelism.

    At this stage, interconnect bandwidth and the maturity of communication libraries become decisive factors in overall performance.

    4. Common Problems and Troubleshooting

    The following issues frequently arise during adaptation:

    • Garbled or repetitive output: Mismatched sampling parameters or numerical precision issues are common causes. Start by fixing the decoding method to greedy decoding and comparing results against a reference implementation.
    • Out-of-memory errors with long inputs: Check the KV cache management strategy first. Then consider context chunking and cache eviction mechanisms.
    • Lower-than-expected throughput: Use profiling tools to locate bottlenecks. Attention and GEMM often account for most execution time. If these operators are already well fused, review the batching strategy.
    • Poor multi-device scaling: If communication accounts for too much execution time, adjust the granularity of parallel partitioning or overlap communication with computation.

    5. Conclusion

    Deploying LLMs on Chinese AI chips is fundamentally a matter of software stack maturity. Operator libraries, compilers, inference frameworks, and communication libraries must work together, and a weakness in any layer can become a major bottleneck.

    For developers, a practical progression is:

    Numerical alignment → Functional validation → Performance tuning → Distributed scaling

    General-purpose cloud capabilities can help reduce surrounding infrastructure work. Object storage can manage model weights, container platforms can standardize deployment environments, and monitoring and alerting can support stable inference services. This allows engineering teams to focus on the core adaptation and optimization tasks.

    As hardware and software continue to be optimized together, the maturity of LLM inference on Chinese AI chips is improving. Continued evaluation and hands-on validation remain essential.