Reducing LLM Inference Costs with MoE Pruning and Speculative Decoding
This practical guide explains how to estimate memory requirements for mixture-of-experts models, prune low-contribution experts, use freed memory for speculative decoding, measure cost and latency consistently, roll out changes safely, and reduce idle cloud capacity. It also highlights the trade-offs involving KV cache usage, load balancing, acceptance rates, long-context quality, and autoscaling.
1. Start with an Accurate GPU Memory Budget
Mixture-of-experts (MoE) models divide their feed-forward layers into multiple expert subnetworks, while activating only a small number of experts for each token. However, the routing decision is not known before computation begins. During inference, the weights of all experts must therefore remain resident in GPU memory.
As a result, memory usage is determined by the total parameter count, not by the number of parameters activated for each token.
For a 2.8-trillion-parameter model, the weight memory is approximately:
- BF16 or FP16: 2 bytes per parameter, or about 5.6 TB
- FP8: 1 byte per parameter, or about 2.8 TB
- INT4: 0.5 bytes per parameter, or about 1.4 TB
These figures cover weights only. A production deployment must also account for the KV cache, activations, framework overhead, and additional expert replicas used to improve throughput.
KV-cache usage increases with concurrency and context length. In long-context workloads, it can consume more memory than the model weights themselves. Multi-node deployments also introduce interconnect communication, which can increase per-token latency.
Deployment planning should therefore calculate the following separately:
- Model weights
- KV-cache capacity
- Target concurrency
- Redundant or throughput-oriented expert replicas
Parameter count alone is not an adequate capacity-planning metric.
Some deployment reports have claimed GPU procurement savings of roughly 20% and cloud rental savings of approximately 22% after inference-cost optimization. Such figures depend on the model, workload, and measurement methodology. They should be reproduced with your own data rather than applied directly to another deployment.
2. Prune Experts Only After Meeting the Prerequisites
The objective of expert pruning is to identify experts that contribute relatively little and remove them. A practical workflow is as follows.
1. Collect representative calibration data
Use calibration data that reflects real production traffic. Record the routing activation frequency and distribution for every expert.
If the calibration set consists only of general-purpose text, the resulting statistics may differ substantially from online traffic.
2. Calculate expert importance
Common indicators include activation frequency and estimated contribution to the output, such as metrics based on gradients or output norms.
Activation frequency alone can overlook experts that are rarely used but critical for specific tasks. In practice, it is safer to combine activation-based and contribution-based metrics.
3. Remove low-scoring experts
Remove experts from the lowest scores upward and update the router at the same time.
The router outputs corresponding to removed experts must be masked. The routing weights of the remaining experts must then be renormalized so that top-k selection continues to work correctly.
4. Check load balance
After the number of experts is reduced, the retained experts must process more tokens. If they are concentrated on only a few GPUs, those devices can become hotspots.
Reconsider the expert-parallel sharding strategy and measure the load ratio for every GPU.
5. Recover accuracy
Apply short-cycle distillation or fine-tuning to the retained experts using the calibration set.
6. Run acceptance testing
Use an internal evaluation suite that covers quality metrics, long-context regression, and latency.
At a minimum, acceptance criteria should include:
- Quality degradation on core tasks remains below the agreed threshold.
- Retrieval and question-answering accuracy remain acceptable at the target context length.
- Per-GPU load differences remain within an acceptable range, and p95 latency stays within budget.
- The original weight version is retained so that the system can be rolled back quickly if necessary.
Choose the pruning ratio conservatively
The results reported by public case studies depend on model size, calibration data, evaluation benchmarks, and measurement methodology. Their pruning ratios should not be transferred directly to another model.
As the pruning ratio increases, performance on long-tail tasks, less common languages, and very long contexts is more likely to degrade. A safer approach is to begin with a small pruning ratio and validate every level on an internal evaluation set instead of selecting a ratio based only on general-purpose benchmarks.
3. Use the Recovered Memory for Speculative Decoding
Once pruning frees GPU memory, the available capacity can be used to deploy a smaller draft model and accelerate generation.
The process has three stages:
- The draft model autoregressively generates k candidate tokens.
- The target model validates those candidates in a single forward pass.
- The system accepts the consecutive candidates that pass validation and resumes generation from the first rejected position.
The validation cost is not the same as validating one token
A common misunderstanding is that validating k candidate tokens costs the same as processing a single token. In fact, the target model performs one forward pass over k + 1 positions, so the computation increases as k increases.
The benefit comes primarily from memory bandwidth. Decoding is often bandwidth-bound. The target model’s weights need to be read from GPU memory only once while processing multiple positions. Consequently, wall-clock time may increase only modestly, while each decoding step can produce more tokens.
The expected number of tokens produced per step can be estimated from the acceptance rate α:
[
E = \frac{1 - \alpha^{k+1}}{1 - \alpha}
]
When the acceptance rate is 0.8 and k = 4, each step produces approximately 3.7 tokens on average. If the acceptance rate falls to 0.5, the same value of k produces only about 1.9 tokens.
Acceptance rate directly determines the benefit. The closer the draft model’s output distribution is to that of the target model, the higher the acceptance rate is likely to be.
MoE models require additional measurement
For an MoE model, a batch of k + 1 tokens may activate more experts than a single token. The resulting increase in expert-weight memory traffic can reduce the bandwidth benefit.
Therefore, the speedup from speculative decoding on an MoE model must be measured directly. Performance figures from dense models should not be applied without testing.
Implementation should also consider the following:
- The draft model consumes GPU memory through both its weights and KV cache. Include these requirements in the capacity plan.
- Under high concurrency, batching may already use the available memory bandwidth efficiently. In that case, speculative decoding may provide less benefit or introduce additional overhead.
- Sampling parameters must be compatible. Standard rejection sampling can preserve the target model’s output distribution. If custom sampling or constrained decoding is used, verify that the validation logic remains correct.
- Define an automatic disable rule. Monitor the acceptance rate and end-to-end throughput online. If they remain below a threshold for a defined period, disable speculative decoding automatically. The threshold should come from workload testing. As an initial reference, it can be set around cases where the speedup over ordinary decoding is below 10%, then adjusted using production data.
4. Build a Cost Baseline Before a Staged Rollout
Whether an optimization can be deployed safely depends on measuring the before-and-after changes with the same metrics and definitions.
Recommended metrics include:
- GPU memory capacity: Measure weights, KV cache, activations, and framework overhead separately at the target concurrency and context length.
- GPU memory bandwidth utilization: Use this to determine whether the bottleneck is capacity or bandwidth.
- Time to first token (TTFT) and time per output token (TPOT): Track both p50 and p95 values.
- Per-GPU throughput: Measure output tokens per second.
Unit cost:
[
\text{Cost per million output tokens}
=
\frac{\text{Hourly cost per GPU}}
{\text{Output tokens per second per GPU} \times 3600}
\times 1{,}000{,}000
]Adjust the result for the number of GPUs and redundant replicas.
The rollout should proceed in stages. Advance to the next stage only after the current stage meets its acceptance criteria throughout the observation window.
- 5% of traffic: Verify service stability and error rates. Metrics should remain comparable to the baseline.
- 20% of traffic: Compare sampled output quality and confirm that accuracy degradation remains within the agreed threshold.
- 50% of traffic: Validate p95 latency and request-queue length during peak periods.
- 100% of traffic: Keep instances running the previous version for a period of time to support rapid rollback.
Every stage should include context-length regression testing that covers the longest inputs used in production. Testing only short prompts is insufficient.
5. Use Cloud Elasticity to Reduce Idle Capacity
Autoscaling based on workload can further reduce idle cloud spending. However, large models often take a long time to load, so scaling policies require careful planning.
- Loading large model weights can take several minutes, creating cold-start delays during scale-out. Set a minimum instance count and route traffic only after warm-up is complete.
- Add a cooldown period to scale-in operations to prevent instances from being repeatedly started and stopped during short-term workload fluctuations.
- Monitor request-queue length, GPU memory usage, and p95 latency rather than relying only on CPU or GPU utilization.
- Set alert and scale-out thresholds based on the time required to add capacity. The longer scale-out takes, the earlier the system must trigger it.
6. Pre-Deployment Checklist
Both expert pruning and speculative decoding can reduce inference costs, but the actual benefit depends on the model, traffic pattern, and quality requirements.
Before deployment, verify that you have:
- A complete memory budget covering weights, KV cache, activations, framework overhead, and replicas.
- Calibration data that represents real production traffic.
- Expert-importance metrics that combine routing frequency with contribution estimates.
- Updated routing, renormalized weights, and a balanced expert-sharding plan after pruning.
- Internal quality, long-context, and latency evaluations for every pruning level.
- A compatible draft model and a measured speculative-decoding acceptance rate.
- Consistent baseline and post-optimization cost metrics.
- A staged rollout plan, automatic disable rules, and a tested rollback path.
- Autoscaling thresholds that account for model-loading and warm-up time.
