LLM Inference Cost Reduction: Practical Expert Pruning and Speculative Decoding
Reducing MoE inference costs requires two things at once: making model weights fit on cheaper GPUs and generating more tokens per GPU-hour. This article explains how expert pruning mainly addresses the first goal and speculative decoding mainly addresses the second, while both depend heavily on model architecture, workload distribution, and hardware. It covers MoE memory composition, structured expert pruning workflows and risks, speculative decoding acceptance rules and parameter choices, and why long-context serving is constrained by KV cache rather than model weights alone.
Bottom Line
MoE inference cost reduction requires handling two things at the same time. First, model weights need to fit on cheaper GPUs. Second, each GPU needs to generate more tokens per hour. Expert pruning mainly addresses the first problem, while speculative decoding mainly addresses the second. The actual gains from both depend on your model, workload distribution, and hardware, so they must be measured in your own environment.
1. Why Trillion-Parameter MoE Models Consume So Much GPU Memory
A mixture-of-experts model activates only a small number of experts per token, but the weights of all experts must remain resident in GPU memory. If experts are loaded only when a request arrives, time to first token increases noticeably. Therefore, inference memory is mainly composed of three parts:
| Memory component | What it scales with | Can expert pruning reduce it? |
|---|---|---|
| Model weights | Parameter count and storage precision (e.g., BF16, FP8, INT4) | Yes; deleting experts reduces it directly |
| KV cache | Number of layers, KV heads, head dimension, context length, concurrency | Usually no; pruning does not change the attention structure |
| Activations and temporary buffers | Batch size, sequence length, inference framework implementation | Mostly no |
This table is the basis for all the judgments that follow. Many teams assume that pruning a batch of experts will directly enable longer contexts. In reality, only the weight portion shrinks; the per-token KV cache footprint does not change.
2. How to Perform Structured Expert Pruning
Structured pruning removes entire expert modules as a unit, directly shrinking tensor shapes, and inference frameworks do not need to change their computation logic. Unstructured pruning sets scattered weights to zero; it usually requires sparse compute kernels to achieve speedups, and on general-purpose frameworks it often shows no benefit. Therefore, for MoE models, deleting experts is usually easier to deploy.
A complete pruning process generally includes the following steps:
- Measure activation frequency. Run a representative set of requests through the model and record how often each expert is selected by the gating network, as well as its contribution to the output. The statistics should cover the real workload distribution. Using only public benchmarks can easily miss low-frequency but important long-tail tasks.
- Define the candidate set. Select experts with very low activation rates and little contribution on critical tasks. The candidate set should not be based only on average activation rate; also check whether some experts serve only specific workloads.
- Delete experts and adjust routing. After experts are deleted, the output dimension of the gating network must shrink accordingly. Routing probabilities originally assigned to deleted experts need to be renormalized, or truncated and taken over by other experts.
- Calibrate and recover capability. Use a small amount of data for fine-tuning or knowledge distillation to recover the capability loss caused by deleting experts. The quality of calibration data directly affects recovery; it is advisable to keep some samples close to production traffic.
- Evaluate across multiple dimensions. Evaluation should include general question answering, code, mathematical reasoning, long-document understanding, and your own production samples. A higher score on a single benchmark does not mean online quality is acceptable.
Three categories of risk need particular attention during pruning:
- Uneven expert load. After deletion, the remaining experts may handle most requests, and some GPUs may become bottlenecks.
- Routing collapse. The gating network selects only a few experts for a long time, reducing output diversity.
- Long-tail task degradation. Metrics for high-frequency tasks look normal, but error rates for low-frequency tasks rise noticeably.
Pruning fits scenarios where all of the following conditions hold: the workload distribution is relatively stable, the team can perform fine-tuning or distillation, and the model itself has obvious expert redundancy. If these conditions are not met, the quality risk usually outweighs the cost benefit.
For each pruning run, record the following metrics so results can be compared before and after:
| Recorded item | Description |
|---|---|
| Pruning ratio | Number of deleted experts as a share of the original total |
| Evaluation set and version | Data source, sample count, and evaluation script version |
| Baseline and post-pruning scores | Comparison under the same evaluation protocol |
| Peak memory | Stable memory after loading and peak memory under high concurrency |
| Time to first token and P99 latency | Measured under low and high concurrency respectively |
3. Speculative Decoding: Principles and Parameter Choices
Traditional autoregressive generation produces only one token per step, and each step requires a full run of the large model. Speculative decoding works as follows: a smaller draft model first generates k candidate tokens quickly, and then the target model verifies these k positions in parallel with a single forward pass. Tokens that pass verification can be output in one batch, so each round can produce multiple tokens.
Acceptance criteria differ by decoding mode.
- Greedy decoding. A draft token is accepted only when it matches the argmax result of the target model at the same position. At the first mismatch, discard that position and all subsequent draft tokens, and use the target model’s output at that position.
- Sampling decoding. A draft token is accepted according to a probability ratio, with acceptance probability min(1, p_target / p_draft). When rejected, resample from a corrected distribution. The corrected distribution is obtained by taking the positive part of the target distribution minus the draft distribution and then normalizing it. Under these rules, the output distribution is theoretically identical to sampling directly from the target model.
Speedup can be estimated roughly. If the acceptance rate is approximately the same across positions, denoted as α, and the draft length is k, then the average number of tokens produced per verification round is approximately (1 − α^(k+1)) / (1 − α). For example, when α is 0.8 and k is 4, the result is about 3.4 tokens. This estimate ignores draft model latency and batch effects; it can only be used for initial screening, not as an online commitment.
The following checklist covers parameter selection:
| Parameter | Impact on results | Tuning advice |
|---|---|---|
| Draft model size | If the draft model is too large, draft generation latency offsets the gains | Use the same tokenizer as the target model and ensure remaining memory can hold it |
| Draft length k | A larger k increases potential gain per round, but also wastes more compute on rejection | Start with 2 and adjust gradually based on acceptance rate |
| Acceptance rate α | Directly determines the actual speedup | Measure on real production requests, not random text |
| Concurrency and batch | At high concurrency the GPU approaches saturation, and speculative decoding gains may decline | Test low-concurrency and high-concurrency scenarios separately |
| P99 latency | Switching between draft and verification may increase tail latency | Monitor both P50 and P99, not just average throughput |
When the acceptance rate is low, the usual cause is a large distribution gap between the draft model and the target model, or a large difference between production text and the draft model’s training data. In this case, consider replacing the draft model or lightly adapting the draft model with production data.
4. Long Context: Enough Memory Does Not Mean It Is Usable
The KV cache footprint per token can be estimated with the following formula:
KV cache bytes per token = 2 × number of layers × number of KV heads × head dimension × bytes per element
For example, assume a model has 60 layers, 8 KV heads, a head dimension of 128, and stores in BF16. Then the KV cache per token is approximately 2 × 60 × 8 × 128 × 2 = 245,760 bytes, or about 240 KB. If a single request reaches a context of 131,072 tokens, the KV cache alone requires about 30 GiB. This number does not yet include weights, concurrency, or framework overhead.
This example shows that long context is mainly constrained by KV cache. Pruning reduces weights, so it frees memory that can be used by other memory consumers, but it does not change the per-token KV cache footprint.
