LLM Inference Cost Optimization: PD Disaggregation and Heterogeneous Mixed Inference in Practice

    This article explains how to cut large language model inference costs by combining prefill-decode (PD) disaggregation with heterogeneous mixed inference. It breaks down why prefill is compute-bound and decode is bandwidth- and capacity-bound, why co-locating both workloads hurts performance, and how to assign prefill to domestic accelerator cards while reserving high-end GPUs for decode. It also covers the five engineering areas you need to get right—request routing, cross-pool KV cache transfer, cache capacity and eviction, batching and scheduling, and elastic scaling with observability—plus common pitfalls and practical rollout advice.

    1. The Problem: Tight Compute Supply Meets Surging Inference Demand

    As large language model applications move into large-scale production, the competitive focus has shifted from “how capable is the model” to “how much does each task cost.” Whoever can serve more users reliably at a lower cost per call holds the commercial advantage.

    At the same time, a structural mismatch on the supply side is becoming more pronounced. High-bandwidth, high-compute accelerator cards remain in short supply, and many teams are working with a limited pool of existing hardware. On the demand side, inference traffic keeps multiplying, input lengths keep growing, and concurrent user counts keep climbing.

    On one side is a hardware budget fixed by what you already own; on the other is load growth with almost no ceiling. The answer is not to keep buying more cards, but to put the hardware you already have to the right use.

    Domestic accelerator chips have moved past the “from nothing to something” stage and are now in the “from something to better” phase. Building the chip is only the first step. The real dividing line is whether the software stack, operator libraries, communication libraries, and scheduling frameworks can fully exploit the hardware’s characteristics and deliver strong cost-performance.

    2. Reframing the Problem: One Inference Is Really Two Opposite Kinds of Work

    To see where the optimization room is, you first need to understand what inference actually looks like at the hardware level. From the user’s perspective it is “one question, one answer.” From the chip’s perspective it is “read everything up front, then write one token at a time.”

    2.1 Prefill: Compute-Intensive

    The model must read all input tokens at once and build the key-value cache (KV Cache) that will be reused throughout generation. This step is highly parallel: thousands of tokens take part in large matrix multiplications simultaneously, and the bottleneck is multiply-add throughput and the momentary pressure on memory bandwidth. Time to first token (TTFT) is determined almost entirely by this phase. The longer the input, the longer the wait.

    2.2 Decode: Bandwidth- and Capacity-Intensive

    Once decoding begins, the model produces only one token per step. The compute per step is tiny, but every step requires re-reading the model weights and the growing key-value cache from memory. Compute units sit largely idle, and the bottleneck shifts to memory bandwidth and memory capacity. Whether output is smooth or stutters depends on this phase.

    2.3 Why Co-Location Creates Interference

    The two workloads demand almost opposite things from the hardware, so putting them on the same cards makes them interfere with each other. When a very long request starts prefill, other users’ decoding on the same card is forced to queue, causing second-long pauses in output. Meanwhile, the low compute usage during decode leaves expensive compute units spinning idle for long stretches.

    The common industry approach is PD disaggregation: split the two phases into two separate resource pools. But if both pools still use the same model of high-end card, the prefill pool is paying for bandwidth it does not need, and the decode pool is paying for compute it leaves idle. The cost waste remains.

    3. The Core Idea: Let Domestic Compute Handle Prefill, Reserve High-End Cards for Decode

    The key insight behind heterogeneous mixed inference is this: prefill is compute-heavy and only moderately dependent on memory bandwidth, while decode is bandwidth- and capacity-heavy and does not need high peak compute. The two workloads have different resource profiles, which makes them a natural fit for different classes of hardware.

    The division of labor then becomes clear. A prefill pool built from domestic accelerator cards handles the highly parallel, matrix-multiplication-heavy compute. A decode pool built from existing high-end cards focuses on long-sequence, high-concurrency token-by-token generation. With the same budget, overall throughput can reach several times that of a homogeneous setup, without buying a single additional high-end card.

    The source of this gain is no mystery. It comes from the overall rise in utilization after aligning resource profiles, not from any “doubling” of a single hardware spec.

    4. Engineering Implementation: Five Areas You Must Get Right

    4.1 Request Routing and Load Decisions

    The gateway needs to decide which pool a request enters based on input length, estimated output length, session state, and current queue depth. In practice, a two-factor strategy of “length threshold plus queue watermark” works well:

    1. def route(req, prefill_pool, decode_pool):
    2. # Long inputs go to the compute pool first; short requests can be co-located
    3. if req.input_tokens >= LONG_INPUT_THRESHOLD:
    4. return prefill_pool.submit(req)
    5. if prefill_pool.queue_depth() > HIGH_WATER_MARK:
    6. return decode_pool.submit(req) # Overflow protection to avoid a queue avalanche
    7. return decode_pool.submit(req)

    4.2 Cross-Pool KV Cache Transfer

    The key-value cache produced by prefill must reach the decode pool efficiently. This is the performance crux of the whole design. The key points are: use high-speed interconnect and a zero-copy transfer path; overlap transfer with compute so decode does not sit waiting; chunk the cache into a pipelined flow that sends while computing; and set timeouts with a recompute fallback so a few requests cannot drag down the whole system.

    4.3 Cache Capacity and Eviction

    The memory capacity of the decode pool directly sets the concurrency ceiling. You need to budget capacity according to the sequence-length distribution, combined with paged cache management, prefix reuse, and a sensible eviction policy, to raise the cache hit rate for repeated system prompts.

    4.4 Batching and Scheduling

    The prefill side aims for large batches to saturate compute, while the decode side aims for low-latency continuous batching. Because the two sides use different batch strategies, they need separate schedulers tuned independently, along with request-priority isolation between pools to keep long requests from starving short ones.

    4.5 Elastic Scaling and Observability

    Scaling each pool independently is cheaper than scaling a homogeneous system as a whole. The observability setup should at minimum cover TTFT, the interval between output tokens, cache hit rate, cross-pool transfer time, per-pool utilization, and queue time, with monitoring, alerting, and logging in place to close the loop.

    5. Practical Tips and Common Pitfalls

    • Pitfall 1: Assuming heterogeneity must bring compatibility problems. As long as you unify the operator abstraction and communication layer, the upper framework can stay unaffected.
    • Pitfall 2: Looking only at peak throughput while ignoring tail latency. Long-input scenarios need their own thresholds and fallback paths.
    • Pitfall 3: Treating cache transfer as a minor detail. It often accounts for a meaningful share of total latency and must be optimized specifically.
    • Recommendation: Start with a small canary to validate the ratio, then ramp up gradually. Treat the resource ratio as a tunable parameter to iterate on continuously, not a one-time setting.

    6. Conclusion

    A limited stock of high-end cards is a reality that cannot be avoided in the short term, but inference cost does not have to be dictated by hardware supply alone. Splitting prefill from decode and assigning heterogeneous compute by resource profile is a practical path to maximizing the value of existing hardware. For engineering teams, the real competitive edge lies in three “soft skills”—scheduling, caching, and observability—which determine how much effective throughput the same hardware can deliver.