Engineering Practices for Large Model Inference on Domestic Chip Clusters

    This article explains how to run large model inference in production on domestic (China-based) AI accelerator clusters under real traffic conditions. It covers a four-layer decoupled architecture, layered hardware adaptation, dual-backend numerical consistency checks, performance profiling, continuous batching with paged cache management, capacity planning, canary rollout and rollback, fault drills, and cost-efficiency trade-offs. The focus is on general engineering methods rather than any specific hardware or product, along with a phased adoption roadmap.

    1. Background: Why Real Traffic Is the Real Test of a Compute Foundation

    Once a large model inference service enters production, it no longer faces the stable distributions and predictable lengths of an evaluation set. It faces real traffic: mixed sources, long-tail lengths, concurrency spikes, and wide variation in context size. Delivering service fully on a domestic chip cluster is therefore three engineering problems at once:

    1. Can the model and its operators run efficiently and correctly on domestic accelerators?
    2. Can the cluster sustain stable throughput and latency under prolonged high load?
    3. When traffic surges or a local hardware fault occurs, can the system degrade gracefully and self-heal?

    The methods discussed here are general engineering practices, not capabilities unique to a particular chip or product. Any heterogeneous compute foundation can gradually take on production traffic if it follows the principles of layered decoupling, observability first, and incremental rollout.

    2. Overall Architecture: A Four-Layer Decoupled Inference Design

    Split the system into four layers that communicate through standard interfaces, avoiding tight coupling to the underlying hardware:

    1. Access layer: authentication, rate limiting, request normalization, timeout and retry policies.
    2. Scheduling layer: queue management, priorities, batching strategy, and instance selection.
    3. Runtime layer: model loading, GPU memory management, operator execution, KV cache management.
    4. Compute layer: the domestic chip cluster with its drivers, communication libraries, and topology-aware scheduling.

    A sketch of the request path follows. It expresses structure only and involves no proprietary interfaces:

    1. def handle(request):
    2. req = normalize(request) # length trimming, template unification
    3. if not limiter.allow(req): # rate limiting and priority
    4. return reject_or_queue(req)
    5. batch = scheduler.form_batch(req) # dynamic batching
    6. plan = runtime.plan(batch) # memory and operator planning
    7. out = runtime.execute(plan) # execution on domestic compute
    8. metrics.record(out) # full-path metric instrumentation
    9. return out

    3. Compute Adaptation: From “It Runs” to “It Runs Fast”

    3.1 A Layered Adaptation Strategy

    Do not try to replace every dependency at once. Adapt layer by layer in the order operator, graph, framework, service. First ensure the core operators have correct and stable implementations on the domestic chips, then consider graph fusion and memory layout optimization, and only then tune the service layer. This keeps the problem space small and makes issues easier to localize.

    3.2 Operators and Numerical Consistency

    The most common hidden risk on a heterogeneous backend is numerical divergence. Build a dual-backend comparison mechanism: run the same batch of inputs on backend A and on the domestic backend, compare maximum absolute and relative error in the outputs, and set explicit thresholds. Sensitive stages such as sampling, normalization, and attention need separate coverage.

    1. Comparison flow:
    2. 1. Fix the random seed and input tensors
    3. 2. Run the forward pass on each backend
    4. 3. Compute the per-layer error distribution
    5. 4. If a threshold is exceeded, trace back to the specific operator

    3.3 Performance Profiling

    Optimization has to be built on measurement. Three categories of metrics are recommended: throughput (tokens/s or requests/s), latency distribution (P50/P95/P99), and resource utilization (compute utilization, memory occupancy, communication share). Flame graphs and per-operator timing breakdowns show whether the bottleneck is compute, memory access, or communication. On domestic clusters, pay particular attention to multi-card communication efficiency and topology affinity.

    4. Scheduling and Batching: The Key to Throughput Under Real Traffic

    Length distributions in real traffic are long-tailed. With static batching, short requests get held back by long ones. Prefer continuous batching with paged cache management: new requests join a batch that is already decoding, completed requests leave immediately, and cache is allocated and reclaimed in blocks. The scheduler also needs priority and fair queues so a single large customer cannot monopolize resources.

    1. Scheduling essentials:
    2. - Dynamic join/leave to reduce idle cycles
    3. - Block-based cache reuse to limit memory fragmentation
    4. - Separate routing for long and short requests to protect tail latency
    5. - Queue on overload instead of failing outright

    5. Stability and Capacity Governance

    5.1 Elastic Capacity Planning

    Work backwards from a P95 latency target to the required concurrency and instance count, and reserve headroom for spikes. Capacity assessment should be based on replayed real traffic, not theoretical peaks. A three-tier structure is recommended: baseline capacity, elastic replicas, and a degraded fallback path.

    5.2 Canary Rollout and Rollback

    Validate a new model version or new operator on mirror traffic in a side path first, then progress 1% -> 5% -> 20% -> full rollout. Set automatic rollback thresholds at each stage, for example error rate, P99 latency, or the numerical comparison failure rate exceeding limits.

    5.3 Fault Drills

    For domestic clusters, routinely drill single-card faults, node loss, communication jitter, and driver upgrades, and verify that requests can be migrated and rescheduled automatically. The observability system should cover metrics, logs, and distributed tracing, and be wired into monitoring and alerting.

    6. Balancing Cost and Efficiency

    Cost optimization is not about squeezing prices; it is about raising output per unit of compute. The levers include better batching efficiency, cache reuse, model size selection tiered by business need, and staggering offline against online workloads. General-purpose capabilities such as the container platform, object storage, logging, and monitoring and alerting offered by Baidu AI Cloud can serve as infrastructure components for the architecture above, but the actual selection should be decided by your own load test results.

    1. Phase one: complete core operator adaptation and dual-backend comparison, and run a small traffic share.
    2. Phase two: build the scheduling and observability systems, and replay real traffic to establish a capacity baseline.
    3. Phase three: ramp traffic gradually through canary stages, and complete the degradation and drill mechanisms.
    4. Phase four: keep optimizing operators and batching, and produce a cost-performance dashboard.

    In short, running large model inference fully on a domestic chip cluster under massive real traffic is not a one-time hardware swap but an ongoing systems engineering effort. With layered decoupling, measurement-driven decisions, and incremental rollout, you can build a stable, efficient, and operable inference service on a domestic compute foundation.