Large-Scale MoE Inference Architecture and Optimization on Domestic AI Accelerators
This article breaks down the core techniques behind large-scale Mixture-of-Experts (MoE) inference: sparse activation that decouples total parameters from per-token compute, low-precision quantization for memory and bandwidth relief, and hybrid attention for long-context workloads. It also outlines a practical optimization path for domestic chips and software stacks, plus an action checklist for developers.
1. Why Simply Scaling Up Dense Models No Longer Works
Over the past two years, much of the capability growth in large models has relied on a simple assumption: scale parameters, data, and compute together, and capability will follow. This path is straightforward engineering-wise, but it is unsustainable from a cost perspective. A classic feed-forward network is dense: every weight participates in multiply-accumulate operations during the forward pass. Once the parameter count crosses the hundred-billion mark, memory footprint, memory bandwidth pressure, and per-inference energy consumption all rise in tandem, while the returns curve gradually flattens.
So the industry has shifted to a different idea: instead of making the model bigger, make the part actually used per inference smaller. This is sparsification. The goal is not to reduce model capacity, but to decouple two things that used to be bound together: total parameter count and compute per token.
2. Sparse Activation: Decoupling Capacity from Compute
The core of the Mixture-of-Experts structure is a routing module that selects a few experts to participate in computation for each token. Total parameters can reach the trillion scale, but each token activates only a small fraction of them, so inference cost is no longer linearly correlated with total parameter size.
Three things deserve close attention in engineering:
- Routing balance. When a few experts are over-selected, “hot experts” emerge while the rest sit idle for long periods, and the effective usable capacity falls far below the nominal capacity. A common approach is to introduce an auxiliary load-balancing loss and monitor the selection frequency distribution of each expert.
- Capacity factor and overflow. Each expert has a fixed processing capacity, and the excess must be dropped or bypassed. Too small a capacity factor hurts quality; too large wastes memory and bandwidth. It needs to be determined through stress testing against real business traffic characteristics.
- Communication overhead. When experts are distributed across different devices, tokens must be routed to the corresponding device, and collective communication becomes the bottleneck. The combination of expert parallelism and tensor parallelism must match the interconnect bandwidth.
The routing logic can be abstracted schematically as:
# Pseudocode: expresses sparse activation semantics only, not a specific implementationlogits = router(hidden_states) # [tokens, num_experts]topk_idx, topk_w = topk_softmax(logits, k=2)y = 0for e in unique(topk_idx):tokens_e = gather(tokens, topk_idx == e)y_e = experts[e](tokens_e) # only this expert participates in computationy += scatter_weighted(y_e, topk_w)
3. Low-Precision Quantization: Relief for Both Memory and Bandwidth
Low precision is the other half of why sparse architectures can actually be deployed. Pushing weights and activations from half precision down to 8-bit or even 4-bit floating-point representations directly reduces memory footprint and memory access volume proportionally. Since most operators in the inference stage are memory-bound, throughput gains are often more pronounced than compute gains.
Key trade-offs in practice:
- Layered precision strategy. Keeping higher precision at numerically sensitive spots such as attention, normalization, and routing, while using lower precision for the main body of the feed-forward experts, is a fairly mainstream compromise.
- Scaling granularity. Whether scaling factors are set per tensor, per channel, or per block directly affects the error introduced by outliers; block-level scaling is usually more stable.
- Representativeness of calibration data. The quantization calibration set must cover the real business distribution; otherwise, degradation on long-tail inputs gets masked by the average.
- Precision regression validation. Before launch, compare metrics on a business evaluation set before and after quantization, keeping the precision loss within an acceptable threshold.
4. Breaking Quadratic Complexity: The Engineering Value of Hybrid Attention
The compute and memory cost of standard self-attention grows quadratically with sequence length, and long-context scenarios are hit first. The layered approach widely adopted in the industry is: most layers use local windows or sparse patterns to compress the candidate range, while a small number of layers retain global attention to aggregate long-range information, combined with mechanisms such as sliding windows and attention sinks to preserve key information pathways. In addition, paged key-value cache management, prefix reuse, and cache quantization can significantly reduce first-token latency and peak memory usage for long contexts at the serving layer.
5. Coordinated Optimization of the Domestic Software and Hardware Ecosystem
Sparse large models act as an amplifier for domestic chips and their supporting software stacks: operator coverage, maturity of communication libraries, and support for quantization operators—missing any one of these will discount the theoretical gains. A practical order of progression:
- Align operators first. Compare the reference implementation against the domestic backend output layer by layer to locate sources of numerical deviation, avoiding misjudging a precision issue as a framework issue.
- Jointly tune communication and parallelism strategies. Fix model precision first, then sweep parallel combinations to find the throughput inflection point.
- Work on the serving layer. Continuous batching, paged caching, request priority queues, and auto-scaling often deliver more direct cost-performance improvement than swapping hardware.
- Fill in observability. Bring throughput, first-token latency, cache hit rate, and expert load distribution into the logging service and monitoring/alerting system to form a basis for capacity planning.
For cloud deployment, you can combine a container platform to host inference services, object storage to hold model weights, and a message queue to smooth request peaks, and leverage general cloud product capabilities from platforms such as Baidu AI Cloud to achieve elastic scaling and full-link observability.
6. An Action Checklist for Developers
- Estimate memory and bandwidth first, then decide quantization precision and parallelism strategy—do not do it in reverse.
- Establish a small-scale precision regression baseline, and push any optimization forward on the premise that metrics do not degrade.
- Treat expert load and cache hit rate as first-class monitoring metrics, not after-the-fact troubleshooting items.
- Shift from “calling the model” to “understanding the inference pipeline”—this is currently the direction with the highest return on investment for capability upgrades.
Sparsification, low precision, and hybrid attention are not independent tricks, but a mutually supporting cost-engineering system. Only by understanding how they couple can you build a truly deliverable system under limited compute.
