Reducing LLM Inference Costs: Expert Pruning and Speculative Decoding in Practice
This article explains how to cut the inference cost of large parameter models, especially trillion-parameter MoE systems, through three combined techniques: structured expert pruning, reusing freed memory for speculative decoding, and long-context memory budgeting. It covers how to score expert importance, guard against accuracy regression, tune draft-model acceptance length, estimate weight and KV Cache memory, and right-size hardware. Readers will also find practical guidance on baseline metrics, tiered serving, regression testing, and autoscaling.
1. Background: Inference Cost Pressure from Growing Parameter Counts
Among publicly downloadable ultra-large MoE (Mixture of Experts) models, total parameter counts have reached the trillion scale. The larger the parameter count, the more VRAM the weights themselves occupy. At the same time, the expert modules on the activation path become more dispersed, so a single GPU can no longer hold the model and multi-GPU parallelism becomes mandatory. This leads to three direct consequences:
- High hardware procurement barriers, requiring accelerators with higher specifications and greater memory bandwidth.
- Persistently high hourly cloud rental costs.
- In long-context scenarios, VRAM is quickly consumed by the KV Cache, causing throughput to drop sharply.
It is important to clarify that inference cost is not made up of “compute unit price” alone. Instead, it is the multiplicative effect of four factors: VRAM capacity, VRAM bandwidth, inter-GPU interconnect bandwidth, and batch concurrency. Any single-point optimization evaluated outside this system-level view can easily end up “saving VRAM without saving money.”
2. Optimization Path 1: Structured Expert Module Pruning
MoE models only activate a subset of experts during inference, yet all expert weights must remain resident in VRAM. The core judgment behind pruning is that not all experts are equally important to the target business.
- Importance measurement: Use a combined score based on each expert’s routing frequency on a validation set, the mean of its gating weights, and the KL divergence of the output distribution after its removal.
- Selective removal: Prioritize removing experts that are chronically under-activated and weakly correlated with core capabilities (such as scientific reasoning and code generation), rather than trimming uniformly.
- Accuracy guardrail: Use a public, high-difficulty reasoning benchmark as a regression gate, requiring the score to stay above 99% of the original; otherwise, roll back the pruning ratio.
An illustrative pruning workflow:
# Pseudocode: routing-statistics-based expert importance pruningscores = {}for batch in calibration_set:logits, idx = router(batch) # record gating distribution and hit expertsfor e, w in zip(idx, logits):scores[e] = scores.get(e, 0.0) + float(w)keep = set(sorted(scores, key=scores.get, reverse=True)[:int(N * (1 - prune_ratio))])pruned_model = drop_experts(base_model, keep) # keep only high-value expertsassert eval_on_gpqa(pruned_model) >= 0.99 * eval_on_gpqa(base_model)
An engineering caveat: after pruning, you must recalibrate the router’s normalization logic and apply moderate weight scaling to the remaining experts; otherwise, the output will exhibit systematic drift.
3. Optimization Path 2: Converting Saved VRAM into Throughput
The VRAM freed by pruning should not sit idle. Instead, it should be used to host a small-parameter “draft model.” The main model verifies multiple subsequent tokens proposed by the draft in a single pass, which is speculative decoding. The logic behind its benefit is that memory-bound single-token decoding is rewritten as a single parallel batch verification, significantly improving VRAM bandwidth utilization.
The key is the acceptance rate. The closer the draft model’s distribution is to the main model’s, the longer the accepted length and the higher the speedup; otherwise, it degrades into additional overhead. In practice, you can use “accepted length” as the core monitoring metric and jointly tune it with temperature and top-p sampling parameters.
# Pseudocode: speculative decoding main loopdraft_tokens = draft.generate(prompt, n=gamma)verified = target.verify(prompt, draft_tokens) # verify in a single forward passaccepted = len(verified)prompt = prompt + verifiedmetrics.observe(accepted_len=accepted, gamma=gamma)
4. Optimization Path 3: Long-Context VRAM Budgeting
Context length consumes VRAM roughly linearly with sequence length, and this scales with concurrency. With pruning and speculative decoding stacked together, the supportable context window is significantly extended. A recommended approach for capacity estimation:
- Estimate resident weight VRAM = parameter count × bytes per parameter (including the quantization scheme).
- Estimate KV Cache = layers × 2 × sequence length × hidden dimension × concurrency × bytes.
- Reserve 10%–15% headroom for activations and communication buffers.
- Work backward to derive the maximum context and concurrency combination that can be supported given the GPU count and per-GPU VRAM.
5. Deployment Results and Lowering Hardware Specs
The direct value of this combined optimization shows up in two directions: the hardware procurement scale per unit of inference drops by about 20%, and cloud rental spending drops by more than 20%. More importantly, the required accelerator spec tier can be lowered by one level, allowing existing infrastructure to be used more fully. The industry has previously compressed the GPU count requirement for the same-generation model by nearly half; the significance of this round of optimization is shifting from “piling on GPUs” to “using GPUs well.”
6. Recommendations for Enterprise Practice
- Measure before optimizing: Establish three baseline metrics—token cost, P99 latency, and accepted length—to avoid tuning by feel.
- Tiered service: Route simple requests to the small model or a high-pruning-ratio version, and complex requests to the full model.
- Continuous regression: Run a full accuracy regression on every pruning or quantization change to prevent silent capability degradation.
- Elastic scaling: Configure queue-length-based autoscaling on the container platform and monitoring/alerting system, turning cost reduction into an actual bill reduction.
Overall, inference cost reduction for ultra-large parameter models is no longer a single-point trick, but systems engineering that combines “structural pruning + VRAM reuse + decoding parallelism + capacity budgeting.” Baidu AI Cloud continues to invest in model serving and elastic compute scheduling, providing general-purpose capabilities to help enterprises make better use of their existing AI infrastructure at a more reasonable cost.
