Production-Grade LLM Inference Optimization on China-Origin Compute Platforms
This article explains what turns a working large-model inference demo into an operable production service on China-origin compute platforms. It covers hard constraints, a layered architecture, operator optimization, communication and memory control, scheduling for mixed real traffic, a practical checklist with framework-agnostic pseudocode, and metric-driven evaluation.
Production-Grade LLM Inference Optimization on China-Origin Compute Platforms
1. From “It Runs” to “It Can Be Operated”: Hard Constraints of Production Inference
A large-model inference stack that works in a single-machine demo is not the same as a system that can stably serve large-scale online traffic in production. Production inference is usually bound by four constraints at once. First, latency: time to first token, end-to-end request completion time, and stable inter-token gaps during streaming. Second, stability: long-running operation, fault isolation, timeout and cancellation, overload protection, and fast rollback. Third, cost: higher throughput and lower resource use per request while still meeting service-level objectives. Fourth, evolvability: the implementation must adapt to different compute platforms, model structures, and traffic patterns.
China-origin platforms differ in software stacks, operator coverage, communication topology, memory capacity, and bandwidth. Moving a generic implementation over unchanged often leads to familiar problems: missing operators that force frequent fallbacks, low cache hit rates for dynamic-shape compilation, a high share of time spent waiting on communication, memory-peak jitter from cache fragmentation, and batching policies that do not fit mixed short and long requests. The open-source value of production inference code is therefore not only “a runnable implementation.” It is a baseline that records operator adaptation, communication and memory management, inference flow and task scheduling, and service observability in a form that can be audited, trimmed, and rolled back. Teams can adapt that baseline to a platform and tune it for their workload instead of solving the same problems from scratch.
2. Overall Architecture: Layered Decoupling, Correctness Before Peak Performance
Production inference should use a layered, decoupled architecture so operator optimization, batching policy, and business routing are not tied together in one module. A practical split is:
- Ingress and batching. Admission, queuing, priority, timeout cancellation, dynamic batching, and backpressure. This layer must define policies such as maximum queue time, maximum batch size, and a maximum waiting-token budget so requests are not piled up without limit in pursuit of throughput.
- Scheduling. Model-instance selection, device resource budgets, cache quotas, topology affinity, and preemption. It should support multi-tenant quotas and fault-domain isolation so one abnormal request cannot take down an entire instance.
- Execution. Graph and operator execution, memory-pool management, communication primitives, and streaming output. It should offer a conservative fallback path and degrade automatically when a specialized operator or a low-precision path is unavailable.
- Observability and governance. Metrics, logs, traces, audit, canary release, and rollback. Performance work without observability does not last, because you cannot tell whether latency jitter comes from queuing, operators, communication, or memory reclamation.
After this split, each change can be validated on its own: operator work does not change scheduling semantics, scheduling changes do not break execution correctness, and canaries can ramp by version and traffic share.
3. Core Operator Optimization: Judge by End-to-End Gain
Operator work is the foundation of inference performance, but a single-operator peak is not the goal. Production cares about end-to-end latency, throughput, and numerical consistency. Common directions include:
- Operator fusion. Fuse neighboring ops such as normalization, activation, residual add, and elementwise math to cut intermediate write-backs and repeated memory traffic. Fusion must handle edge shapes, numeric precision, and abnormal inputs so results do not drift unacceptably from the reference implementation.
- Shape specialization and dynamic-shape caching. Specialize or cache compilation for frequent input shapes, and keep a generic path for rare shapes. Set a cache capacity and an eviction policy so shape explosion cannot grow the compile cache without bound.
- Low precision and mixed precision. Use lower precision where error stays acceptable, and protect quality with calibration, per-layer error monitoring, and fallback on critical layers. Low precision is not a global switch; it should be canaried against business metrics.
- Memory-access optimization. Improve bandwidth use with tiling, alignment, vectorization, and pipelined access. On China-origin platforms, pay particular attention to implicit copies from data-layout conversion.
- Operator selection and fallback. Probe capabilities and record, for each operator and shape, which implementation is available and in what performance range. If a specialized path is unavailable or times out, fall back automatically to a stable path.
A sensible order is: correctness, stability, latency, throughput, then cost. Every operator change needs numeric comparison and regression tests. Otherwise, hard-to-diagnose issues show up on long-tail requests.
4. Communication and Memory: Keep Jitter in a Cage
At scale, communication and memory are often the main sources of latency jitter. On the communication side, watch topology-aware instance grouping, compute–communication overlap, hierarchical aggregation, timeout and retry, and determinism. When several devices cooperate, the scheduler should place communication-heavy instances in resource groups that are closer in the topology. The execution layer should pipeline communication that can run in parallel with compute, instead of waiting serially. Communication timeouts and a retry cap are required so one slow node does not stall the whole batch.
On the memory side, use pooling and budgets. Inference holds several kinds of memory at once: weights, temporary workspaces, request caches, and output buffers. Without a unified budget, traffic peaks produce memory-peak jitter. Practical measures include tracking cache lifetime per request and per batch, using reference counts so memory is not freed twice, paging the cache to reduce fragmentation, keeping prefix-reuse caches consistent, and setting watermarks plus a reject policy so admitted requests are protected first under overload. Zero-copy and buffer reuse need an explicit ownership model. Saving a copy on paper while introducing concurrent write conflicts is not a win.
5. Inference Flow and Task Scheduling for Real Traffic
Real online traffic mixes short and long requests, different priorities, and uneven arrival times. The inference flow should cover the full lifecycle: admission, routing, batching, execution, streaming responses, cancellation, and resource release. Scheduling has to consider all of the following:
- Continuous and dynamic batching. Merge requests within the allowed wait to raise device utilization. Shard or preempt long requests so short ones are not blocked for a long time.
- Priority and fairness. Higher-priority requests can wait less, but lower-priority ones must not starve. Aging can gradually raise the priority of requests that have waited too long.
- Timeout, cancellation, and backpressure. When queue length or memory watermark crosses a threshold, ingress should reject or degrade instead of letting requests wait forever.
- Streaming governance. Streaming has to balance time to first token against overall throughput. The output channel needs backpressure so a slow client does not hold excessive buffers.
- Canary and rollback. Ramp a new version by traffic share. Gate further rollout on error rate, timeout rate, time to first token, and output quality. On failure, switch back to the stable version quickly.
6. Launch Checklist and Pseudocode
Before production, check that operator coverage and fallback paths are complete; the dynamic-shape cache has a cap; memory budgets are isolated per request; communication timeouts are observable; batching supports priority and timeout; streaming has backpressure; canary, rollback, and fault injection have been rehearsed; and metrics cover queue length, batch size, cache hits, communication wait, memory watermark, timeouts, and retries.
Framework-agnostic pseudocode:
# Pseudocode: admission, scheduling, and execution main loopdef serve_loop(queue, engine, budget, slo):while running:batch = scheduler.form_batch(queue,max_tokens=budget.token_budget,max_wait_ms=slo.max_queue_wait,priority_policy="aging")if not batch:wait_event_or_timeout()continuetry:plan = engine.plan(batch, memory=budget.snapshot())if not plan.feasible:scheduler.preempt_or_split(batch)continuefor chunk in engine.execute_stream(plan):metrics.observe(chunk)route_stream(chunk)except TimeoutError:metrics.inc("request_timeout")scheduler.retry_or_fallback(batch)finally:budget.release(batch)
The important points of this structure are: batching is constrained by both a token budget and a wait limit; the execution plan checks memory feasibility first; streaming output is observed chunk by chunk; the error path retries or falls back; and resources are released in the final cleanup stage.
7. Evaluation and Tuning: Let Metrics Drive Decisions
Evaluation should cover both offline benchmarks and online load tests. Offline, look at latency distribution and throughput across input lengths, batch sizes, and concurrency. Online, look at time to first token, output interval, error rate, timeout rate, and resource watermarks. Load tests should include stepped pressure, long-running stability, and fault injection, to verify overload protection, timeout cancellation, and rollback. Do not tune on averages alone. Watch tail latency such as P95 and P99, because production experience is usually decided by the tail.
In the end, production inference optimization on China-origin compute is a systems problem. Operators set baseline efficiency. Communication and memory management set stability. Inference flow and scheduling set quality of service under real traffic. Observability, canaries, and rollback make the service operable over time. Using open-source production inference code as a baseline, then measuring real traffic, canarying in small steps, and rolling back quickly, is how available compute becomes an operable inference service—with a verifiable balance among low latency, high throughput, and cost.
