Cutting LLM Inference Costs: Expert Pruning and Speculative Decoding in Practice
This article presents a practical approach to reducing large language model inference costs by combining MoE expert pruning, speculative decoding with the freed GPU memory, and hardware sizing. It covers the main cost drivers, an evaluation workflow for pruning safely, memory planning for draft models, a unit-cost formula for GPU selection, and step-by-step recommendations for rolling out these optimizations in production.
1. The Problem: Model Scale vs. Inference Cost
Larger models are generally more capable, but inference-time resource consumption grows with them. Consider Mixture-of-Experts (MoE) architectures: total parameters can reach the trillion scale, yet only a subset of experts is activated per forward pass. Even so, all weights must stay resident in GPU memory—otherwise, routing to an unloaded expert triggers expensive swapping overhead.
Inference cost is mainly driven by three factors:
- Memory footprint: determines whether the model fits on a single GPU or node;
- Compute throughput: determines how many tokens can be generated per second;
- Context length: determines how fast the KV cache grows.
A common mistake when choosing hardware is focusing only on per-GPU compute while ignoring memory capacity and bandwidth. For autoregressive generation, the decoding phase is typically memory-bandwidth-bound rather than peak-FLOPS-bound. Comparing theoretical GPU performance alone often leads to wrong cost conclusions.
2. Three Levels of Cost Optimization
Inference cost reduction can be tackled at three levels: the model, the execution layer, and the hardware.
- Model level: reduce parameter count or numerical precision via pruning, quantization, or distillation.
- Execution level: increase per-unit-time output via speculative decoding, batching and scheduling, and KV cache management.
- Hardware level: choose GPU instances that match the model’s actual footprint instead of over-provisioning.
These levels interact. A smaller model leaves more room for concurrency at the execution level, and improved execution efficiency changes which hardware options are viable. Optimization should therefore proceed level by level, checking the impact on the other levels at each step.
3. Pruning Expert Modules
3.1 How It Works
Pruning removes structural units that contribute little to the target workload. In MoE models, those units are the expert networks. Routing statistics reveal how often each expert is activated, while ablation experiments quantify its contribution to the output.
3.2 Evaluation Workflow
- On a representative dataset, measure each expert’s activation frequency and observe metric changes through ablation.
- Set an upper bound on the pruning ratio and rank experts by contribution, lowest first.
- Remove experts incrementally, running regression tests on core benchmarks after each step.
- Once the pruning ratio is fixed, re-validate sub-scenarios such as long context, multilingual tasks, and code.
3.3 Risk Control
The biggest risk in pruning is uneven capability distribution. Some low-frequency experts may handle long-tail tasks, and deleting them outright causes noticeable degradation in specific scenarios. Evaluation should therefore be done per task dimension, not by looking at average scores alone.
The following illustrative pseudocode shows the evaluation logic:
def prune_experts(model, eval_set, max_ratio=0.3, tolerance=0.01):# Measure each expert's activation frequency and ablation impactstats = collect_routing_stats(model, eval_set)ranked = sorted(stats, key=lambda s: s.contribution)removed = []baseline = evaluate(model, eval_set)for expert in ranked:if len(removed) / model.num_experts >= max_ratio:breakcandidate = model.without(removed + [expert.id])score = evaluate(candidate, eval_set)if baseline - score > tolerance:breakremoved.append(expert.id)return model.without(removed)
This logic has three key elements: ranking by contribution, capping the pruning ratio, and using an accuracy regression threshold as the stopping condition. Missing any one of them can introduce unacceptable capability loss during compression.
4. Using the Freed Memory for a Draft Model
4.1 How Speculative Decoding Works
In speculative decoding, a small draft model quickly generates candidate tokens, which the large target model then verifies in parallel. A single forward pass by the large model can validate multiple positions. If candidates are accepted, one computation yields multiple tokens; rejected portions are resampled and corrected by the large model. In theory, the output distribution is identical to generating token by token with the large model alone.
4.2 Gains Depend on the Acceptance Rate
The speedup is largely determined by the acceptance rate. The closer the draft model’s output distribution is to the target model’s, the higher the acceptance rate. If acceptance is too low, the draft model’s extra computation slows the system down overall. Draft model selection should therefore be based on acceptance rate and end-to-end latency, not parameter count alone.
4.3 Memory Planning
The draft model requires additional space for weights and KV cache. Capacity planning should reserve room for:
- The draft model’s weights;
- KV caches for both the draft and target models;
- Headroom for peak usage when batch sizes grow.
Speculative decoding is only feasible if total usage stays below the device’s available memory.
5. GPU Sizing and Cost Accounting
5.1 Selection Steps
- Measure the model’s static footprint and runtime peak at the target precision.
- Estimate KV cache size based on the maximum context length.
- Work backward from the minimum concurrency that meets your latency target to determine the number of GPUs.
- Compare unit token cost across GPU types.
5.2 Cost Formula
Unit token cost can be approximated as:
Unit cost = hourly instance price ÷ effective output tokens per instance-hour
Effective output tokens must be measured under real workloads—theoretical peak throughput should not be used directly. Request length distribution, batching strategy, and timeout rates all significantly affect this number.
5.3 Caveats
Downsizing reduces purchase and rental costs, but may sacrifice memory bandwidth and interconnect capability. Communication overhead in multi-GPU tensor parallelism grows with GPU count. When selecting hardware, evaluate memory capacity, bandwidth, interconnect, and price together—don’t compare unit price alone.
6. Context Length vs. Module Count
Reducing the number of expert modules typically frees more memory, enabling longer contexts. However, KV caches grow quickly with context length, and the achievable length is still limited by attention implementation, paged cache strategy, and hardware capacity. Teams should load-test both typical and extreme context lengths from their actual workloads rather than designing services around theoretical values.
7. Practical Rollout Recommendations
- Establish a baseline: record accuracy, latency, throughput, and cost before optimizing.
- Validate incrementally: introduce one optimization at a time and attribute its impact individually.
- Build a regression suite: cover general reasoning, code, long-text, and safety refusal scenarios.
- Monitor production metrics: track acceptance rate, time-to-first-token, tail latency, and error rate.
- Keep a rollback plan: retain the original weights and configuration so you can switch back quickly.
8. Conclusion
Model pruning, speculative decoding, and hardware selection are not independent techniques. Combined thoughtfully, they reduce resource consumption while preserving core model capabilities. The key is to drive decisions with quantifiable metrics rather than a single headline number.
