Optimizing State Caching in Hybrid Architectures: Up to 3x Higher Prefill Throughput

    This article examines why caching is harder to manage in hybrid architectures that combine full attention layers with linear state layers, especially under multi-turn agent workloads. It presents a redesign that unifies two heterogeneous state types across GPU memory, CPU memory, and distributed storage through tiered caching, a prefix tree with state snapshots, and cost-aware eviction and prefetching. It also covers prefill pipelining, cross-node reuse, and measured results showing up to 3.14x prefill throughput and up to 88.4% lower p90 time-to-first-token, along with practical deployment recommendations.

    1. Introduction: Why Hybrid Architectures Are Becoming the Default for Long-Context Workloads

    Major model architectures are shifting from pure attention stacks toward hybrid designs that combine full attention layers with linear state layers. These models offer lower computational complexity during decoding and a significantly smaller KV Cache footprint, giving them a natural advantage in long-context scenarios.

    However, when the workload shifts from single-turn question answering to multi-turn, long-context, prefix-heavy interactions such as coding agents, cache management complexity rises sharply. The theoretical benefits of hybrid architectures do not automatically translate into real throughput.

    This article takes a general technical perspective and breaks down the prefix caching and state caching challenges of hybrid architecture models under agent workloads. It then presents a complete redesign approach: how to orchestrate two heterogeneous state types across GPU memory, CPU memory, and distributed storage, increasing prefill throughput by several times while keeping p90 time-to-first-token extremely low.

    2. Background: Why Caching Is Harder in Hybrid Architectures

    2.1 Semantic Differences Between Two State Types

    In pure attention models, context is stored layer by layer as KV pairs. Cache entries are homogeneous and can be reused at arbitrary prefix boundaries. Hybrid architectures maintain two state types at the same time:

    • Attention state: strongly bound to specific token positions and reusable block by block along a prefix;
    • Linear state: compressed from the entire history into a fixed-length summary that evolves over time and cannot be simply split by token.

    As a result, the same prefix has completely different reuse granularity, invalidation conditions, and migration costs across the two state types.

    2.2 Three Amplifiers in Agent Workloads

    1. Multi-turn accumulation: tool call results, code snippets, and retrieved content are appended continuously, so the prefix keeps growing;
    2. Frequent branching: a single session produces retries, rollbacks, and parallel subtasks, causing the prefix to branch like a tree;
    3. Short lifecycles: the reuse window for a single prefix may last only a few seconds, so eviction policies must be highly sensitive.

    Under these three amplifiers, sticking to a single-stack approach that caches only KV leads to a cascade of problems: sharply lower hit rates, repeated prefilling, memory fragmentation, and surging cross-node transfer overhead.

    3. Core Design: Unified Orchestration of Both State Types

    3.1 Tiered Cache Pools

    The cache is split into three tiers: a GPU memory hot tier, a CPU memory warm tier, and a distributed storage cold tier. The hot tier keeps only the prefixes most likely to be reused by the current session; the warm tier holds recently evicted branches that may still be revived; the cold tier supports long-term reuse across sessions and nodes. All three tiers map to each other through unified block addressing, avoiding the problem where the same prefix is stored separately in different tiers without being recognized as the same entry.

    3.2 Prefix Tree Plus State Snapshots

    A prefix tree describes session branching, with each node bound to both state types:

    1. root
    2. ├─ sys_prompt (attn: A1, state: S1)
    3. │ ├─ file_read (attn: A2, state: S2)
    4. │ │ ├─ retry_branch (attn: A3, state: S3)
    5. │ │ └─ rollback (reuse A2/S2)
    6. │ └─ tool_call

    Rollbacks and retries no longer require re-prefilling. Instead, they return directly to the snapshot of the nearest common ancestor. Linear state is stored as snapshots plus deltas, and only the differences are recomputed.

    3.3 Cost-Aware Eviction and Prefetching

    Eviction scoring considers reuse distance, branch activity, state reconstruction cost, and cross-tier transfer bandwidth. Linear states with high reconstruction costs receive a higher survival weight. Prefixes about to be hit by parallel subtasks are prefetched into the hot tier in advance, overlapping data movement with computation.

    4. Key Optimization: Pipelining the Prefill Stage

    1. Chunked prefill: long prefixes are split into fixed-size blocks, processed in parallel within each block and pipelined across blocks, avoiding a single long sequence filling up GPU memory at once;
    2. Parallel construction of both states: attention blocks and linear state deltas advance in parallel within the same batch, reducing serial waiting;
    3. Skip on hit: a prefix hit skips recomputation for the corresponding tier, and only the unmatched tail receives incremental prefill;
    4. Mixed in-batch scheduling: long requests that need heavy prefilling are mixed with short decoding requests to smooth GPU utilization and prevent long requests from hurting tail latency.

    5. Distributed and Cross-Node Reuse

    When a single machine’s cache is insufficient, the design introduces a CPU cache pool on the order of 512GiB and a multi-node state repository. Prefix blocks are identified by content-addressed global keys, and nodes locate the holder through consistent hashing. Cross-node reuse verifies fingerprints first and then pulls only the missing blocks incrementally. This supports sharing system prompts and common code context across sessions, and also enables fast recovery after a session migrates between nodes.

    6. Measured Gains and Engineering Lessons

    When replaying real coding agent traces on a single high-end GPU, the redesigned approach achieved up to approximately 3.14x prefill throughput compared with a general-purpose inference framework, and up to approximately 88.4% lower p90 time-to-first-token. The gains remained significant after adding a 512GiB CPU cache. Three engineering lessons stand out:

    • Caching is not an add-on but a first-class citizen on par with the scheduler;
    • Hybrid architectures require managing both states together; any single-stack approach leaves a performance cliff;
    • The gains come mainly from computing less rather than computing faster; hits and reuse are the first principle.

    7. Implementation Recommendations

    To reproduce similar gains in your own inference service, start with a minimal closed loop: first unify block addressing and fingerprint verification, then add the prefix tree and snapshot rollback, and finally extend to the CPU and distributed tiers. Combined with containerized deployment, object storage for cold-tier persistence, and monitoring and alerting for hit rate and tail latency, this approach can evolve smoothly in a general cloud environment such as Baidu AI Cloud without binding to any proprietary interfaces.