Reducing Inference Costs for Ultra-Large Models: Expert Pruning and Speculative Decoding in Practice

    This article explains how to lower inference costs for ultra-large sparse Mixture-of-Experts (MoE) models. It covers expert pruning with quality gates, using the freed GPU memory for a draft model with speculative decoding, and choosing lower-tier or fewer accelerator cards based on long-context and capacity needs. It also outlines a practical workflow for validating and rolling out these changes.

    1. Background: The Cost Bottleneck of Ultra-Large Sparse Models

    As Mixture-of-Experts (MoE) architectures become common in models with very large parameter counts, model capabilities improve, but inference costs rise quickly. Such models can reach trillions of total parameters. Although each forward pass activates only a subset of experts, weight storage, expert routing, communication buffers, the KV Cache, and temporary activations still consume large amounts of memory and accelerator resources. Organizations that deploy models privately or rent cloud capacity typically face two direct costs: accelerator purchase costs and rental costs billed per card-hour. Both depend heavily on the number of cards required, the card specification, and utilization.

    Cost reduction therefore cannot rely only on cheaper hardware. It also requires coordinated optimization across model structure, runtime scheduling, and service orchestration. One reusable approach follows three steps. First, reduce weight and memory pressure through expert pruning. Second, use the freed memory to deploy a draft model and enable speculative decoding. Third, choose a lower-tier accelerator or fewer cards based on long-context requirements and capacity evaluation. In public optimization cases, purchase costs fell by about 20% under certain configurations, and cloud rental costs fell by about 22%. These ratios depend heavily on model structure, task distribution, and concurrent load, so they should not be applied directly to other workloads.

    2. Solution Overview: Pruning, Memory Reallocation, and Decoding Acceleration

    The solution has four stages:

    1. Expert pruning: Identify expert modules that contribute little to the target tasks, and remove them in a set proportion. This reduces total parameters and weight memory usage.
    2. Quality gate: Run regression evaluations on task suites covering scientific reasoning, code, math, and long-document understanding. Confirm that core capabilities do not degrade noticeably.
    3. Memory reallocation: Use the memory freed by pruning to deploy a small draft model or to expand the KV Cache budget for longer contexts.
    4. Speculative decoding and accelerator downgrade: The draft model proposes subsequent tokens, and the main model verifies them in parallel, accepting several tokens at once to speed up generation. Once throughput and latency targets are met, lower the accelerator specification or reduce the number of cards.

    The key to this solution is not any single technique. It is the linkage between quality, memory, speed, and cost. If the pruning ratio is too low, cost gains are limited. If it is too high, expert routing coverage and quality stability may decline. A draft model that is too small has a low acceptance rate, while one that is too large takes resources from the main model. A closed loop of unified quality gates and a capacity model is needed to evaluate these trade-offs.

    3. Expert Pruning: From Parameter Reduction to Quality Gates

    Expert modules in MoE models typically handle different tokens according to the routing distribution. Pruning should not simply remove experts by parameter count. Instead, it should consider routing hit rates, task sensitivity, expert redundancy, and load balance together. In practice, start by measuring how often each expert is activated on the target traffic. Mark candidates that have low hit rates, high redundancy, and low replacement cost. Then remove them gradually in small proportions, and watch for obvious shifts in routing.

    The quality gate should cover three types of metrics. The first type covers general capabilities, such as the score retention rate on a high-level scientific reasoning benchmark. The second type covers business task metrics, such as question-answering accuracy, structured output success rate, and tool-calling correctness. The third type covers stability metrics, such as needle-retrieval loss, repetition rate, refusal rate, and routing load balance under long contexts. In public implementations, after about 37% of expert modules were removed, the model still kept more than 99% of its original score on a scientific reasoning benchmark. These results apply only to the specific model and evaluation set used. Organizations still need to retest with their own task suites.

    A workable configuration example is shown below:

    1. inference_plan:
    2. model_family: sparse_expert
    3. expert_pruning_ratio: 0.30
    4. quality_gate:
    5. reasoning_benchmark_delta_max: 0.01
    6. task_suite_pass_rate_min: 0.98
    7. long_context_recall_min: 0.95
    8. runtime:
    9. draft_model: enabled
    10. speculative_tokens: 4
    11. max_context_tokens: 512000
    12. capacity:
    13. accelerator_tier: lower_spec
    14. min_card_count: 8

    After pruning, a fallback strategy is required. When routing confidence is low, when a task falls outside the distribution covered by pruning evaluation, or when quality monitoring triggers an alert, the system can fall back to the unpruned model or to a higher-tier cluster. This turns structural optimization from a one-time experiment into a capacity strategy that can be operated over time.

    4. Memory Reallocation: Draft Models and Speculative Decoding

    Memory freed by expert pruning does not have to be used only to buy fewer cards. It can also fund inference acceleration. A common approach is to deploy a smaller draft model that generates several candidate tokens in advance. The main model then verifies these candidates in parallel within a single forward pass and accepts the tokens that match its own distribution. Because verification runs in parallel, a higher acceptance rate lets the system generate more tokens per unit of time, which lowers the cost per output token.

    The benefit of speculative decoding depends mainly on three factors: how closely the draft model’s distribution matches the main model’s, the number of candidate tokens, and the batching efficiency of main-model verification. Too many candidates increase verification and rollback overhead. Too few limit the speedup. Engineers should adjust the candidate length dynamically and track acceptance rates separately for each business scenario. For example, dialogue scenarios may have high acceptance rates, while high-precision code generation or complex reasoning may have lower rates. Each scenario may need its own threshold.

    The memory budget also needs to be reassessed. Break it down into the amount used by weights, the KV Cache, activations and temporary buffers, communication buffers, and the draft model. After pruning lowers the weight footprint, some of the remaining headroom can go to longer contexts and some to the draft model. If long-context requests make up a large share of traffic, prioritize the KV Cache. If short requests with high concurrency dominate, prioritize speculative decoding to increase throughput.

    5. Long Context and Accelerator Specification Selection

    Long-context capability depends heavily on the KV Cache budget. Expert pruning mainly reduces weight memory. It does not remove the linear growth of the KV Cache. However, the overall memory it frees can make room for longer contexts. In public implementations, removing about 30% of expert modules supported context windows on the order of 500,000 tokens. Removing about 37% supported context windows in the millions of tokens. Organizations should plan capacity based on the actual distribution of request lengths, not only on maximum-length stress tests.

    Accelerator selection should follow one principle: first meet memory and bandwidth requirements, then optimize unit price. If single-card memory and inter-card communication still meet the target concurrency after pruning, higher-tier accelerators can be replaced with lower-tier ones. If communication becomes the bottleneck, first reduce cross-node expert parallelism, or lower communication volume through batching and routing locality. A previous similar solution reduced the required number of higher-tier accelerator cards from 8 to 4. Later optimization lowered the required specification tier further. This shows that capacity optimization should be an ongoing process.

    A simplified cost estimate can use the following formula:

    1. def effective_cost(cards, unit_price, nodes, utilization):
    2. # cards: number of cards per node
    3. # unit_price: purchase or rental price per card
    4. # nodes: number of nodes
    5. # utilization: effective utilization rate; clamped to avoid division by zero
    6. return cards * unit_price * nodes / max(utilization, 0.01)

    When pruning reduces the card count, or a lower specification reduces unit price, the effective cost falls too. However, if utilization drops because of quality rollbacks or scheduling fragmentation, the cost savings can be offset. Throughput, latency, error rate, and fallback ratio must therefore be monitored together.

    6. Engineering Rollout and Risk Control

    A rollout should follow four steps: offline evaluation, small-traffic canary release, capacity recalculation, and full cutover. The offline stage covers expert sensitivity analysis and quality gate testing. In the canary stage, traffic is split by business line. Teams compare the acceptance rate, P95 latency, and cost per token between the pruned version and the baseline. In the capacity recalculation stage, card count, specification, and context limits are adjusted based on real traffic. After full cutover, keep a one-click rollback option.

    The main risks include quality degradation on long-tail tasks, fluctuation in draft-model acceptance rates, memory fragmentation under long contexts, and communication bottlenecks on lower-tier hardware. Mitigations include building per-task quality dashboards, adjusting speculative candidate length dynamically, reserving a memory safety margin, and balancing load on routing hotspots. In general-purpose cloud environments such as Baidu AI Cloud, teams can also use GPU instance categories, monitoring and alerting, and elastic scaling as a capacity fallback. The goal is not to chase the lowest single-point price. It is to run existing AI infrastructure stably and at reasonable cost while keeping quality acceptable.