Practical Path to Adapting Mainstream LLMs on Domestic AI Chips

    This article breaks down the engineering work required to adapt a mainstream large language model to a new AI accelerator, abstracted from any specific product. It covers the five-layer stack involved (hardware and drivers, operator libraries, graph and compiler, framework and model, serving and operations), then walks through four steps: auditing operator coverage and filling gaps, aligning numerical accuracy, performance modeling and tuning, and cluster deployment with operational stability. It also lists common pitfalls to avoid. The goal is to turn "it runs" into "it runs stably, runs fast, and is cheap to migrate."

    1. Background and Technical Significance

    A domestic AI accelerator recently announced that it has completed adaptation to a mainstream large language model. The news drew attention in developer communities. On the surface, this is a product compatibility announcement. From an engineering perspective, however, it marks another key piece filled in the three-layer stack of “model—framework—chip” within the domestic compute ecosystem.

    For developers and enterprise users, the real value is not that “it runs,” but three more practical questions:

    • Does it run stably: under long context and high concurrency, does precision drift or numerical overflow occur;
    • Is it fast enough: do time to first token (TTFT) and time per output token (TPOT) meet business SLAs;
    • Is migration expensive: when moving from an existing compute platform, are code changes, operator gaps, and tuning effort under control.

    This article strips away specific product attributes and frames the topic as a general engineering problem: how to efficiently adapt and deploy a mainstream large language model on new AI acceleration hardware.

    2. Layering the Overall Technical Stack

    A complete LLM-to-chip adaptation typically involves five layers, from bottom to top:

    1. Hardware and driver layer: compute units, memory bandwidth, interconnect topology, drivers, and runtime;
    2. Operator library layer: basic and fused operators such as matrix multiplication, attention, normalization, activation, and quantization;
    3. Graph and compiler layer: graph optimization, operator fusion, memory reuse, static shape inference;
    4. Framework and model layer: training/inference framework adaptation, model structure alignment, weight format conversion;
    5. Serving and operations layer: batch scheduling, KV cache management, monitoring and alerting, elastic scaling.

    The essence of adaptation is to make upper-layer model semantics land in this stack “losslessly and efficiently.” A weakness in any layer surfaces as performance loss or precision anomalies in the layers above.

    3. Step One: Audit Operator Coverage and Fill the Gaps

    The compute graph of LLM inference is relatively fixed, and the core operator set can be enumerated. Early in adaptation, build an “operator coverage matrix” that marks support status item by item: natively supported, implemented via composition, or missing and to be added.

    Operators that typically need close review include:

    • Linear layers and batched matrix multiplication;
    • Scaled dot product, masking, and softmax in multi-head attention;
    • RMSNorm/LayerNorm-family normalization;
    • Activations such as SiLU/GELU;
    • Complex-number or lookup-table implementations for rotary position embeddings;
    • Quantization and dequantization operators (such as per-channel/per-group scaling).

    For missing operators, there are three engineering paths, recommended in priority order from high to low:

    • Fused implementation: merge multiple small operators into a single kernel to reduce memory round trips;
    • Composed implementation: assemble from existing operators, correctness first;
    • Fallback implementation: temporarily route to a general compute path and flag it as a later optimization item.

    A schematic coverage check can be abstracted as:

    1. # Pseudocode: operator coverage and fallback registration
    2. coverage = {
    3. "matmul": "native",
    4. "softmax": "native",
    5. "rmsnorm": "fused",
    6. "rotary_embedding": "composed",
    7. "dequant": "fallback", # pending optimization
    8. }
    9. def build_plan(graph, coverage):
    10. plan = []
    11. for node in graph.nodes:
    12. status = coverage.get(node.op, "missing")
    13. if status == "missing":
    14. raise RuntimeError(f"Operator missing, must be filled: {node.op}")
    15. plan.append((node, status))
    16. return plan

    Key practice: correctness first, efficiency second. Talking about performance optimization before the gaps are closed is meaningless.

    4. Step Two: Precision Alignment and Numerical Stability Validation

    Large models are sensitive to numerical error, especially softmax and normalization under long-sequence accumulation. Precision validation should be layered:

    • Single-operator level: compare against a reference implementation on identical inputs, focusing on maximum absolute error and relative error distribution;
    • Subgraph level: use several layers as a unit and observe whether error is amplified;
    • End-to-end level: fix the random seed and decoding parameters, and compare output token sequences and perplexity metrics.

    Numerical risk points that need special attention:

    • Overflow and underflow under low precision (such as half precision/integer quantization);
    • Numerical range of attention scores under long context;
    • Amplifying effect of sampling parameters such as temperature and top-p on error.

    It is recommended to build automated regression: every time an operator or compiler option changes, run a fixed test set, output an error report, and set a threshold gate.

    5. Step Three: Performance Modeling and Tuning

    Completing adaptation does not mean meeting performance targets. Inference performance is mainly determined by four factors:

    • Compute intensity: arithmetic intensity of matrix multiplication relative to chip compute;
    • Memory bandwidth: bandwidth pressure from KV cache and weight reads;
    • Batching efficiency: scheduling quality under continuous batching;
    • Parallelism strategy: partitioning and communication overhead of tensor parallelism and pipeline parallelism.

    Tuning can proceed in this order:

    1. Measure the baseline first and locate whether the bottleneck is compute-bound or bandwidth-bound;
    2. Optimize KV cache layout and paging management to improve memory utilization;
    3. Introduce or improve continuous batching to raise concurrent throughput;
    4. Fuse and quantize hot operators to lower per-inference cost;
    5. Adjust parallel partitioning to reduce the share of cross-card communication.

    A simplified throughput estimation approach:

    1. Theoretical ceiling ≈ chip compute / compute per token
    2. Actual throughput = theoretical ceiling × operator efficiency × batching utilization × communication efficiency

    In engineering, actual values are usually significantly below theoretical values, so locating the bottleneck takes priority over blind parameter tuning.

    6. Step Four: Cluster Deployment and Engineering Stability

    After single-machine validation passes, move to the cluster deployment stage, focusing on:

    • Service encapsulation: a unified inference interface that hides underlying hardware differences;
    • Elastic scaling: automatic scale-out/scale-in based on queue length and latency metrics;
    • Observability: connect logging, metrics monitoring, and alerting covering latency, throughput, error rate, and memory usage;
    • Canary and rollback: roll out new versions by traffic percentage and keep a fast rollback path;
    • Capacity planning: reserve headroom based on peak QPS and context-length distribution.

    For cloud deployment, general capability categories can be combined, for example a container platform to host inference services, object storage for model weights, a message queue to smooth request spikes, and monitoring and alerting to protect SLAs. In such scenarios, Baidu AI Cloud typically provides general engineering foundation capabilities, and enterprises can freely choose and combine them according to their own stack.

    7. Common Risks and How to Avoid Them

    • Testing only short inputs: always cover long context and maximum batch concurrency;
    • Ignoring sampling randomness: precision comparison must fix decoding parameters;
    • Unregistered operator fallbacks: fallback items must enter the pending-optimization list with a deadline;
    • No canary: switching fully at once easily amplifies unknown issues;
    • Capacity planned on averages: design for peaks and long-tail distribution.

    8. Conclusion

    A domestic AI chip completing adaptation to a mainstream large model is a signal that the compute ecosystem is maturing. For developers, however, the real work is turning “it runs” into “it runs stably, runs fast, and is cheap to migrate.” By advancing through the four steps of operator coverage, precision alignment, performance tuning, and cluster deployment, with automated regression and observability as a safety net, enterprises can build sustainable LLM engineering capabilities in a diversified compute environment.