Understanding PD Asymmetry in Large Model Inference: Prefill vs. Decode

    This article explains why Prefill and Decode are inherently asymmetric in autoregressive LLM inference, and how that asymmetry shapes system design. It covers the compute-bound versus memory-bound nature of the two phases, a reusable framework for estimating their cost, the overlooked last-token special case in Prefill, and the benefits of disaggregating the two stages. It also clears up common misconceptions and offers practical guidance on capacity planning and observability.

    1. Where the Problem Starts: Why Two-Phase Inference Is Naturally Asymmetric

    In large model inference serving, request processing is typically split into two phases: Prefill and Decode. Many discussions treat “asymmetry” as a patent of some new architecture, which is a misunderstanding. Even for the most conventional generative models, the computational characteristics of these two phases are completely different. Asymmetry is an inherent property of the autoregressive generation paradigm, not an add-on design of any particular model generation.

    The root cause is that the two phases have different objective functions:

    1. Prefill processes all input tokens at once, generating and writing the cache for every layer, and produces the first output token along the way;
    2. Decode processes only one new token at a time, yet must read the entire history cache and repeatedly execute the full parameter matrix.

    The direct consequence is that Prefill is compute-bound while Decode is memory-bound. Scheduling both under the same batch and the same resource configuration inevitably leads to resource waste.

    2. Looking at the Difference Through Computation Volume: A Reusable Estimation Framework

    Let the input length be S, the output length be T, the model hidden dimension be d, and the number of layers be L. A rough but sufficient view for guiding capacity planning looks like this:

    • The scale of Prefill’s matrix multiplication is proportional to S, and the S tokens can be assembled into one large matrix and computed in a single pass, giving high arithmetic intensity;
    • Decode processes only 1 token per step, so the matrix multiplication degenerates into “matrix × vector,” with extremely low arithmetic intensity, and performance is almost entirely determined by memory bandwidth.

    Illustrative pseudocode can express this difference:

    1. # Prefill: compute all input positions at once
    2. logits, cache = model.forward(input_ids[:, :S]) # large matrix multiply, compute saturated
    3. # Decode: advance token by token, repeatedly reading weights and cache
    4. for step in range(T):
    5. logits, cache = model.forward(last_token, cache) # matrix × vector, bandwidth-bound

    A common engineering rule of thumb is that each token generated in the Decode phase requires moving all model weights and the history cache from memory once. When the batch size is insufficient, bandwidth is saturated by weight reads; when the batch size is large enough, weight reads are amortized, and Decode gradually shifts from bandwidth-bound to compute-bound. This curve is exactly why batching is so critical in inference optimization.

    3. An Overlooked Detail: The “Last Segment” Special Case Inside Prefill

    The output of conventional models in the Prefill phase is not entirely homogeneous. Apart from the last position, which genuinely participates in “predicting the first token,” the remaining positions are only responsible for writing the cache; the associated output projection layer and language model head (LM Head) contribute nothing to cache generation. This means:

    • If the implementation runs the full output head computation for all positions, it produces a considerable amount of wasted compute;
    • A more rigorous implementation calls the output head only for the last position, while the remaining positions only complete the backbone network and cache writes.

    This kind of detail yields especially clear benefits in scenarios with long inputs and short outputs (such as long-document summarization and retrieval-augmented question answering), because the input length may be tens of times the output length.

    4. Two-Phase Disaggregation: Turning Asymmetry Into an Architectural Advantage

    Since the two phases have different resource profiles, the most natural approach is to deploy them separately and scale them independently:

    • Prefill cluster: pursues high compute and low queuing latency, focusing on time to first token (TTFT);
    • Decode cluster: pursues high bandwidth and large cache capacity, focusing on time per output token (TPOT) and overall throughput.

    Between the two phases, intermediate state (Key/Value Cache) is passed via message queues or high-speed cache services, and three things need focused design:

    1. Serialization and transfer overhead of the cache, avoiding “compute fast, transfer slow”;
    2. Cache lifecycle management, with reclamation strategies for request cancellation, timeouts, and extremely long contexts;
    3. Routing strategy, bucketing requests by input length to avoid long and short requests blocking each other.

    The simplified scheduling logic can be written as:

    1. def route(request):
    2. if request.input_len > LONG_THRESHOLD:
    3. return prefill_pool_heavy # prioritize compute for long inputs
    4. return prefill_pool_light
    5. def on_prefill_done(req, cache):
    6. kv_store.put(req.id, cache, ttl=req.max_output_len)
    7. decode_queue.push(req.id) # hand off to the decode resource pool

    5. Common Misconceptions and Clarifications

    • Misconception 1: Asymmetry is unique to new architectures. In fact, it stems from the computational paradigm of autoregressive generation, and exists in any conventional generative model.
    • Misconception 2: Switching to faster cards alone will solve it. The bottleneck of Decode lies in bandwidth and cache capacity, so simply piling on compute yields limited returns.
    • Misconception 3: The bigger the batch, the better. Too large a batch raises single-request latency, so a clear SLO tradeoff between throughput and latency is needed.
    • Misconception 4: The cache can be retained indefinitely. Cache usage grows linearly with context length and must be incorporated into the capacity model and eviction strategy.

    6. Implementation Advice: Capacity Planning and Observability

    It is recommended that teams build a capacity table before going live, containing at least: average input length, average output length, number of concurrent requests, bytes per token of cache (estimable from layers × hidden dimension × precision), and target TTFT and TPOT. After going live, focus on monitoring four categories of metrics: queuing latency, cache hit rate, memory usage watermark, and batch size distribution.

    For cloud implementation, you can combine container platforms to host elastic inference replicas, object storage to hold long-lived session state, message queues to decouple the two phases, and logging services plus monitoring and alerting systems for full-link observability. These are all general capability categories, and specific choices should be evaluated against your own SLO and cost model.

    7. Summary

    The asymmetry between Prefill and Decode is not a defect but a structural fact that can be exploited through engineering. Understanding the essential difference between “compute-bound vs. memory-bound,” and then making the right tradeoffs in cache management, batching, two-phase disaggregation, and capacity planning, is the main line of inference cost optimization.