Reducing LLM Inference Costs: Expert Pruning and Speculative Decoding in Practice
This article examines cost reduction for very large Mixture-of-Experts model inference, focusing on expert pruning and speculative decoding. It explains where memory, bandwidth, communication, and queuing costs arise, presents a contribution-based pruning workflow, and shows how freed memory can support draft models and longer context. It also outlines a cost model, evaluation metrics, canary rollout practices, and risks for reducing accelerator specifications without sacrificing quality or latency.
Reducing LLM Inference Costs: Expert Pruning and Speculative Decoding in Practice
1. Problem Background: Where Inference Costs Come From in Very Large MoE Models
As model parameter counts reach the trillion scale, Mixture-of-Experts (MoE) has become a common way to balance model capacity and computational efficiency. The core idea of MoE is that the model contains many expert modules, but each forward pass activates only a small subset of them. This controls the computation per pass while the parameter count grows. However, a large parameter count does not automatically mean low inference cost. In production deployment, cost mainly comes from four areas: memory capacity, memory bandwidth, cross-card communication, and request queuing.
First, a large number of expert modules and large weight volumes lead to high model loading and resident memory usage. Even if only some experts are activated per pass, all expert weights may still need to be distributed across devices. Memory capacity directly determines the number and specifications of required accelerator cards. Second, the routing mechanism introduces dynamic load: different requests activate different experts, which can create both hot experts and cold experts, causing local compute and bandwidth bottlenecks. Third, long-context scenarios significantly increase KV cache usage, further reducing the memory available for model weights. Finally, in cloud environments where resources are rented by accelerator-hour, failing to meet latency and throughput targets raises the cost per request.
Therefore, inference optimization cannot focus only on “computing faster.” It should also target “using less memory, scheduling more stably, and requiring lower specifications.” In public cases, an optimization team used expert pruning to free memory, then used the freed memory for a draft model and long-context support. Combined with speculative decoding to improve generation speed, this ultimately reduced procurement cost by about 20% and cloud rental cost by about 20%. This path has general reference value: first lower the resource floor, then use the freed resources to gain throughput and context capability, and finally reduce unit cost through specification downgrade.
2. Optimization Mainline: Free Memory with Pruning, Spend It on Speed and Context
Cost reduction for very large MoE inference can be abstracted into one mainline: identify low-contribution experts and prune them to free memory and bandwidth; reallocate the freed resources to draft models, long-context cache, or higher concurrency; improve output per unit time through speculative decoding; and ultimately reduce the required accelerator card specifications and count.
This mainline involves three constraints: quality, latency, and engineering. The quality constraint requires that core task metrics do not drop noticeably after pruning. The latency constraint requires that first-token latency and tail latency remain controllable. The engineering constraint requires that the pruned routing table, parallel partitioning, and deployment configuration remain maintainable. Without any one of these constraints, cost reduction may become “saving cards at the expense of user experience.”
In the public case, there is a clear tradeoff between pruning ratio and context capacity: a version with about 30% fewer modules can support hundreds of thousands of tokens of context, while a version with about 37% fewer modules can support million-token context. This shows that memory freed by pruning can be used not only to reduce card count but also to expand the context window. However, the higher the pruning ratio, the greater the risk of routing drift and long-tail capability degradation. Therefore, evaluation should be layered and staged.
3. Expert Pruning: From Routing Frequency to Contribution Evaluation
Expert pruning is not simply deleting modules that “look unimportant.” It requires estimating each expert’s contribution to the final output on a calibration set. Common signals include routing frequency, output norm after activation, sensitivity to the loss function, coverage of specific task distributions, and memory and bandwidth cost penalties. One practical scoring approach is as follows:
Input: expert set E, calibration samples D, target retention ratio rInitialize importance score s_e for each expertFor each sample in D:Record frequency f_e of routing to expert eCompute output difference d_e before and after removing eCompute memory footprint m_e and bandwidth cost b_e of eFor each expert e:s_e = α * f_e + β * d_e - γ * m_e - δ * b_eSort experts by s_e in descending orderKeep the top ceil(r * |E|) expertsRenormalize routing weights for affected layersCalibrate the pruned model with small-scale distillation or continued trainingOutput: pruned model, routing table, quality evaluation report
The key to this process is “contribution evaluation” rather than “frequency only.” High-frequency experts are usually important, but low-frequency experts may also cover critical long-tail tasks. Pruning only by frequency can easily cause a sharp drop in capability for specific domains. A more reliable approach is layer-wise pruning: keep more experts in shallow layers to maintain representation capability, and increase the pruning ratio moderately in deeper layers. At the same time, renormalize routing to avoid shifting the routing probability distribution after pruning.
The benefits of pruning appear in three areas. First, weight memory decreases, which can directly reduce the number of accelerator cards or lower the per-card specification. Second, expert-parallel communication volume decreases, reducing cross-card routing overhead. Third, after memory is freed, the KV cache budget can be expanded to support longer context or higher concurrency. In the public case, after pruning, core scientific reasoning benchmarks still retained more than 99% of the original scores. This indicates that with sufficient calibration and distillation, moderate pruning can achieve quality close to the original. However, this conclusion depends on the task distribution, and production environments must verify it with their own business data.
4. Speculative Decoding: Trading a Draft Model for Throughput
The memory freed by pruning can be used to deploy a lightweight draft model. The basic idea of speculative decoding is that the draft model first generates several candidate tokens quickly, and the main model verifies these candidate prefixes in parallel at once, accepting the longest matching prefix. This reduces the number of serial decoding steps in the main model. For generative inference, this method can improve throughput without changing the main model’s output distribution, and it is especially suitable for scenarios with spare memory and compute/memory-access constraints.
Pseudocode is as follows:
Loop until generation ends:Draft model generates k candidate tokensMain model computes verification probabilities for the candidate prefixes in parallelCompare from the beginning of the candidates and accept the longest matching prefixIf all candidates are accepted:Append the candidates and continueElse:Accept the matching partMain model generates one additional token, then continueDynamically adjust k based on acceptance rate
Three engineering points need attention. First, the distribution of the draft model and the main model must not diverge too much; otherwise, the acceptance rate will be low and verification overhead may slow throughput instead. Second, the draft model itself also consumes memory and must be included in the total memory budget. Third, under batched requests, different sequences have different acceptance rates, so the scheduler needs to dynamically adjust candidate length to avoid long-tail requests dragging down overall tail latency. In the public case, the freed memory was used to run an auxiliary draft model, enabling faster answer generation even on a smaller accelerator cluster. This is a typical example of “trading memory for speed.”
5. Cost Model and Specification Downgrade
Inference cost reduction must ultimately land on a cost model. A simplified cost per request can be expressed as:
Cost per request =(procurement depreciation or rental unit price × number of cards × occupancy time+ energy and cooling+ operations and scheduling overhead+ latency violation cost) / number of valid requests
Pruning and speculative decoding affect different terms: pruning reduces card count and specification requirements, speculative decoding increases valid requests, and long-context capability affects business coverage. In the public case, by compressing the accelerator cards required for operation from a higher-spec multi-card setup to a lower-spec fewer-card setup, and further lowering the specification level required for subsequent models, procurement cost fell by about 20% and cloud rental cost fell by about 20%. The logic is not simply “switching to cheaper cards.” It first lowers the resource floor through pruning, then runs the draft model and long context in the freed memory, and only then performs specification downgrade.
Specification downgrade should follow the order of “compress resources first, change specifications second, expand concurrency last.” If specifications are downgraded directly without pruning, memory may be insufficient or frequent swapping may occur. If pruning is done without evaluation, quality may degrade. If speculative decoding is implemented without controlling the draft model budget, it may crowd out main model memory. Therefore, cost optimization should be advanced as a system engineering effort.
6. Evaluation and Canary Rollout
Production environments should establish four types of evaluation metrics: quality, performance, resource, and cost. Quality metrics cover core business sets, long-tail tasks, and long-context question answering. Performance metrics include first-token latency, per-token latency, throughput, and tail latency. Resource metrics include peak memory, bandwidth utilization, expert load balance, and KV cache hit rate. Cost metrics include accelerator-hours per request, procurement depreciation, and cloud rental cost.
Canary rollout can be divided into three steps. The first step is offline replay, comparing output differences before and after pruning using historical requests and setting a quality degradation threshold. The second step is small-traffic canary rollout, splitting traffic by business line and observing tail latency and error rates. The third step is gradually expanding the pruning ratio and specification downgrade scope while keeping a fast rollback switch. For long-context businesses, evaluate separately whether context window expansion after pruning causes attention degradation, avoiding the situation where content “fits but is answered inaccurately.”
7. Risks and Best Practices
Main risks include: expert pruning causing long-tail capability degradation, insufficient routing renormalization causing uneven load, draft model distribution shift causing lower acceptance rate, long-context expansion crowding out concurrency budget, and tail latency increasing after specification downgrade. Corresponding best practices are: use business calibration sets rather than a single public benchmark; prune layer by layer and retain fallback experts; continuously monitor the routing table; dynamically adjust speculative decoding candidate length; schedule long-context requests and normal requests in separate pools; and use cost per valid request rather than per-card cost as the final metric.
Overall, the reusable path for reducing inference cost in very large MoE models is: use expert pruning to lower the resource floor, use memory reallocation to support draft models and long context, use speculative decoding to improve throughput, use specification downgrade to realize cost benefits, and use canary evaluation to control quality and latency risks. For enterprises, this method does not depend on a specific product model. The core is to connect model structure optimization, inference execution optimization, and service scheduling optimization so that existing AI infrastructure can be used well at a reasonable cost.
