Token Production with Domestic AI Chips: A Practical Guide
This article explains how to treat large language model inference as a token production pipeline built on domestic AI chips. It breaks down a five-layer reference architecture, outlines model adaptation and acceptance criteria, and details four levers for lowering cost per token: batching, cache reuse, quantization, and elastic prioritization. It also covers the metrics needed for evaluation and common deployment pitfalls.
1. Why Token Production Should Be Built Like a Factory
As large models move from demos into daily business, the core cost structure shifts from “train once” to “infer endlessly.” Every conversation turn, every document summary, and every code completion consumes compute and produces tokens. This workload is best described as token production because it shares the characteristics of manufacturing: highly variable demand, clear delivery deadlines, a yield rate (output quality and format compliance) that must be measured, and a unit cost that must keep falling.
Under this view, single-card performance is no longer the only metric. What really determines cost per token is the effective utilization of the entire production line: queueing time, batching efficiency, whether memory capacity and bandwidth become bottlenecks, the retry rate for failed requests, and the adaptation overhead between models and hardware. For domestic AI chips to scale in this scenario, the key is not peak numbers on paper but whether system-level engineering can push these overheads low enough.
2. Reference Architecture: From the Compute Foundation to the Service Gateway
A deployable token production system is usually divided into five layers, decoupled through explicit contracts so each can be optimized and replaced independently.
- Compute foundation layer: built from domestic accelerator cards, providing matrix compute, memory capacity, and inter-card interconnect. This layer focuses on topology, interconnect bandwidth, and thermal stability.
- Runtime and operator layer: includes drivers, runtime, communication libraries, and operator implementations that map the computation graph onto the hardware. Adaptation quality is largely decided here.
- Model and parallelism layer: defines how tensor parallelism, pipeline parallelism, and expert parallelism are partitioned, along with weight quantization and KV cache strategy.
- Serving and scheduling layer: handles dynamic batching, priority queues, elastic scaling across replicas, timeouts, and degradation.
- Gateway and metering layer: provides unified authentication, rate limiting, canary rollout, logging, and usage metering. It is the entry point for cost attribution and quality monitoring.
The core benefit of layering is replaceability: when one layer becomes a bottleneck, you can adjust that layer alone instead of rebuilding the whole pipeline. This matters especially for the fast iteration of the domestic chip ecosystem.
3. Model Adaptation: Moving from “It Runs” to “It Runs Reliably”
System-level adaptation usually advances along four tracks, each with clear acceptance criteria.
- Operator coverage and fallback: ensure high-frequency operators have high-performance implementations first, and route the rest through a generic path. The acceptance criterion is that the end-to-end pipeline runs without numerical anomalies.
- Numerical consistency: outputs should stay consistent across different parallelism partitions and batch sizes. It is recommended to build a regression comparison over a fixed input set, with tolerance defined in advance.
- Memory and cache: long-context scenarios put extreme pressure on memory, so the combined effect of cache paging, prefix reuse, and block size needs evaluation.
- Communication efficiency: the collective communication overhead introduced by parallel partitioning is often amplified in small-batch, low-latency scenarios.
An illustrative adaptation validation script (pseudocode, expressing the flow only):
def validate(engine, cases, atol=1e-3):for case in cases:out = engine.run(case.prompt, batch_size=case.bs)assert finite(out), "Output contains non-numeric values"diff = max_abs_diff(out, case.expected)assert diff <= atol, f"Accuracy regression: {diff}"return report(throughput=tokens_per_sec(engine),p99_ms=percentile(engine.latency, 99))
4. Engineering Optimization: Four Levers for Cost per Token
Lever one: batching strategy. Static batching is simple to implement but underutilizes the hardware; continuous batching slots in new requests as soon as sequences finish, significantly improving effective throughput. In practice, you need to set a maximum batch size and a maximum wait window to balance throughput against latency.
Lever two: cache reuse. System prompts, long documents, and retrieved snippets are often reused, and prefix caching avoids recomputation. The hit rate depends on request similarity and the cache eviction policy, and should be tracked as a first-class metric.
Lever three: quantization and compression. Weight quantization reduces memory footprint and memory access pressure, but must be gated by quality regression; for latency-sensitive workloads, you can apply low-bit processing to only some layers.
Lever four: elasticity and priority. Pool online interactive traffic separately from offline batch jobs, and combine priority queues with degradation policies so offline jobs do not crowd out the interactive path.
A simplified scheduling decision logic:
def admit(request, cluster):if request.kind == "offline":return cluster.offline_pool.try_enqueue(request)if cluster.online_pool.load() > HIGH_WATER:return degrade_or_queue(request) # Degrade to a smaller model or queuereturn cluster.online_pool.schedule(request)
5. Evaluation: Make Decisions with Metrics, Not Gut Feel
It is recommended to fix four categories of metrics and track them over the long term: throughput (output tokens per second), latency (percentiles of time to first token and end-to-end latency), quality (regression set pass rate and format compliance rate), and cost (compute and energy converted to cost per token). Also record the retry rate and cache hit rate, which are usually leading signals of performance fluctuation. Load testing should cover three typical shapes—short prompt with long output, long prompt with short output, and sudden concurrency spikes—to avoid optimistic conclusions drawn from a single shape.
6. Common Deployment Pitfalls
- Selecting hardware by peak compute alone while ignoring memory access and interconnect bottlenecks.
- Skipping accuracy regression during adaptation and only discovering long-text quality degradation after launch.
- Keeping batching parameters fixed so the system cannot handle traffic waveforms.
- Lacking metering and canary rollout, so cost cannot be attributed to the responsible business team.
- Limiting disaster recovery to process restarts, with no request-level degradation path.
7. Conclusion
Scaling token production is essentially about turning uncertain model workloads into a pipeline that is measurable, schedulable, and optimizable. With domestic AI chips as the compute foundation, together with clear architectural layering, strict adaptation acceptance, and a metrics-driven tuning loop, sustainable reductions in unit cost become achievable in real business settings. Baidu AI Cloud likewise emphasizes layered decoupling and full-pipeline observability in its related practice, an approach with general reference value for building an autonomous and controllable inference production system.
