LLM Inference DualPath Architecture: Solving the Prefill Bottleneck

    This article explains why large language model inference splits into two distinct workloads—prefill and decode—and how their opposite resource profiles create scheduling bottlenecks in multi-turn and agentic scenarios. It introduces the DualPath approach, covering path separation, tiered KV caching, compute-transfer overlap, and independent scaling, along with practical engineering guidance and common pitfalls.

    1. Where the Problem Starts: One Request, Two Very Different Workloads

    Once large language model inference moves into production serving, a request is typically split into two semantically different phases. Prefill sends the entire input through the model at once to produce internal representations—the key-value vectors (KV Vectors) generated layer by layer and head by head. Decode then generates subsequent tokens autoregressively in a loop, processing only one new token per step while reading the full historical context.

    The resource profiles of these two phases are almost opposites:

    • Prefill is a mix of compute-bound and bandwidth-bound work. The longer the input, the larger the matrix multiplications and the more cache data that must be written.
    • Decode is memory-access bound. Each step involves very little computation; the bottleneck is repeatedly moving weights and historical cache.

    A minimal illustration shows the difference (pseudocode only, to express scheduling semantics):

    1. # Prefill: process N input tokens at once
    2. kv = prefill(prompt_tokens) # produce and persist/reside KV
    3. cache.append(kv)
    4. # Decode: process 1 token per step, but read all history
    5. for _ in range(max_new_tokens):
    6. kv_step = read_history(cache) # memory-access dominated
    7. logits = decode_one(token, kv_step)
    8. token = sample(logits)
    9. cache.append(token_kv)

    When both are scheduled serially on the same execution path, hardware resources inevitably show a sawtooth pattern: one side is saturated while the other sits idle.

    2. How Chat and Agent Workloads Amplify the Conflict

    For single-turn question answering, the duration gap between prefill and decode can still be tolerated. But in multi-turn conversations and tool-calling scenarios, every request must reassemble the full context: prior questions and answers, system instructions, retrieved snippets, and tool return values are concatenated repeatedly. If the cache is not effectively reused, the same prefix is recomputed multiple times, and cost accumulates roughly linearly with the number of turns.

    The cost of cache reuse does not disappear; it shifts. Compute pressure becomes read pressure. When cache capacity exceeds a single GPU’s memory and must be placed on storage tiers further out, network and storage bandwidth become the new constraint. Worse, pipeline coupling emerges: while prefill is busy pulling historical cache back into GPU memory, the decode queue gets no data and can only wait; once prefill finishes, decode occupies GPU memory bandwidth for a long time, and new prefill requests queue up. This mutual waiting pushes overall utilization well below the theoretical value, showing up as “acceptable average latency but severe tail-latency jitter.”

    It is worth emphasizing that this conflict is not exclusive to any particular model or vendor. It is a common engineering challenge of the autoregressive architecture under long contexts and high call frequency. When resources are ample, it can be smoothed out by adding hardware, but cost rises linearly; when resources are constrained, effective compute must be obtained through scheduling and data layout.

    3. The Core of DualPath: Decoupling the Two Workloads

    DualPath essentially treats prefill and decode as two independently orchestrated task flows, each bound to suitable resources and execution rhythms, then synchronizes state through an explicit handoff protocol. It has four layers of design:

    1. Path separation. Set up independent execution queues and concurrency quotas for long-input prefill and incremental decode, so long requests do not drag down short-request latency, and small-step decode tasks are not blocked by large compute chunks.
    2. Tiered caching. Organize multi-level caches by access heat: hot data stays in GPU memory, warm data moves down to host memory, and cold data lands on higher-capacity media. Combined with prefix hashing for deduplication and sharing, the same system prompt and the same document snippet are computed only once.
    3. Compute and transfer overlap. Split cache movement into blocks and advance it in parallel with the current batch’s computation, using prefetch to hide latency. Transfer granularity must match the compute step size: too fine adds scheduling overhead, too coarse raises time to first token.
    4. Independent scaling. The resource ratio of the two paths can be tuned separately by workload profile. The optimal ratio for long-document summarization typically differs from that for multi-turn tool-calling workloads.

    A schematic scheduling skeleton is shown below:

    1. class DualPathScheduler:
    2. def __init__(self):
    3. self.prefill_q = deque() # long input, compute-intensive
    4. self.decode_q = deque() # incremental generation, memory-access-intensive
    5. self.cache = TieredKV() # GPU memory / host memory / external media
    6. def step(self):
    7. # Split prefill by budget first to avoid long monopolization
    8. batch = self.prefill_q.pop_up_to(token_budget)
    9. if batch:
    10. kv = prefill(batch) # compute path
    11. self.cache.put(batch.prefix_id, kv)
    12. # Decode-side async prefetch, overlapped with compute
    13. for req in self.decode_q.ready():
    14. kv = self.cache.async_prefetch(req.prefix_id)
    15. req.attach(kv) # transfer path
    16. decode_and_sample(self.decode_q)

    4. Implementation Essentials and Common Pitfalls

    • Prefix identifiers must be stable. Cache reuse depends on reliably determining that “this prefix matches a historical segment.” This is usually based on content hashing and version numbers; any change in concatenation order causes hit rates to drop sharply.
    • Batching strategy should be path-specific. Prefill is best bucketed by length to reduce padding waste; decode is best orchestrated by remaining length and priority to control tail latency.
    • Eviction policy should fit the business. Recent context in multi-turn sessions has higher value, while static knowledge snippets can reside long-term. Mixing both under one policy makes them squeeze each other.
    • Do not look at average throughput alone. Observe time to first token, per-token generation latency, cache hit rate, transfer wait time, and queue backlog together to locate whether the bottleneck is compute, bandwidth, or scheduling.
    • Leave headroom in capacity planning. After cache tiering, the system has more states, so buffer must be reserved for bursty long requests and hot prefixes; otherwise hit-rate gains are offset by jitter.

    5. Conclusion

    The spread of long-context and agentic applications has shifted the focus of inference-system competition from “single-GPU peak compute” to “effective throughput per unit cost.” The value of DualPath lies not in some mysterious parameter but in a clear architectural tradeoff: acknowledging that prefill and decode are two kinds of workloads, and using decoupling, tiering, overlap, and independent scaling to place each on the most suitable resources. For developers, the reusable methodology is to first quantify the workload profile, then decide cache tiers and parallelism granularity, and finally validate gains with a complete set of metrics. This approach also applies to inference services built on general cloud capabilities such as container platforms, object storage, message queues, and monitoring and alerting; when deployed on platforms like Baidu AI Cloud, the same tiering and observability framework can be used for capacity evaluation.