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

    This article explains how expert pruning and speculative decoding can reduce the memory footprint and serving cost of very large mixture-of-experts models. It covers expert selection, draft-model acceptance rates, GPU memory estimation, KV-cache capacity planning, rollout steps, and the risks that must be validated before production deployment.

    1. Where Very Large Model Inference Costs Come From

    The cost of serving large language models is mainly driven by three factors: GPU memory usage, computational throughput, and service latency. As the parameter count grows, more memory is required to load the weights, more accelerators are needed for each inference instance, and the compute cost per token increases.

    Some publicly available mixture-of-experts (MoE) models now contain trillions of total parameters, while activating only a small subset of them for each inference request. Compute requirements are therefore not directly proportional to the total parameter count. Memory usage, however, is directly tied to the full set of parameters. In practice, the central challenge in reducing inference cost is often not insufficient compute, but the expense and difficulty of fitting all model weights into memory.

    Publicly reported optimization efforts for very large models have reduced hardware procurement costs by roughly 20% while lowering cloud rental costs by slightly more than 20%, without materially affecting core inference capabilities. This article does not examine any specific product. Instead, it breaks down the general techniques involved and explains how to evaluate and reproduce these ideas in an internal environment.

    2. Expert Pruning: A Primary Method for Reducing Memory Usage

    An MoE model consists of a router and a large number of expert subnetworks. For each token, the router selects only a small number of experts to perform the computation. If certain experts are rarely activated in the target workload, or make only a limited contribution to the output, they may be removed to reduce the size of the model weights.

    Expert pruning typically involves four steps:

    1. Collect statistics: Run the model on a representative dataset and record each expert’s activation frequency and output contribution.
    2. Rank and select: Rank experts by contribution, define the set to retain, and reserve an appropriate safety margin.
    3. Adjust routing: After removing experts, update the router’s output mapping so that tokens are assigned correctly to the remaining experts. This prevents routing requests to deleted modules.
    4. Run regression tests: Compare the pruned and original models on general benchmarks and business-specific samples, with particular attention to long-tail scenarios and low-frequency tasks.

    The higher the pruning ratio, the greater the risk of quality degradation. In one publicly reported case, removing approximately 30% of the modules still produced nearly the same score as the original model on a difficult scientific reasoning benchmark. However, this result depends heavily on the task distribution and should not be generalized to every workload.

    In production engineering, pruning should be performed incrementally. Each step should be followed by regression testing rather than deleting a large portion of the model in a single operation.

    3. Turning Recovered Memory into Higher Throughput: Speculative Decoding

    Once memory has been freed, the same set of accelerators may be able to host an additional small draft model. The two models can then work together through a technique known as speculative decoding:

    • The draft model quickly proposes several subsequent tokens.
    • The target model verifies those candidates in a single forward pass.
    • The longest prefix that matches the target model is accepted. The first mismatch and all later draft tokens are discarded, and the target model supplies the correct token at that position.

    The benefit comes from verifying multiple candidate tokens in one target-model pass. Assume that the draft model proposes k tokens per round, and that the probability of accepting an individual token is α, with the positions treated as independent and identically distributed. The expected number of valid tokens produced by each target-model forward pass is:

    E = (1 − α^(k+1)) / (1 − α)

    For example, with α = 0.8 and k = 4, E ≈ 3.36. Each round therefore produces an average of approximately 3.4 tokens. The actual speedup must also account for the draft model’s compute cost and communication latency, so the final result should be determined through measurement.

    The closer the vocabularies and output distributions of the draft and target models, the higher the acceptance rate is likely to be. If their styles and distributions differ substantially, the acceptance rate may fall, and speculative decoding can increase latency instead of reducing it.

    4. Hardware Planning: From Adding More GPUs to Right-Sizing the Deployment

    Deployment capacity is generally determined by two components: model weight memory and context-cache memory.

    4.1 Estimating Weight Memory

    A rough estimate for the number of accelerators required is:

    Weight memory ≈ Parameter count × Bytes per parameter

    With a low-precision format that uses one byte per parameter, a 2.8-trillion-parameter model requires approximately 2.8 TB of memory. If 37% of the modules are pruned and expert weights account for most of the parameters, the weight footprint may fall to approximately 1.8 TB.

    This means that the same service target may require fewer accelerators, or that higher-end hardware could be replaced with a lower-memory tier.

    4.2 Estimating Context-Cache Memory

    For long-context inference, a major source of memory consumption is the key-value cache, or KV cache. Its approximate size can be estimated as:

    KV cache ≈ 2 × Number of layers × Number of KV heads × Head dimension × Context length × Bytes per element × Number of concurrent requests

    This formula shows that memory requirements increase linearly with context length and concurrency. After pruning the model, teams should first define the target context limit and then work backward to determine the required memory capacity.

    For example, the concurrency supported at a shorter context length may be several times higher than that supported at a longer context length.

    5. A Practical Engineering Rollout

    1. Define the optimization target: Set the priority among latency, throughput, and cost. If the application is sensitive to time to first token, the benefits of speculative decoding should be evaluated separately.
    2. Build an evaluation set: Cover general capabilities, core business tasks, and long-tail scenarios. Use this set as the regression baseline after every pruning step.
    3. Prune incrementally: Start with the experts that contribute the least. Run regression tests after each step and record the changes in quality and efficiency.
    4. Select a draft model: Prefer a small model from the same model family or one with a similar output distribution. Measure its acceptance rate on target data.
    5. Plan capacity: Use the weight and cache formulas to estimate accelerator count and maximum context length. Reserve approximately 20% of GPU memory for peak demand.
    6. Roll out gradually: Run the old and new configurations in parallel. Compare cost per token, response quality, and tail latency. Switch fully only after confirming that there is no unacceptable regression.

    The following pseudocode illustrates the control flow of speculative decoding. It is not an interface for any specific framework:

    1. def speculative_generate(target, draft, prompt, k=4, max_new=256):
    2. tokens = list(prompt)
    3. limit = len(prompt) + max_new
    4. while len(tokens) < limit:
    5. # The draft model proposes k candidate tokens
    6. candidates = draft.propose(tokens, k)
    7. # The target model performs one forward pass to predict each position
    8. predictions, next_token = target.verify(tokens, candidates)
    9. # Select the longest prefix that matches the target model
    10. accepted = longest_matching_prefix(candidates, predictions)
    11. tokens.extend(accepted)
    12. # At the first mismatch, append the correct token from the target model
    13. tokens.append(next_token)
    14. return tokens

    6. Risks and Boundaries

    • Capability degradation: Pruning may weaken performance on low-frequency tasks or specific languages and domains. These scenarios must be tested separately.
    • Speculative decoding becoming ineffective: If the draft-model acceptance rate is too low, the additional proposal and verification overhead may cancel out the benefit. A fallback switch should be provided.
    • Time-sensitive cost estimates: Hardware prices and rental fees fluctuate. The figures in this article are intended only to illustrate the scale of the calculation; actual planning should use current quotations.
    • Hidden costs of long contexts: The maximum context length is constrained by both the model architecture and available memory. A smaller model does not provide unlimited context capacity.

    7. Conclusion

    Inference costs for very large models are often constrained primarily by memory capacity. Expert pruning reduces the weight footprint and lowers the hardware barrier. The recovered memory can then be used to deploy a draft model, while speculative decoding improves the number of tokens produced per target-model forward pass.

    The key to combining these techniques is to prune incrementally against a representative evaluation set, estimate capacity with explicit formulas, and verify real-world speedups through measurement. With this process, teams can determine which models and workloads are suitable for right-sized deployments and find an acceptable balance between quality and cost.