Cost Reduction for Large Model Inference: Pruning, Speculative Decoding, and GPU Selection Practices
This article explores strategies to reduce the inference costs of large language models. It covers the impact of parameter scale on memory and computation, establishing a cost model, and optimizing through expert module pruning, speculative decoding with draft models, and memory planning for long contexts. Practical insights on GPU selection and deployment are also discussed.
1. How Parameter Scale Increases Inference Costs
LLM inference costs come mainly from memory and computation. Model weights must reside in memory. For half-precision storage, each parameter takes 2 bytes; 100 billion parameters require about 200GB of memory. More parameters mean more GPUs are needed to hold the model, leading to more frequent inter-GPU communication.
Mixture of Experts (MoE) is another typical case. Each token only activates a few experts, making single computation manageable. However, inference services usually need all expert weights in memory; otherwise, scheduling latency increases significantly. Thus, total parameters determine the deployment threshold, while activated parameters mainly affect single computation speed.
Inference costs can be broken down into three parts: hardware purchase or rental costs, the minimum number of GPUs determined by memory usage, and the unit cost determined by throughput. These three should be observed separately during optimization. Compressing only one aspect may not reduce the overall cost.
2. Establishing a Cost Model First
Before discussing specific methods, it is recommended to use a simple formula to measure optimization effects:
Cost per token = Cost per GPU per hour * Number of deployed GPUs / Tokens generated per hour
Here is a hypothetical example to illustrate the calculation. Assuming the cost per GPU per hour is A, and the number of deployed GPUs decreases from 8 to 4. If throughput remains unchanged, the unit cost is halved. In practice, throughput usually changes, so stress testing under real workloads is necessary; looking solely at GPU count is insufficient.
Reported cost reduction percentages in the industry vary greatly. The same method may yield completely different benefits across different models and request distributions. Teams should rely on measured results from their own traffic samples.
3. Method 1: Expert Module Pruning
The core of pruning is finding the modules that contribute the least to the target task and removing them or merging them with similar modules. Three common criteria are:
- Activation frequency: Count how many times each expert is selected by the router on representative data. Experts rarely selected over a long period are better candidates.
- Output contribution: Compare the difference in output distribution before and after removal, or observe changes in task metrics.
- Redundancy: Check if functionally similar experts can be merged to reduce duplicate parameters.
Post-pruning calibration is required. Router weights may need adjustment, and some scenarios require minimal fine-tuning. Validation should not rely on a single evaluation set; it should cover reasoning, code, long-text comprehension, instruction following, and real business samples. The larger the pruning scale, the more attention should be paid to performance degradation on out-of-distribution data.
Below is a schematic of the validation process:
for expert in model.experts:stats[expert] = count_routed(expert, calib_dataset)candidates = [e for e in model.experts if stats[e] < threshold]pruned = remove(model, candidates)pruned = calibrate(pruned, calib_dataset)assert eval(pruned, benchmark_suite) >= baseline * tolerance
4. Method 2: Draft Models and Speculative Decoding
Autoregressive generation outputs only one token at a time, leaving the main model’s computing power often waiting for memory read/writes. Speculative decoding uses a smaller draft model to propose several continuous candidate tokens, which are then verified by the main model in a single parallel forward pass. The accepted prefix is retained. When the first unaccepted position is encountered, the main model resamples and continues generation.
Under the standard accept-reject sampling algorithm, the output distribution is theoretically identical to using only the main model, so this method usually does not change the statistical properties of the generated results. The benefits depend on three factors:
- Acceptance rate: The closer the draft model is to the main model, the more tokens pass verification per round.
- Draft overhead: The single inference latency of the draft model must be significantly lower than the main model.
- Batch size: At larger batch sizes, computation gradually becomes the bottleneck, reducing the speedup. High-concurrency services need separate evaluation before enabling this.
The draft model itself requires extra memory. If pruning saves some memory, it can be used to deploy the draft model. Combining both methods is a common approach.
The pseudocode is as follows:
k = 4draft_tokens = draft_model.propose(prefix, k)target_probs = target_model.forward(prefix + draft_tokens)accepted = verify(draft_tokens, target_probs)if len(accepted) < k:next_token = sample_from_target(target_probs, position=len(accepted))
5. Method 3: Memory Planning for Long Contexts
The longer the context, the more KV cache is used, roughly proportional to the sequence length. The KV cache estimation formula is as follows:
KV cache bytes ≈ 2 * Number of layers * Number of KV heads * Head dimension * Sequence length * Bytes per element * Concurrent requests
Assuming 2 bytes per element, when context increases from hundreds of thousands of tokens to millions, the KV cache per request grows proportionally. The number of concurrent requests a single GPU can handle decreases. The computation during the prefill phase for ultra-long inputs also increases significantly, requiring separate monitoring of Time to First Token (TTFT). Therefore, long context capabilities must be planned alongside concurrency and GPU specs; simply verifying “if a request can run” is insufficient.
Common practices include:
- Quantizing the KV cache to reduce the storage bit-width per element. After quantization, verify if long-text retrieval quality degrades.
- Using paged memory management to reduce memory fragmentation and increase available capacity.
- Tiering requests by length, setting up independent queues and timeout strategies for ultra-long requests to avoid…
