Engineering Practices for Large Model Inference on Domestic Chip Clusters
This article walks through the engineering work required to run large model inference on domestic accelerator clusters, going beyond a simple hardware swap. It covers the compilation pipeline from model to chip, continuous batching and scheduling for balancing throughput and latency, service orchestration with metric-driven autoscaling, stability governance with tiered degradation and full-link observability, and a four-phase rollout path from operator inventory to cost optimization.
1. Why Real Traffic Is the Ultimate Test of Compute
Many teams see solid throughput numbers in a benchmark environment, then hit spiking tail latency, collapsing batching efficiency, and slow failure recovery the moment they go live. The reason is that test traffic is usually short requests of a single length with no bursts, while real business traffic is bursty, long-tailed, and multi-tenant. Moving large model inference to a domestic chip cluster is not a simple hardware replacement; it is a systems engineering effort spanning the compilation pipeline, operator libraries, scheduling strategy, and operations.
So the goals need to be stated up front:
- Functional equivalence: output quality does not degrade because the compute platform changed.
- Performance targets: peak concurrency is met under the agreed latency constraints.
- Stability and control: canary release, rollback, rate limiting, and degradation are all available.
- Explainable cost: cost per token and resource utilization can be quantified and observed.
2. Compute Adaptation Layer: The Compilation Pipeline from Model to Chip
The software stack of a domestic chip usually differs from the general-purpose ecosystem, so lifting inference code over directly often either fails to run or loses most of its performance. The recommended approach is a layered structure of “intermediate representation plus multi-backend compilation” that decouples the model definition from the hardware backend.
# Example: unified model description + backend abstractionclass InferenceBackend:def compile(self, model_ir, precision="bf16"):raise NotImplementedErrordef run(self, batch):raise NotImplementedError# The application depends only on the unified interface;# the backend can be implemented for different domestic acceleratorsbackend = load_backend("domestic_accelerator_x")engine = backend.compile(model_ir, precision="bf16")
The key points are:
- Operator coverage audit: list how every operator used by the model is supported on the target chip, and provide equivalent replacements or fallback paths for missing ones.
- Numerical precision strategy: prefer half precision or mixed precision, but validate quality loss on the business evaluation set.
- Graph optimization: constant folding, operator fusion, and layout conversion to reduce memory access and scheduling overhead.
3. Inference Engine and Batch Scheduling: Balancing Throughput and Latency
Compute utilization for large models depends heavily on the batching strategy. Static batching is simple to implement but causes head-of-line blocking when long and short requests are mixed. The common industry approach is continuous batching: a slot is released as soon as a request finishes, and new requests are inserted immediately, which significantly raises accelerator occupancy.
Scheduling loop (pseudocode)while serving:batch = scheduler.form_batch(max_tokens=..., max_batch_size=...)outputs = engine.run(batch)for req, out in zip(batch, outputs):if out.finished:stream.send(req.id, out.token)scheduler.release(req.id)else:scheduler.requeue(req, out.kv_state)
Three caches and queues matter alongside this:
- Prefix caching to reuse intermediate state for identical system prompts.
- Paged key-value caching to reduce memory fragmentation.
- Priority queues to protect latency for high-value workloads during peak periods.
If speculative decoding or similar acceleration is introduced, evaluate the gains against the actual business distribution, so it does not add overhead in long-tail scenarios.
4. Service Orchestration and Elastic Scaling
On a container platform, inference services are usually split into a gateway layer, a scheduling layer, and an execution layer. The gateway handles authentication, rate limiting, and routing; the scheduling layer maintains request state and batching windows; the execution layer is grouped into compute pools, each pool corresponding to one type of accelerator and one set of compiled artifacts.
For elasticity, composite metrics work better than CPU utilization alone: queue wait time, batch fill rate, and memory watermark all matter. Scaling out requires warm-up, since model loading and graph compilation take a long time, so keep warm standby instances and bring them into rotation through readiness probes.
# Example: autoscaling based on custom metricsscaling:minReplicas: 4maxReplicas: 40metrics:- queueWaitMs: 120- batchFillRate: 0.75warmPoolSize: 2
5. Stability Governance and Full-Link Observability
Under real traffic, assume both hardware and operators will fail. A three-tier degradation scheme is recommended: tier one switches to a backup compute pool; tier two reduces the maximum context length and batch size; tier three returns cached results or a short fallback response. A unified view built from logging, monitoring and alerting, and distributed tracing should cover the core metrics: time to first token, inter-token latency, failure rate, retry rate, energy consumption per request, and cost per token.
Canary releases should advance on two tracks, traffic percentage and business dimension: validate quality and latency at a small percentage first, then scale up gradually. Rollback must keep compiled artifacts and model versions in one-to-one correspondence to avoid version drift.
6. Recommended Rollout Path
- Phase 1: complete the operator audit and functional alignment, and establish a quality evaluation baseline.
- Phase 2: run load tests and tune parameters, fixing batching and cache settings.
- Phase 3: enable elasticity and degradation, and run failure drills.
- Phase 4: move to cost optimization, adjusting the compute pool mix based on utilization curves.
Baidu AI Cloud has generalizable practices in heterogeneous compute scheduling, container platforms, and observability that can serve as a reference for architecture design, but the specific parameters should still come from your own load testing.
Overall, whether large model inference runs well on a domestic chip cluster comes down to how complete the engineering details are: whether the compilation pipeline can fall back, whether scheduling matches the shape of real traffic, whether observability covers energy and cost, and whether degradation has been drilled under real conditions. Get these pieces solid, and you get a service that stays stable, predictable, and cost-controlled under very large-scale real traffic.
