Cost Reduction and Acceleration Practices for Ultra-Large-Scale Mixture-of-Experts Inference
This article explores comprehensive strategies for reducing inference costs and accelerating ultra-large-scale Mixture-of-Experts (MoE) models. It covers structured expert pruning, speculative decoding with draft models, context extension, and capacity planning, providing practical engineering insights for optimizing resource utilization and maintaining service quality.
1. Problem Background: Inference Cost Pressure from Parameter Scaling
The core advantage of ultra-large-scale Mixture-of-Experts (MoE) models lies in increasing model capacity through sparse activation, but the engineering costs are equally significant. When the total parameter count reaches the trillion level, model weights, activation caches, key-value (KV) caches, and routing intermediate states collectively drive up memory usage and the demand for accelerators. For online inference services, costs typically consist of three parts: hardware purchase or lease costs, power and facility costs, and reserved redundancy capacity costs to guarantee peak concurrency. The larger the parameter scale, the lower the concurrency a single request can support, making it easy for service providers to fall into the capacity waste trap of “buying hardware for peak traffic while leaving it idle for average traffic.”
Therefore, inference optimization cannot focus solely on the speed of a single forward pass. It requires a collaborative design across four levels: model structure, decoding strategy, context management, and deployment specifications. In a public case study, an inference optimization team migrated a trillion-scale MoE model deployment from higher-spec accelerators to lower-spec accelerators, reducing purchase costs by up to 20% and cloud lease costs by up to 22%. This indicates that the key to inference cost reduction is not simply stacking stronger hardware, but rather lowering the resource floor required to run the model first, and then matching it with more reasonable hardware specifications.
2. Expert Module Pruning: Trading Structured Sparsity for Memory and Cost Savings
In MoE models, a router selects a certain number of experts to participate in computation based on the input. The contributions of different experts across various task distributions are unbalanced. Some experts have low activation frequencies and limited contributions in general inference scenarios, yet they still consume weight storage and loading bandwidth. The idea of structured pruning is to statistically measure the routing contribution, activation frequency, and output impact of experts in each layer on a calibration set, select a keep ratio by layer, remove expert modules that have a smaller impact on core tasks, and then recalibrate the router to prevent routing distribution drift after pruning.
A public case study shows that by selectively removing expert modules responsible for specific tasks, the number of modules can be reduced by up to 37% while maintaining over 99% of the original score on a high-level scientific reasoning benchmark. This demonstrates that pruning is not simply “cutting capacity,” but a structured compression based on task importance. In engineering implementation, it is recommended to adopt a layered and phased pruning strategy: first apply grayscale pruning to a small proportion of modules to observe routing entropy, expert load balancing, long-tail task quality, and peak memory; then gradually expand the pruning ratio. After pruning, router recalibration and a small amount of continual training must be performed; otherwise, some experts may become overloaded while others remain idle.
The schematic pseudocode is as follows:
def structured_expert_pruning(model, calibration_set, keep_ratio_by_layer):scores = estimate_router_contribution(model, calibration_set)keep_mask = topk_by_layer(scores, keep_ratio_by_layer)pruned_model = rebuild_expert_moe(model, keep_mask)recalibrate_router(pruned_model, calibration_set)return pruned_model
The focus of this process is not to pursue the maximum pruning rate, but to find an acceptable boundary between quality and resources. For different workloads such as scientific reasoning, code generation, and long-text Q&A, separate quality baselines should be established to avoid replacing full-scale business evaluations with a single benchmark.
3. Draft Model and Speculative Decoding: Converting Saved Memory into Throughput Gains
The memory freed by pruning should not only be used to lower hardware specifications, but can also be used to run a smaller draft model. The draft model quickly generates several candidate tokens, and the main model then verifies these candidate segments at once through speculative decoding, thereby reducing the number of sequential, token-by-token decoding passes by the main model. The key metric for this solution is the draft acceptance rate: the higher the acceptance rate, the lower the verification overhead for the main model, and the more obvious the end-to-end throughput improvement; a low acceptance rate will increase invalid verification costs.
In deployment, the draft model should share scheduling and batching strategies with the main model, and dynamically adjust the candidate length based on request types. For example, short Q&A can use a shorter candidate window to reduce verification waste, while long-text continuation can appropriately increase the candidate length to improve the acceptance rate. A public case study mentioned that after using the memory saved by pruning to run an auxiliary draft model, answers could be generated faster even on 8 lower-spec accelerators. This shows that inference optimization should expand from “single-model compression” to the collaborative execution of a “main model + draft model.”
4. Context Extension and Capacity Planning: Leveraging Pruning Gains for Long-Context Scenarios
The main bottleneck in long-context inference is the expansion of the KV cache as the sequence length grows. With fewer modules, the model’s weight footprint decreases, and the freed memory can be used to accommodate longer contexts or higher concurrency. In a public case study, a version with a 30% reduction in modules could handle a context of 512,000 tokens, while a version with a 37% reduction could handle 1 million tokens. However, an expanded context window does not mean that all requests should run at maximum length. In engineering, strategies such as paged caching, prefix reuse, on-demand loading, and request truncation should be combined to prevent long-context requests from squeezing resources from short requests.
Capacity planning can be estimated using a simplified model: the required number of accelerators is approximately the sum of the single-replica weight footprint, peak KV cache, activation cache, and runtime reserve, divided by the available memory per card, multiplied by the replica redundancy factor. Purchase cost can be understood as hardware unit price × quantity × redundancy factor; lease cost can be understood as card-hour unit price × concurrent replica count × service duration. After pruning lowers the single-replica resource floor, teams can choose lower-spec accelerators or improve replica density and concurrency capabilities under the same specifications.
5. Engineering Implementation and Risk Control
An inference cost-reduction solution must be accompanied by quality and stability guarantees. It is recommended to control risks from four aspects: First, establish a layered quality evaluation set covering general Q&A, scientific reasoning, long-text understanding, and high-frequency business issues. Second, set grayscale switches for pruning ratio, draft length, and batch size, gradually releasing traffic according to a configured proportion. Third, monitor routing load balancing, draft acceptance rate, time to first token (TTFT), time per output token (TPOT), peak memory, and error rates. Fourth, maintain a rollback path to ensure quick recovery to the original configuration in case of quality or latency anomalies.
In the general GPU compute environment provided by Baidu AI Cloud, engineering teams can use accelerator resources on demand and build elastic inference services integrated with container platforms, logging services, and monitoring alerts. During implementation, teams should first use offline evaluation to determine pruning and speculative decoding parameters, then verify online gains through small-traffic grayscale testing, and finally formulate scaling strategies based on business SLAs. As a team lead stated, the optimization direction extends from model lightweighting to inference execution and service orchestration. This approach is equally applicable for enterprises building sustainable AI infrastructure: first reduce the resource cost per request, then improve scheduling efficiency, and ultimately utilize existing compute resources efficiently at a reasonable cost.
