Reducing Inference Costs for Ultra-Large Models with Expert Pruning and Speculative Decoding
This article describes how an inference optimization team combined expert module pruning with speculative decoding on a model with about 2.8 trillion parameters. The approach reduced accelerator procurement costs by up to about 20% and cloud rental costs by up to about 22%. It covers where inference costs come from, how to prune experts while checking quality, how speculative decoding uses the freed memory, how longer context and lower-tier hardware fit into the plan, and how to roll the changes out safely.
As ultra-large models move into real business use, the inference goal has shifted from whether a model can run to whether it can run reliably at scale and at a reasonable cost. Larger models need more memory and accelerator capacity for their weights, expert modules, context caches, and concurrent requests. Procurement and cloud rental costs rise with them.
An inference optimization team applied a combination of expert module pruning and speculative decoding to a model with about 2.8 trillion parameters. The result was a reduction of up to about 20% in accelerator procurement costs and up to about 22% in cloud rental costs.
The value of this case does not lie in any single product. It shows a reusable technical path. First, lower the minimum memory and compute the model needs to run. Second, use the freed resources to increase generation speed. Third, reduce total cost of ownership by deploying on lower-tier hardware specifications.
1. Where the Cost Comes From
Ultra-large models usually use a Mixture-of-Experts (MoE) architecture. A single inference pass activates only a subset of experts, but all experts still need to stay in memory or in storage that can be swapped in quickly. Longer context increases the size of the key-value cache. Higher concurrency makes memory fragmentation and scheduling overhead more visible.
Cost pressure comes from four main areas:
- Weights and expert modules. These consume memory and determine whether a single accelerator can hold the model and how many cards are needed.
- Activation computation and routing. These determine the latency of each request.
- Cache growth from long context. This determines the context length and the number of concurrent requests the system can serve.
- Accelerator specification and count. These determine procurement and rental prices.
Effective cost reduction therefore does not mean simply switching to cheaper hardware. It starts with model structure optimization to lower the resource floor, then applies inference execution optimization to raise throughput per unit of hardware.
2. Expert Pruning: Fewer Modules, Core Capability Retained
Expert modules in a MoE model often handle different tasks or semantic patterns. Pruning does not mean removing parameters bluntly. Instead, the team evaluated each expert’s contribution to the output distribution using calibration data. They selectively removed experts that were redundant for specific tasks, then recalibrated the routing and output layers after pruning.
In this case, the number of modules was reduced by up to 37%. The model still retained more than 99% of the original score on high-level scientific reasoning benchmarks. The key to pruning is task sensitivity assessment followed by regression testing after pruning.
In practice, start by building a layered evaluation set that covers general question answering, scientific reasoning, long-document understanding, code, and long-tail business tasks. Then rank experts by importance and increase the pruning ratio step by step while watching for inflection points in the metrics. The following pseudocode illustrates the process:
def build_pruning_plan(model, eval_sets, max_drop=0.37):importance = estimate_expert_importance(model, eval_sets)plan = []for ratio in [0.10, 0.20, 0.30, 0.37]:candidates = select_low_importance_experts(importance, ratio)score = evaluate(model.without(candidates), eval_sets)if score.core_quality >= 0.99 * score.baseline:plan.append((ratio, candidates, score))return best_tradeoff(plan, max_drop)
After pruning, monitor routing drift, degradation on long-tail tasks, and changes in supported context length. The version with 30% fewer modules supports 512,000 tokens of context. The version with 37% fewer modules supports 1 million tokens. Freeing memory from reduced expert storage can therefore translate into longer context or higher concurrency.
Teams should not prune to the limit in one step. Keep a rollback configuration and roll out pruned versions gradually based on business traffic.
3. Memory Reallocation and Speculative Decoding: Using Saved Resources to Speed Up Generation
Memory freed by pruning does not need to sit idle. It can host a smaller draft model. The basic speculative decoding process works as follows. The draft model proposes several subsequent tokens. The main model then verifies all candidate tokens in one pass. If the candidates are accepted, the sequence advances in a batch. If they are rejected, the system falls back to the first position that does not match. The main model can therefore generate more tokens with the same or fewer forward passes, which lowers the latency per output token.
In this case, the team generated answers faster on eight lower-tier accelerator cards. This worked because pruning left enough memory to hold the draft model. The following pseudocode illustrates the process:
context = promptwhile not finished(context):draft = draft_model.propose(context, k=4)accepted = main_model.verify(context, draft)context.extend(accepted)if len(accepted) < len(draft):context.extend(main_model.next_token(context))
The benefit of speculative decoding depends on how closely the draft model matches the main model’s distribution, the length of the candidate sequence, and the verification overhead. A weak draft model lowers the acceptance rate. A strong draft model takes resources away from the main model. In practice, monitor the acceptance rate, the number of tokens verified per step, tail latency, and remaining memory headroom, then adjust the candidate length dynamically.
This method forms a loop with pruning. Pruning lowers the memory floor, the draft model raises throughput, and higher throughput spreads the cost per token across more output.
4. Long Context and Deployment Specifications: From Eight Cards to Four and Lower
Long context is not free. Longer context increases cache usage and makes scheduling more complex. In this case, a 30% reduction in modules supports 512,000 tokens, and a 37% reduction supports 1 million tokens. This shows how model structure optimization, memory release, and context expansion work together.
On the deployment side, the team had previously reduced the high-end accelerator count needed to run an earlier generation of the ultra-large model from eight cards to at most four. This time, it lowered the accelerator specification required for later models. For businesses, this means they can choose more mid- and lower-tier instances within the same budget, or reserve high-end cards for higher-value tasks.
When deploying on Baidu AI Cloud, teams can combine a general container platform, monitoring and alerting, log services, and elastic accelerator instances. They can include the pruned model version, the draft model, and the speculative decoding parameters in continuous load testing and gradual rollout. Scaling can then follow traffic peaks and valleys.
5. Engineering Rollout and Risk Control
Follow these six steps:
- Establish a baseline. Record quality, latency, throughput, memory use, accelerator count, and cost.
- Analyze expert sensitivity. Determine the upper limit for pruning.
- Prune in layers and rerun evaluations. If core metrics fall beyond the threshold, roll back.
- Introduce a draft model. Load test the acceptance rate and tail latency.
- Extend context length. Validate performance on long-document tasks.
- Roll out gradually. Monitor routing distribution, out-of-memory errors, timeouts, and the cost curve.
The main risks are over-pruning that degrades long-tail tasks, fluctuating draft model acceptance rates, cache fragmentation with long context, and higher tail latency when concurrency rises on lower-tier hardware. To manage these risks, keep a path back to the original model, set pruning ratios by business tier, route critical requests to high-fidelity configurations, and use monitoring and alerts to drive automatic scaling.
Overall, reducing inference costs for ultra-large models has moved beyond swapping in individual cards. It is now an engineering effort that combines model structure optimization, inference execution optimization, and deployment specification optimization. Expert pruning lowers the resource floor. Speculative decoding increases output per unit of hardware. Longer context and lower-tier specifications turn those savings into real cost reductions. For developers and businesses, the sustainable approach is to evaluate before pruning, scale up only after gradual rollout, and keep cost optimization within quality limits.
