Prefill-Decode (PD) Asymmetry in LLM Inference: Design and Optimization
This article explains why Prefill and Decode have different goals and resource profiles in autoregressive LLM inference, examines often-overlooked asymmetry inside Prefill, and discusses when PD separation helps and what it costs. It also outlines model- and system-level optimization priorities for low-cost inference and suggests metrics and load-analysis practices for evaluating PD designs.
Prefill-Decode (PD) Asymmetry in LLM Inference: Design and Optimization
When discussing lightweight LLMs, low-cost inference, and new architectures, the asymmetry between Prefill and Decode is often mentioned. Many discussions treat “PD asymmetry” as a special design introduced by a new architecture. However, from the basic flow of autoregressive inference, conventional Transformer-based LLMs also exhibit Prefill/Decode asymmetry. The real question is not whether asymmetry exists, but how a system identifies, exploits, and optimizes it.
1. Prefill and Decode Have Different Goals
Autoregressive generation can be divided into two stages. In the Prefill stage, the full prompt is processed at once, with two main goals: first, compute and write the KV Cache for all prompt tokens; second, use the final hidden state of the last token through the LM Head to predict the first generated token. In the Decode stage, starting from the first generated token, the model reads historical cache token by token, computes the K/V for the current token, appends the cache, and samples the next token through the LM Head.
The resource profiles of these two stages differ significantly. Prefill can process many tokens in parallel, involves large matrix computations, and is usually more compute-intensive. Decode processes only a small number of new tokens at a time but repeatedly reads a growing KV Cache, making it more memory-bandwidth- and latency-sensitive. Therefore, placing Prefill and Decode in the same resource pool and scaling them with the same policy often leads to problems such as prefill queuing affecting first-token latency, insufficient utilization of decode instances, or excessive cache movement overhead.
| Dimension | Prefill | Decode |
|---|---|---|
| Input scale | Entire prompt processed in parallel | Token-by-token incremental |
| Main computation | Large parallel matrix computation | Small-batch per-token computation |
| Cache behavior | Batch construction of KV Cache | Frequent KV Cache reads and appends |
| Key metrics | First-token latency, prefill throughput | Per-token latency, decode throughput |
| Resource tendency | Compute capacity, parallelism | Memory bandwidth, cache capacity |
2. Prefill Also Has Overlooked Internal Asymmetry
A common misconception is that in the Prefill stage, all tokens must traverse the entire network. More precisely, Prefill must build K/V for all prompt tokens at every layer, but not all computation paths are equally necessary. In intermediate layers, MLP outputs participate in constructing the inputs for subsequent layers, so they cannot simply be skipped; otherwise, the K/V for later layers cannot be generated correctly.
The trimmable parts mainly appear in the last layer and its tail paths: for non-last tokens that no longer enter subsequent layers, their final hidden states do not need to continue into the next layer. The LM Head is only meaningful for the last token, because only the last token’s logits are used to predict the first generated token. That is, “only the last token needs the LM Head” holds, but directly generalizing “MLP is unrelated to cache” to all layers and all tokens is not accurate; it must be limited by layer position and subsequent dependencies.
The following pseudocode illustrates the difference between Prefill and Decode:
def prefill(prompt_tokens, model):hidden = embed(prompt_tokens)kv_cache = {}# Intermediate layers need a full forward pass so later layers get correct K/Vfor layer in model.layers:k, v = layer.attn.project_kv(hidden)kv_cache[layer.id] = (k, v)hidden = layer.mlp(layer.attn(hidden, k, v))# Only the last token enters the LM Head to produce the first generated tokenfirst_logits = model.lm_head(hidden[-1])first_token = sample(first_logits)return first_token, kv_cachedef decode(last_token, kv_cache, model):output = []while not stop_condition():hidden = embed([last_token])for layer in model.layers:k, v = layer.attn.project_kv(hidden)kv_cache[layer.id] = append(kv_cache[layer.id], k, v)hidden = layer.mlp(layer.attn(hidden, kv_cache[layer.id]))logits = model.lm_head(hidden)last_token = sample(logits)output.append(last_token)return output
This sketch does not expand last-layer trimming. In production implementations, paths in the final layer that no longer affect subsequent cache or output can be fused, skipped, or optimized with specialized kernels, but equivalence must be strictly proven by a compiler, graph optimization, or hand-written operators. Theoretical gains must not break cache consistency.
3. Why PD Separation Works
The core idea of PD separation is to split Prefill and Decode into different execution units or resource pools, allowing them to scale and schedule independently. Prefill instances can be configured with stronger parallel compute resources, while Decode instances focus more on memory capacity, cache bandwidth, and stable low latency. For online services with明显的? No. For online services with significant request fluctuations, this separation can reduce interference and improve overall throughput and tail latency.
However, PD separation is not a free lunch. The KV Cache produced by Prefill must be transferred to the Decode side, and cache transfer introduces bandwidth, latency, and consistency challenges. Cache pool management, fault recovery, request migration, and batching strategies also become more complex. If requests are short, concurrency is low, or cache reuse is very low, the benefits of separation may be offset by transfer overhead. Therefore, whether to adopt PD separation should be based on the actual load profile, not just the architecture diagram.
4. Optimization Priorities for Lightweight Models
In low-cost inference scenarios, model-side and system-side optimizations need to work together. On the model side, common techniques such as more compact parameter scales, sparse activation, low-precision quantization, and grouped-query attention can reduce computation and cache overhead. On the system side, chunked prefill, prefix caching, continuous batching, and cache compression and eviction policies can improve resource utilization. For extended scenarios such as multimodal models, it is also necessary to evaluate how additional encoding and alignment modules affect the Prefill and Decode resource profiles, so that optimization does not focus only on the text path while ignoring overall latency.
Evaluation should cover first-token latency, per-token latency, throughput, cache hit rate, memory footprint, instance utilization, and cost per token. It is advisable to first analyze the length distribution, concurrency distribution, and cache reuse rate of real requests, and then decide the Prefill/Decode resource ratio and batching strategy. Only by treating PD asymmetry as a basic fact rather than a marketing label can teams build a verifiable, iterative framework for inference performance optimization.
