Engineering Practices for Large Model Inference on Domestic AI Chip Clusters
This article examines the engineering practices required to serve large model inference at scale on domestic AI chip clusters. It covers building a hardware abstraction layer to decouple model code from accelerators, three-tier compilation and operator optimization with mixed-precision and quantization strategies, distributed parallelism aligned with physical interconnect topology, service governance mechanisms such as dynamic batching, priority queues, rate limiting, elastic scaling and fault isolation, and observability plus capacity planning. The goal is to show how teams can sustain stability, latency targets and unit cost under real production traffic on self-developed compute.
1. The Real Problem: Production Traffic Is the Ultimate Test of Compute
Industry discussions of model capability tend to focus on offline benchmarks. In production, however, what determines whether a service succeeds is stability, latency distribution and unit cost under massive real traffic. The core premise here is that a model’s serving stack already runs entirely on domestic AI chip clusters, which means the operator library, compilation toolchain, communication library and scheduler must all be adapted end to end.
The difficulty is not whether the workload runs at all, but whether it keeps running under high concurrency, long-tail requests and sudden traffic spikes. Three characteristics of real traffic continuously amplify low-level problems:
- Long-tail distribution: Input lengths vary enormously, with short requests mixed alongside very long contexts, causing batching efficiency to fluctuate sharply.
- Burstiness and tidal patterns: Traffic spikes within seconds, and scaling out is often slower than traffic growth.
- Failures are the norm: Anomalies in a single card, node or switch link are inevitable events, not low-probability ones.
Running a service fully on domestic chip clusters is therefore essentially a systems engineering effort to contain uncertainty.
2. Hardware Abstraction Layer: Decoupling Application Code from the Chip
Domestic chips differ in instruction sets, memory hierarchies and interconnect topologies. If application code binds directly to low-level interfaces, migration costs become unmanageable. The more robust approach is to introduce a unified hardware abstraction layer (HAL) that consolidates device management, memory allocation, and stream and event semantics behind one internal interface.
# Illustration: a unified device abstraction that hides differences between acceleratorsclass Accelerator:def __init__(self, device_id: int):self.device_id = device_idself.backend = self._detect_backend() # detected at runtimedef _detect_backend(self):# illustrative only, not bound to any specific vendor APIreturn "domestic_backend"def alloc(self, size_bytes: int):return self.backend_alloc(size_bytes)def synchronize(self):return self.backend_sync()
The abstraction layer delivers three things: model code is written against unified semantics; adding a new chip model requires only a backend plugin; and multiple backends can be compared under the same application logic through canary rollouts, so traffic allocation is decided by data rather than subjective judgment.
3. Compilation and Operator Optimization: From “It Computes” to “It Computes Fast”
Unlocking the compute of domestic chips depends heavily on compilation quality and operator implementations. In practice, a three-tier optimization system is usually needed:
- Graph-level optimization: Operator fusion, constant folding and layout transformation to reduce round trips of intermediate tensors to device memory.
- Operator-level optimization: Combined manual and automatic tuning for hot operators such as attention, normalization and activation functions.
- Precision strategy: Mixed precision and quantization in inference, backed by layer-by-layer error evaluation so that precision regressions do not degrade output quality.
Quantization is not a one-size-fits-all decision. Numerically sensitive stages such as attention scoring and Softmax typically retain higher precision, while the large matrix multiplications in fully connected layers can be compressed to narrower bit widths more aggressively. A “precision–latency–throughput” benchmark dashboard is recommended, and no optimization should ship without passing regression evaluation.
4. Distributed Parallelism: Communication Becomes the New Bottleneck
Once the model exceeds the memory of a single card, a parallelism strategy becomes mandatory. Common combinations include tensor parallelism, pipeline parallelism and data parallelism. Interconnect bandwidth and topology on domestic clusters affect the payoff of each split, so the partitioning scheme must align with the physical topology:
- Keep tensor parallelism, which is the most communication-intensive, within the high-speed interconnect domain of a single machine.
- Split pipeline parallelism by layer, using micro-batches to fill pipeline bubbles.
- Use data parallelism for throughput scaling, with gradient accumulation to control peak memory usage.
request -> router -> [tensor parallel group (intra-node)] -> [pipeline parallel (inter-node)] -> sampling and post-processing
One frequently overlooked detail: higher parallelism is not always better. Communication overhead grows non-linearly with the degree of parallelism, so the inflection point must be found through measurement rather than copied from rules of thumb.
5. Service Governance: Stability Under High Concurrency
Stability under real traffic comes from governance, not from hardware alone. The key mechanisms include:
- Dynamic batching: Aggregate requests under a latency constraint with a maximum wait window, balancing throughput against time to first token.
- Priority queues: Separate interactive requests from offline batch jobs so long requests do not block short ones.
- Rate limiting and degradation: Token bucket limiting at the gateway, plus queue depth caps and fast failure in the inference layer.
- Elastic scaling: Scale on multiple signals such as queue length, concurrency and memory watermark rather than a single CPU metric.
- Fault isolation: Cell-based deployment that partitions traffic into independent units so a single point of failure does not spread globally.
Canary releases matter just as much. A new model version or newly compiled artifact is first validated on a tiny fraction of traffic, with latency percentiles (P95/P99) and error rate observed before the share is gradually increased.
6. Observability and Capacity Planning
There is no optimization without measurement. At minimum, collect four categories of metrics: request-level latency distribution, throughput and concurrency, memory and compute utilization, and sampled output quality scores. Logs, metrics and traces should be correlated under the same request identifier, making it possible to trace an anomalous output back to the specific node and batch composition.
For capacity planning, estimate a baseline as “peak concurrency × average resource usage per request × safety factor,” then calibrate with load testing. The safety factor must cover burst traffic, capacity lost to node failures, and the overhead of running two versions concurrently during rolling upgrades.
7. Conclusion
Serving massive real traffic entirely on domestic AI chip clusters is not a one-off adaptation exercise but a continuously iterated engineering system: isolate differences with a hardware abstraction layer, unlock compute through compilation and operator optimization, match parallelism to topology, guarantee stability through service governance, and drive decisions with observability. Baidu AI Cloud has long invested in general-purpose capabilities for heterogeneous compute scheduling and inference service governance, and this methodology applies equally to any team running high-concurrency large models on self-developed compute.
