Cutting LLM Inference Costs: Expert Pruning and Speculative Decoding in Practice
This article explains how expert pruning and speculative decoding can lower the cost of serving large language models. It covers the main cost drivers, a three-layer optimization approach, a pruning workflow, draft-model speculative decoding, context length trade-offs, cost modeling, a rollout plan, and the conditions under which this approach fits.
1. The Cost Bottleneck of Very Large Models
As parameter counts keep growing, inference cost is no longer just a matter of buying more accelerator cards. It is a systems problem shaped by memory capacity, memory bandwidth, parallel communication, batching efficiency, context length, and cloud rental prices. Larger models need more memory for weights, activations, KV Cache, temporary buffers, and communication. In sparse mixture-of-experts models, each request activates only some experts, but all expert weights must stay resident in memory or be swapped in on demand. Memory pressure remains significant.
Companies typically face two kinds of spending. The first is GPU purchase cost, which includes accelerator cards, servers, networking, and data center infrastructure. The second is cloud GPU rental, billed by card-hour or instance time. Purchase cost depends mainly on peak capacity and hardware class. Rental cost depends mainly on utilization and elastic scheduling. If a model needs many high-end cards that sit idle for long periods, the cost per token rises quickly. Cost reduction therefore does not come from simply switching to cheaper cards. It comes from rebalancing memory footprint, compute density, and concurrency through model compression, execution optimization, and service orchestration.
A publicly reported case showed that after inference optimization, a very large model could run on lower-tier accelerator cards, reducing GPU purchase cost by up to about 20% and cloud GPU rental cost by up to about 22%. The result suggests a clear link between model-side optimization and infrastructure selection.
2. Overall Approach: From Model Compression to Execution and Serving Optimization
The original practice can be summarized in three layers:
- Model compression: Prune task-specific experts to reduce the number of expert modules, which lowers weight and memory usage while preserving core inference quality as much as possible.
- Inference execution optimization: Use the freed memory to deploy an auxiliary draft model. Speculative decoding then lets the main model verify several candidate tokens in one pass, which speeds up generation.
- Serving and capacity optimization: Based on the lower memory and compute requirements, move to a lower hardware tier or reduce the number of cards per instance. Then redesign batching, context length limits, and elastic scheduling.
This approach does not aim only to make the model smaller. It converts the resulting resource headroom into higher throughput, longer context support, or cheaper hardware. For businesses, cost optimization must weigh quality, latency, throughput, and hardware fit together. No single metric is enough.
3. Expert Pruning: Reducing Modules to Free Memory and Hardware Headroom
In sparse expert models, expert modules are usually activated selectively by task or by token routing. The basic expert pruning method works as follows. Using routing statistics, activation frequency, task contribution, and calibration data, identify expert modules that contribute little to core tasks. Remove or merge them selectively to reduce the total module count. Publicly reported results indicate that the module count can be reduced by up to about 37% while keeping more than 99% of the original score on a high-level scientific reasoning benchmark. The key is selective pruning, not uniform trimming. Experts that matter for core reasoning chains, long-context understanding, and key tasks must be kept. Experts that are highly redundant, rarely routed, or easily replaced by others are the candidates for removal.
In engineering terms, expert pruning should include these steps:
- Calibration set construction: Cover core business questions, long-document understanding, code reasoning, multi-turn dialogue, and edge cases. Do not evaluate on a single task type.
- Importance scoring: Combine routing frequency, activation contribution, gradient sensitivity, and output perturbation to rank experts by importance.
- Progressive pruning: Prune a small share first, re-evaluate, then increase the ratio step by step. This avoids breaking routing balance all at once.
- Quality gates: Set thresholds for core benchmarks, business evaluation sets, refusal behavior, and safety policies separately. Roll back any version that misses a threshold.
- Structural remapping: After pruning, update the expert index and routing table so that the inference graph, weight layout, and parallel partitioning stay consistent.
Illustrative pseudocode:
for ratio in [0.10, 0.20, 0.30, 0.37]:score = evaluate_expert_importance(calibration_set)pruned_model = prune_experts(base_model, score, ratio)quality = run_eval(pruned_model, core_benchmarks + business_cases)if quality.core_score >= threshold and quality.business_score >= threshold:candidate[ratio] = pruned_modelelse:break
The direct benefits of pruning are lower weight footprint, reduced memory pressure, and possibly less expert-parallel communication and routing overhead. The indirect benefits are the option to use lower-tier accelerator cards, or to support longer context and larger batches on the same number of cards. Pruning ratio and quality are not linearly related. Beyond a certain threshold, the risks of routing imbalance, degradation on long-tail tasks, and loss of long-context capability rise noticeably. Capacity decisions must be based on business evaluations.
4. Draft Models and Speculative Decoding: Turning Saved Memory into Throughput
The memory freed by expert pruning does not have to go entirely toward lowering hardware tier. Part of it can host a lightweight draft model. The draft model proposes several candidate tokens in advance. The main model then verifies these candidates in parallel through speculative decoding, accepting several correct tokens at once. This reduces the number of serial decoding steps the main model must run. For generative inference, the method is more likely to improve throughput when outputs are long and acceptance rates are high.
Key engineering considerations include:
- Draft model selection: The draft model should have a distribution close to the main model and should be small and low-latency, so that draft generation does not become a new bottleneck.
- Candidate length control: Too few candidate tokens yield limited gains. Too many increase verification cost. Tune the length against the business workload.
- Acceptance rate monitoring: Track acceptance rates separately for each task type. Fall back to standard decoding where acceptance is low.
- Memory budget allocation: Plan draft model weights, main model weights, KV Cache, and batching buffers together. Avoid a situation where the memory saved by pruning is consumed by the draft model.
- Batching and scheduling: Speculative decoding changes the shape of the compute graph, so batch size, concurrency, and tail latency must be reevaluated.
Publicly reported practice indicates that responses can also be generated faster on an environment with eight high-end accelerator cards. The point is not the specific card model. The point is that combining expert pruning to free memory, a draft model, and speculative decoding can improve generation efficiency without upgrading hardware. When deploying in production, teams should track end-to-end P95 latency, cost per token, and acceptance rate as core metrics, not just per-step decoding speed.
5. Context Length and Memory Trade-offs
Context length strongly affects KV Cache and activation memory. Publicly reported results show that a version with about 30% fewer modules can handle a context of about 512,000 tokens, and a version with about 37% fewer modules can handle about 1 million tokens. This shows that memory freed by pruning can be reallocated to long-context caching. However, longer context has costs. A larger KV Cache increases memory use, attention computation, and scheduling complexity, and it reduces room for batching.
Context limits should therefore be configured by business tier:
- Use shorter context for general Q&A and short documents to preserve more concurrent capacity.
- Use medium context for long-document analysis and multi-turn dialogue, combined with chunking, summarization, and retrieval to reduce unnecessary context.
- Assign ultra-long context tasks to a separate pool, limit their concurrency, and set timeouts and degradation strategies so they do not crowd out online serving capacity.
Illustrative capacity configuration:
if expert_prune_ratio == 0.30:max_context_tokens = 512_000elif expert_prune_ratio == 0.37:max_context_tokens = 1_000_000else:max_context_tokens = baseline_contextreserve_memory = model_weights + kv_cache(max_context_tokens, batch_size) + draft_model + runtime_bufferassert reserve_memory <= gpu_memory_budget
6. Cost Model: Evaluate Purchasing and Renting Separately
Cost reduction should be evaluated with a reusable cost model. For purchasing, the focus is total cost of ownership, including accelerator card class, number of servers, networking, data center space, operations, and depreciation. For renting, the focus is the card-hour price, utilization, elastic scaling, and idle cost. A simplified formula is:
Cost per token =(cost per card-hour × number of cards × runtime hours + allocated networking/storage/operations cost)/ number of effective output tokens
After optimization, three changes should be tracked: whether the number of cards needed per instance has decreased, whether lower-tier cards can still meet the SLA, and whether throughput per unit time has increased. Publicly reported practice indicates that the number of high-end accelerator cards needed to run a very large model was reduced from eight to at most four, and the hardware tier was then lowered further. For businesses, the lesson is to reduce card count first through pruning and parallelism strategy, lower unit price second by moving to a lower hardware tier, and raise throughput third through speculative decoding and batching. Only the combination of these three steps produces sustainable cost reduction.
7. Rollout Steps and Monitoring Metrics
The following phased plan is recommended:
- Baseline measurement: Record peak memory usage, throughput, P95 latency, context limit, cost per token, and business quality scores for the original model.
- Expert importance analysis: Build a calibration set that covers core business use cases, then produce expert scores and candidate pruning ratios.
- Progressive pruning and regression testing: Validate at 10%, 20%, 30%, and 37% pruning ratios in turn. Set quality gates and rollback points.
- Draft model adaptation: Evaluate draft model size, acceptance rate, and end-to-end latency. Determine candidate length and fallback strategy.
- Hardware tier reselection: Select accelerator card class, number of cards per instance, and parallelism strategy based on the memory budget and SLA.
- Service orchestration: Split traffic into a short-context pool, a long-context pool, and a fallback pool for low-acceptance requests. Configure rate limiting, timeouts, and degradation.
- Continuous monitoring: Track peak memory usage, KV Cache hit rate, batch size, acceptance rate, P95 and P99 latency, error rate, cost per token, and business quality scores.
In cloud environments such as Baidu AI Cloud, general-purpose services like container platforms, object storage, log services, and monitoring and alerting can support this workflow. The specific choices should be based on SLA, budget, and compliance requirements. Monitoring should focus on memory overflow, routing imbalance, sudden drops in acceptance rate, and queue buildup in long-context requests.
8. Risks, Boundaries, and Applicability
This approach does not suit every model or task. Expert pruning depends on the model having a prunable sparse structure. If experts are tightly coupled or routing is nearly uniform, pruning can cause significant quality loss. Speculative decoding depends on the alignment between the draft model and the main model and on task acceptance rates. In low-acceptance scenarios, it can add overhead instead of saving time. Context expansion is limited by memory and scheduling, so pruning alone cannot extend context indefinitely. After moving to lower-tier hardware, teams must also verify that memory bandwidth, interconnect, and failure domains still meet the SLA.
Teams should therefore follow this order of priorities: quality gates first, cost optimization second, and capacity elasticity as a fallback. Protect core task quality and stability first. Then expand the pruning ratio and hardware downgrade gradually. Keep fallback paths for long-tail tasks, and give long-context and low-acceptance requests separate resource pools. Only by coordinating model compression, inference execution optimization, and service orchestration can a one-time optimization become a repeatable infrastructure cost reduction capability.
