Cost Reduction for Large Model Inference: How to Use Pruning and Speculative Decoding

    This article explores two practical techniques to reduce the inference cost of large language models: expert pruning in mixture-of-experts architectures and speculative decoding with draft models. It covers step-by-step implementation, hardware and workload considerations, memory estimation, cost calculation frameworks, and common pitfalls—helping engineering teams adopt these methods based on real-world validation rather than generic benchmarks.

    As large language models grow in parameter count, both GPU memory usage and compute overhead during inference rise significantly. While pursuing better inference performance, organizations also face the increasing costs of GPU procurement and cloud rental. Model pruning and speculative decoding are two common approaches to reduce cost, but their effectiveness depends on model architecture, hardware conditions, and request patterns. There is no universal number that can be applied directly.

    1. How to Prune a Mixture-of-Experts Model

    Among the huge models currently available for public download, the mixture-of-experts (MoE) architecture is widely used. These models have a large total parameter count, but only a subset of experts is activated for each inference step. At deployment, all expert weights typically need to be loaded into GPU memory or host memory, depending on the offloading strategy and parallelization method. As a result, inactive experts still occupy resources—this is the entry point for pruning.

    The basic idea of pruning is to evaluate the contribution of each expert module to real business tasks, then remove experts that serve low-frequency or edge-case functions. A recommended step-by-step approach:

    1. Build a representative evaluation set that covers the actual request distribution in production, rather than relying only on generic benchmarks.
    2. Measure the activation frequency of each expert and analyze its contribution to output quality.
    3. Gradually remove candidate experts in order of increasing contribution, logging core task metrics at each step.
    4. Set a threshold for acceptable performance degradation in advance. Stop pruning when metrics fall below that threshold.

    Some practice reports indicate that benchmark scores remain mostly stable even after a large fraction of experts are removed. However, this outcome depends on the specific model, evaluation set, and experimental settings, and cannot be directly generalized to other models. Before adopting pruning, teams should re-validate the approach on their own data.

    2. What Does Freed GPU Memory Enable?

    The most direct benefit of pruning is reduced GPU memory usage. The freed space can be used to increase batch sizes, accommodate longer KV caches, or deploy additional model replicas.

    Freed memory does not automatically extend long-context capability. Handling long contexts still depends on several conditions:

    • The extrapolation ability of positional encodings, which determines whether a model can stably process inputs beyond its training length.
    • The implementation of attention, such as chunked computation kernels that reduce memory usage.
    • The context length used during training; models not trained on long texts often behave unstably.
    • The KV cache management strategy, including paged storage and eviction mechanisms.

    To estimate KV cache size, use the following approximate formula:

    KV cache bytes ≈ 2 × (number of layers) × (number of KV heads) × (head dimension) × (sequence length) × (batch size) × (bytes per element)

    The factor of 2 accounts for storing both Key and Value. After plugging in actual parameters, you can determine how long a context the freed memory can support.

    Important: after pruning, three types of validation are necessary. First, regression tests for core capabilities to confirm no obvious degradation on regular tasks. Second, long-context specific evaluations such as long-document retrieval and cross-paragraph question answering. Third, staged rollout with real traffic to compare key metrics. Do not rely solely on a single science reasoning benchmark.

    3. Selecting a Draft Model for Speculative Decoding

    Traditional autoregressive generation outputs one token per step, leading to low GPU utilization. Speculative decoding works as follows: a small draft model quickly proposes multiple candidate tokens, and the main model verifies these candidates in parallel. Tokens that pass verification are accepted at once; if a token is rejected, the main model resumes generation from that position.

    When choosing a draft model, focus on three aspects:

    • Distributional consistency with the main model. The acceptance rate directly determines the speedup. A low acceptance rate makes drafting a net overhead.
    • The draft model’s own inference cost. It must be lightweight enough, otherwise the time saved will be offset.
    • Memory footprint. The draft model must reside in memory alongside the main model, so it competes for remaining GPU memory.

    Additionally, the draft model and the main model should use the same tokenizer; otherwise, token-level alignment for verification is impossible.

    Evaluation is straightforward: record acceptance rate, average number of accepted tokens per step, end-to-end latency, and throughput, and compare each metric against a baseline without speculative decoding. Benefits also depend on task type. Code completion, templated text, and other highly predictable content usually have higher acceptance rates; open-ended creative writing typically has lower acceptance rates.

    Common mistakes include three types: looking only at single-request latency while ignoring throughput changes under high concurrency; using a tokenizer mismatch between draft and main models; and testing only on public datasets without using the real request distribution.

    4. How to Estimate Cost Savings

    The degree of cost reduction is determined by multiple factors, including original hardware specifications, model size, peak and valley QPS, average generation length, and cloud billing model (pay-as-you-go, reserved instances, or spot instances). Therefore, percentages from articles or case studies are only rough references and cannot be treated as your own expected results.

    When estimating, list key assumptions in a table, then calculate for both the before and after scenarios.

    Metric Description
    Unit cost Hardware or rental cost per unit time divided by number of tokens generated per unit time
    Peak and average QPS Peak determines capacity planning; average determines cost estimation
    Number of instances Fixed cost when provisioned for peak, or average cost when auto-scaling based on load
    Optimized throughput Must come from actual measurement, not theoretical values

    For workloads with significant load fluctuation, dynamically adjusting instance count based on QPS changes is usually more cost-effective than holding resources at peak capacity year-round.

    5. From Model-Level to Full-Stack Optimization

    Model pruning and quantization address the model’s size. To continuously reduce inference cost, you also need to optimize the execution and serving layers—for example, adjusting batching strategies, improving KV cache memory management and recomputation, and adding request routing and load balancing at the service level.

    This path suits teams that already have stable services and complete monitoring infrastructure. Smaller teams can start with model selection and deployment configuration, then accumulate data before deeper optimization.

    Common Questions

    How do I prune a model? Build a representative evaluation set first, then measure expert activation frequency and contribution, remove low-contribution modules in order, and check whether core metrics fall below a threshold at each step.

    How do I select a draft model for speculative decoding? Prioritize small models that are close to the main model’s distribution, share the same tokenizer, and have low inference overhead. Use acceptance rate and end-to-end throughput as the final judgment criteria.

    What determines the amount of cost reduction? It depends on original hardware specifications, model size, load fluctuation, generation length, and billing type. Establish a baseline first, then compute benefits from measured data.

    What are common mistakes? Common mistakes include: using only generic benchmarks to evaluate pruning without long-context specific tests; focusing on single-request latency and ignoring throughput; directly applying other people’s percentages as your own expectation; and starting optimization without a cost baseline.