Reducing LLM Inference Costs: Combining Expert Pruning and Speculative Decoding
This article explains how to lower large language model inference costs by pruning experts in a mixture-of-experts model and using the freed memory for speculative decoding. It covers how serving costs break down, how pruning reduces weight size and supports longer context, how a draft model speeds up generation, and a step-by-step workflow for checking quality before deployment.
1. Background: The Inference Cost Pressure of Very Large Models
Parameter counts keep growing, and hardware costs for inference rise with them. Model weights must stay resident in GPU memory. More parameters mean more memory capacity and higher memory bandwidth are needed. For businesses, inference cost usually has three parts: one-time hardware purchases, GPU rental charged by the hour in the cloud, and lost service capacity caused by low concurrency or slow responses.
In one publicly reported case, a research team systematically optimized a mixture-of-experts model with a total parameter count in the trillions. After optimization, GPU purchase costs fell by up to about 20%, and cloud GPU rental costs fell by up to about 22%. These results show that cost reduction does not always require more hardware. It can also start with model architecture and the inference workflow.
2. Breaking Down the Sources of Cost
Before optimizing, separate the costs. Three metrics determine the unit cost of an inference service.
- Memory usage: Weights, the KV cache, and activations together occupy GPU memory. Longer context means a larger KV cache.
- Compute throughput: The number of tokens generated per unit of time determines how many users a single GPU can serve.
- Hardware specification: Whether GPU memory can hold the complete model determines whether a lower-tier GPU can be used or fewer cards are needed.
These three factors constrain each other. Reducing compute without reducing memory often does not allow a switch to cheaper hardware. Reducing memory without maintaining throughput does not lower unit cost either. A sound plan therefore considers all three metrics together.
3. Path One: Expert Module Pruning
A mixture-of-experts model consists of multiple expert subnetworks, and each input activates only some of them. Many experts mean a large total weight count, but the compute for a single inference pass depends on the number of activated experts. This creates room for pruning. If some experts contribute little to the target task, they can be removed to reduce weight storage.
The key to pruning is judging expert importance. Common approaches include:
- Measuring each expert’s routing frequency and activation strength on the target dataset;
- Masking experts one at a time and observing how much core evaluation metrics drop;
- Recalibrating routing weights for the retained experts to compensate for the distribution shift caused by removal.
In the case described above, the number of expert modules was reduced by up to about 37%. The model still reached more than 99% of the original model’s score on a challenging scientific reasoning benchmark. This result depends on how closely the chosen evaluations match real business use. If the business covers a wide range of tasks, the pruning ratio should be more conservative, and each task type should be validated separately.
4. Path Two: Using the Saved Memory for Speculative Decoding
The memory freed by pruning can host a small draft model. The basic speculative decoding process works as follows:
- The draft model quickly proposes several candidate tokens that follow.
- The main model runs one parallel forward pass over these candidates and decides whether to accept each one.
- Candidates after the first rejected position are discarded. The main model outputs its own token at that position, and the process repeats.
Because the main model can verify several tokens in one forward pass, the average number of tokens generated per step increases, and end-to-end latency drops. The draft model’s acceptance rate is the key metric. When the acceptance rate is low, drafting only adds overhead. The draft model should therefore be aligned with the main model on the same corpus, and the acceptance rate should be measured on real requests.
In the case study, 8 high-end GPUs were enough to run inference, and generation speed improved. This shows a positive feedback loop between memory savings and speculative decoding. Enough memory allows the draft model to fit. A faster draft model then lets the same hardware serve more requests.
5. Prerequisite for Lowering the Hardware Tier: Memory Estimation
Whether a lower-tier GPU can be used depends on whether memory can hold the weights plus runtime overhead. The following simplified formulas give a rough estimate:
Required memory ≈ weight memory + KV cache + activation and framework overheadWeight memory ≈ parameter count × bytes per parameter
Take a 100-billion-parameter model stored in BF16, where each parameter takes 2 bytes. The weights need about 200 GB. If the expert modules are reduced by 30%, the weight size drops to roughly 140 GB. The exact figure depends on the share of shared layers and embedding layers. The remaining memory can then be allocated to the KV cache and the draft model.
Keep in mind that this is a rough estimate. Actual deployment also depends on the tensor parallelism scheme, communication overhead, and memory fragmentation. The estimate is only a starting point for hardware selection. Final decisions must be based on measured results.
6. How Context Length Relates to Memory
Context length is another major variable. The KV cache size scales roughly linearly with sequence length, so long contexts consume memory quickly. After pruning, the memory budget becomes looser, and the same hardware can support longer contexts.
In the case study, the version with a 30% module reduction supported a context of about 512K tokens. The version with a 37% reduction supported about 1 million tokens. When choosing a version, teams should consider their traffic pattern. If most requests are short, a version with a higher retention rate is the safer choice. If long-document processing is common, quality under long context should be validated first.
7. Implementation Steps
The following general workflow applies to any large model with an expert structure.
# Illustrative workflow. Variable and function names are for explanation only# and do not correspond to the interface of any specific library.def optimize_moe_inference(model, eval_set, prune_ratio_candidates):baseline = evaluate(model, eval_set)candidates = []for ratio in prune_ratio_candidates:pruned = prune_experts(model, ratio, calib_data=eval_set)score = evaluate(pruned, eval_set)retention = score / baselineif retention >= 0.99:candidates.append((ratio, retention, pruned))best = max(candidates, key=lambda c: c[0])draft = build_draft_model(best[2], size="small")accept_rate = measure_acceptance(best[2], draft, eval_set)return best, accept_rate
The workflow has four steps:
- Establish a baseline: On an evaluation set relevant to the business, record the original model’s quality metrics, latency, and throughput.
- Prune in tiers: Remove experts at different ratios and record the quality retention for each tier.
- Select a version: Among versions that meet the quality threshold, choose the one with the highest pruning ratio, and calculate the remaining memory headroom.
- Deploy speculative decoding: Train or select a draft model, measure its acceptance rate, and confirm the end-to-end gain.
Keep reproducible records at every step, including data versions, random seeds, and hardware configurations.
8. Risks and Evaluation
Pruning and speculative decoding both change model behavior, so explicit risk controls are needed.
- Quality risk: After pruning, some edge-case tasks may degrade noticeably. Break evaluations down by task type instead of relying only on the overall score.
- Distribution shift risk: If calibration data differs from live traffic, routing may deviate from expectations. Regularly re-validate using sampled production data.
- Performance variability risk: The draft model’s acceptance rate varies with input type. Load test under peak traffic and monitor tail latency.
- Rollback risk: Before a new version goes live, keep the original model available and use a gradual, percentage-based traffic switch.
Evaluation metrics should cover four areas: quality, latency, throughput, and cost per token. Optimizing one area while sacrificing the others will not improve overall results.
9. Summary
Reducing LLM inference cost requires coordinated changes to model structure, memory use, and the decoding process. Expert pruning reduces weight size while keeping core capabilities. The freed memory can support longer context and host a draft model, which increases throughput through speculative decoding. Whether a lower hardware tier can be used should be decided by both memory estimates and measured results. Following the workflow of establishing a baseline, validating each tier, selecting a version, and then deploying acceleration, teams can lower purchase and rental costs while controlling quality risk, and make better use of existing AI infrastructure.
