LLM Inference Cost Reduction: Expert Pruning and Speculative Decoding in Practice

    This article examines how expert-module pruning and speculative decoding can reduce large language model inference costs. It covers the relationship between parameter scale and hardware cost, a workflow for pruning low-contribution MoE experts, using freed GPU memory to support speculative decoding, re-evaluating hardware specifications, a reference evaluation framework, and risk controls. Readers will learn how to connect model structure, inference strategy, and hardware selection to business metrics such as cost per million tokens, first-token latency, and maximum context length.

    1. Problem Background: Parameter Scale and Hardware Cost

    The parameter scale of large language models continues to grow. More parameters mean more weights must be loaded into GPU memory during inference, which increases memory usage. For mixture-of-experts (MoE) models, all expert weights must reside in GPU memory even though only a small subset is activated during a single inference pass. As a result, deployment cost is mainly determined by two factors: total GPU memory capacity and the number of compute devices required to meet throughput targets.

    In practice, enterprises usually encounter three types of problems:

    • Insufficient GPU memory requires more cards, which increases purchase or rental costs;
    • Low per-GPU throughput leads to high response latency and affects user experience;
    • In long-context scenarios, KV cache usage grows quickly, reducing the number of concurrent requests that can be handled.

    These problems share the same root cause: model weights and the inference process consume hardware resources. Reducing cost requires work across three layers at the same time: model structure, inference strategy, and hardware specifications.

    2. Core Approach: Reduce Footprint, Free Memory, Increase Output per Unit

    The optimization plan can be split into three steps:

    1. Remove parts of the model that contribute little to the target task, reducing weight size;
    2. Use the freed GPU memory to improve inference efficiency, for example by deploying an auxiliary small model;
    3. Re-evaluate available hardware specifications under the new resource constraints.

    These steps depend on one another and should not be viewed in isolation. If pruning does not translate into higher throughput or better context capability, reducing the parameter count alone has limited business value. If speculative decoding has no memory headroom, it cannot be deployed. Therefore, the design should start from business metrics and work backward to target values for each step, such as cost per token, first-token latency, and maximum supported context length.

    3. Expert Module Pruning: Removing Low-Contribution Modules

    A mixture-of-experts model consists of multiple expert subnetworks and a router. The router selects a small number of experts for each input token to participate in computation. If some experts are rarely activated on the data distribution of the target task, or contribute almost nothing to the output, they can be considered for removal.

    The pruning workflow usually includes the following stages:

    • Measure activation frequency: Record how often each expert is selected by the router and the weight distribution on a representative dataset;
    • Evaluate expert contribution: Mask experts one by one and observe changes in validation metrics to judge their importance;
    • Iterative removal: Remove the lowest-contribution batch of experts in each round and run regression tests after each round;
    • Fine-tuning recovery: Depending on the results, use a small amount of data for fine-tuning to repair distribution shifts caused by expert removal.

    There is no universal pruning ratio. One publicly reported case described a model that retained a score close to the original on a difficult scientific reasoning benchmark after removing about 30% of modules. However, this conclusion depends on the specific task and evaluation set. Enterprises should re-validate on their own business data rather than applying the ratio directly.

    Evaluation should cover multiple dimensions, including accuracy, long-text understanding, output stability, and safety and compliance behavior. A pruned model may degrade in some edge cases, especially niche domains that depend on a small number of experts. Such scenarios need separately designed test cases.

    4. Freeing GPU Memory for Speculative Decoding

    The GPU memory saved by pruning can be used in two ways. One is to reduce the number of cards and directly lower hardware spending. The other is to keep the same number of cards and use the headroom for other acceleration methods. Speculative decoding belongs to the latter.

    The basic speculative decoding process is as follows:

    1. A small draft model quickly generates several candidate tokens;
    2. The main model performs one forward pass over these candidates and verifies them in parallel;
    3. Candidate tokens consistent with the main model distribution are accepted. Remaining candidates after the first rejected position are discarded, and the main model supplies one token.

    The main model can confirm multiple tokens per forward pass, so overall generation speed has an opportunity to improve. The acceleration effect depends on the acceptance rate. The closer the output distributions of the draft model and the main model, the higher the acceptance rate is likely to be, and the more obvious the benefit. In practice, the draft model should preferably share the same origin as the main model or undergo dedicated alignment training.

    Note that speculative decoding adds extra GPU memory usage and scheduling complexity. The draft model weights, the KV caches of both models, and the batching strategy all need to be included in capacity planning.

    5. Re-evaluating Hardware Specifications

    After GPU memory demand decreases, the number of high-end devices originally required may fall, and some workloads may migrate to lower-tier devices. However, selection should not consider memory capacity alone. The following metrics should also be considered:

    Metric Description
    GPU memory capacity The sum of weights, KV cache, and draft model must be less than available GPU memory
    GPU memory bandwidth Determines the speed ceiling during decoding and significantly affects per-token generation
    Interconnect bandwidth A key factor in inter-card communication overhead during multi-GPU tensor parallelism
    Unit cost Converted to cost per million tokens based on purchase price or rental price

    When selecting hardware, compare the total cost of different configurations rather than only the price per card. Fewer cards with a higher price per card may not reduce total cost.

    6. Reference Implementation and Evaluation Workflow

    The following code shows the structure of an evaluation framework. The functions are placeholders and should be replaced with interfaces provided by the inference framework and evaluation tools in actual use.

    1. def score_experts(model, calib_data):
    2. # Measure activation frequency and average routing weight for each expert on calibration data
    3. ...
    4. def select_lowest(scores, target_ratio):
    5. # Sort by contribution from low to high and return expert IDs to remove
    6. ...
    7. def remove_experts(model, expert_ids):
    8. # Remove specified experts from the model and update the routing table
    9. ...
    10. def prune_experts(model, calib_data, target_ratio):
    11. scores = score_experts(model, calib_data)
    12. to_remove = select_lowest(scores, target_ratio)
    13. return remove_experts(model, to_remove)
    14. def evaluate(model, eval_set):
    15. # Return metrics such as accuracy, long-context score, and output stability
    16. return run_benchmarks(model, eval_set)
    17. def cost_per_million_tokens(gpu_count, hourly_price, throughput_tps):
    18. # throughput_tps is the number of tokens generated per second
    19. cluster_cost_per_hour = gpu_count * hourly_price
    20. tokens_per_hour = throughput_tps * 3600
    21. return cluster_cost_per_hour / tokens_per_hour * 1_000_000

    The evaluation workflow should preferably be executed in the following order: first obtain reference metrics for the baseline model on a fixed evaluation set; then prune iteratively and record quality changes; next stress-test throughput and latency on the target hardware; finally compare candidate configurations with the unit cost function and select the lowest-cost option that meets the quality red line.

    7. Risks and Controls

    • Quality regression: Establish a fixed evaluation set, compare key metrics after each pruning round, and set an acceptable degradation limit;
    • Long-context capability: Test information recall and reasoning performance separately for the target context length;
    • Distribution shift: Monitor online input distribution. If it differs significantly from the calibration data, re-evaluate expert contribution;
    • Rollback capability: Keep the original weight version and support fast switching during deployment so service can be restored if problems occur.

    8. Conclusion

    Parameter scale directly determines deployment cost. Expert module pruning can reduce weight size, and the freed GPU memory can either reduce the number of cards or support acceleration methods such as speculative decoding. Hardware specifications should be reselected based on new memory, bandwidth, and interconnect metrics, and the overall cost per million tokens should be used as the basis for comparison. The key to the entire plan is to validate every step with business quality metrics and ensure that cost reduction does not come at the expense of service quality.