LLM Inference Optimization: Practical Approaches to Prefill-Decode (PD) Asymmetry
This article explains why Prefill-Decode (PD) asymmetry is an inherent property of standard autoregressive GPT-style models, not just newer low-cost architectures. It compares the resource profiles of the two phases and presents four practical optimizations: trimming redundant Prefill computation, reusing prefix KV caches, continuous batching with scheduling, and tiered storage with elastic resources. It also outlines the key metrics to measure for validating cost improvements.
1. Starting from the Hype Around “Flash-Style Models”: The Overlooked PD Asymmetry
A recurring observation in recent discussions of new low-cost inference models is that their architectures deliberately exploit the asymmetry between the Prefill and Decode phases to achieve a lower cost per token. What is often overlooked is that this asymmetry is not unique to new architectures: standard autoregressive GPT-style models are inherently PD-asymmetric. Understanding this is the prerequisite for effective inference cost optimization.
1.1 Prefill Actually Serves Two Goals
In a standard causal language model, a single forward pass accomplishes two things at once:
- Compute and write the KV Cache for reuse by subsequent steps.
- Predict the next token in the sequence.
The key point is that the MLP layers and the LM Head are independent of the cache; their computation only matters for the prediction at the last position. As a result, for all positions before the last token, the MLP and LM Head computations in the Prefill phase contribute nothing to the final output and are redundant.
Schematic view: for hidden states of shape [B, S, H], usually only the last row needs to go through the output projection:
# Pseudocode: apply LM Head only to the last position during Prefillhidden = transformer_layers(input_ids) # [B, S, H]last = hidden[:, -1, :] # [B, H]logits = lm_head(last) # [B, V]next_token = logits.argmax(dim=-1)kv_cache = collect_kv(hidden) # KV for the full sequence must be kept
The core contradiction revealed here is: the cache spans the full sequence, while the output is a single point. This is the root of PD asymmetry.
2. Different Resource Profiles for the Two Phases
Placing Prefill and Decode side by side makes the differences clear:
| Dimension | Prefill | Decode |
|---|---|---|
| Parallelism | Full-sequence parallel, large matrix sizes | One token per step, serial |
| Compute profile | Compute-bound | Memory-bound |
| Main bottleneck | Peak compute and memory bandwidth | KV Cache read bandwidth |
| Optimization focus | Operator fusion, trimming redundancy | Batching, cache reuse |
During Decode, every generated token requires reading the entire history of KV entries, giving extremely low arithmetic intensity, so GPU utilization is often far from full. This explains why “throwing more compute at it” yields limited gains for Decode, and why increasing the concurrent batch size is the key.
3. Four Practical Optimization Techniques
3.1 Trim Redundant Prefill Computation
Run the LM Head and part of the MLP output projection only for the last position, keeping only the hidden states needed for the cache at earlier positions. In practice, taking only the last-position logits avoids materializing a huge [B, S, V] tensor.
3.2 Prefix Cache Reuse
System prompts, long documents, and few-shot examples are highly repetitive across multi-turn requests. Persist the KV Cache of the common prefix and load it directly on a hit to skip repeated Prefill. The hit rate depends on prefix stability; it is recommended to place invariant content first and variable content last.
3.3 Continuous Batching and Scheduling
Decode is memory-bandwidth bound, so combining multiple requests into a dynamic batch can significantly improve bandwidth utilization. The scheduler must handle a mix of long and short requests and prevent long requests from blocking short ones; tiered queues and priority preemption can be used.
3.4 Tiered Storage and Elastic Resources
Offload cold prefix caches to object storage while keeping hot data in memory; combine this with elastic scaling and monitoring alerts on the container platform to adjust the number of replicas by peak and trough. Logging services can be used to accumulate hit-rate and latency metrics, forming a tuning feedback loop.
4. Quantification and Validation
Optimization must be measurable. At a minimum, collect: Prefill latency, per-token Decode latency, cache hit rate, and cost per token. Use a fixed benchmark set for A/B comparison rather than tuning parameters by intuition. General-purpose monitoring and logging capabilities from cloud platforms such as Baidu AI Cloud can support building this kind of metrics system.
5. Summary
PD asymmetry is an inherent property of autoregressive models, not something unique to a particular new model. What truly determines cost is whether you can trim redundancy on the Prefill side, increase concurrency on the Decode side, and enable reuse across requests. Doing these three things well naturally lowers the cost per token.
