Redesigning State Caching for Hybrid Architecture Models: 3x Prefill Throughput

    This article explains why state caching is harder to manage in hybrid models that combine full attention layers with linear or state-space layers, and how a hybrid state caching design addresses the problem. It covers dual-track addressing, layered checkpointing, branch-aware invalidation, and tiered storage with differentiated eviction, along with the reported prefill throughput and first-token latency gains, plus practical guidance on observability, capacity planning, and consistency boundaries.

    Redesigning State Caching for Hybrid Architecture Models: 3x Prefill Throughput

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

    Over the past year, mainstream large model architectures have visibly diverged. While keeping some full attention layers, they add linear attention or state-space layers, forming a hybrid structure of “full attention + linear layers.” The motivation is clear: the inference complexity of linear layers grows roughly linearly with sequence length, and the decoding stage no longer needs to store per-token key-value pairs. It only needs to maintain a fixed-size recurrent state, which significantly reduces memory usage and makes each decoding step faster.

    For AI Agent applications, this benefit is especially attractive. A single task in an AI coding tool often involves dozens of tool calls, code retrieval, and file reads and writes, with context lengths reaching hundreds of thousands of tokens. Under a pure attention architecture, the KV Cache grows linearly with context, and any slight failure of prefix reuse causes memory pressure and jittery time-to-first-token. A hybrid architecture, by contrast, naturally has a smaller state footprint.

    But the problem is that a smaller state does not mean the cache is easier to manage.

    2. The Core Conflict: Why Hybrid State Caches Are Harder to Manage

    A “state” in a hybrid model layer actually contains two kinds of data with completely different semantics:

    • KV Cache of full attention layers: strongly bound to position, appended token by token, and precisely split and matched by block in a prefix tree.
    • Recurrent state of linear layers: a tensor that evolves over time and cannot be split by token; any forward pass overwrites and updates it.

    This creates three concrete problems:

    1. Granularity mismatch. The classic approach to prefix caching is hash addressing over fixed-length blocks, but recurrent states have no natural block boundaries, and forced splitting breaks the state semantics.
    2. Invalidation propagation. In multi-turn conversations, if a prefix fork occurs in one turn (for example, the user modifies an instruction), the full attention KV after the fork point can be discarded and rebuilt, but the linear state cannot “roll back to a certain token” and can only be recomputed from the most recent available checkpoint.
    3. Scheduling and placement conflicts. The two kinds of state differ greatly in size, lifecycle, and transfer cost. Using the same cache eviction policy and the same storage tier for both inevitably leads to “small states being squeezed out by large KV” or “hot states being dragged down by cold data.”

    This is the root cause of why prefix cache hit rates and prefill efficiency fall short of expectations in long-context AI Agent workloads under hybrid architectures.

    3. Design Approach: Modeling “State” as a First-Class Citizen

    The core idea of the state-of-the-art solutions for this problem (referred to collectively in this article as “hybrid state caching solutions”) can be summarized in four points:

    1. Dual-Track Addressing

    Build independent index spaces for the two kinds of state: the KV part continues to use block-level hashing, while the recurrent state uses “checkpoints” as its unit, recording the corresponding context length and the branch it belongs to. The two are linked through unified session-branch metadata to avoid cross-contamination.

    A schematic metadata structure:

    1. @dataclass
    2. class HybridCacheEntry:
    3. session_id: str
    4. branch_id: str
    5. kv_blocks: list[BlockHandle] # Block-level prefix cache
    6. state_ckpt: StateHandle # Linear layer recurrent state checkpoint
    7. prefix_len: int # Number of tokens consumed by this checkpoint
    8. priority: int # Scheduling priority

    2. Layered Checkpointing

    Frequently reused short prefixes keep only KV and do not store recurrent states; recurrent state checkpoints are generated only when a session enters a stable reuse range (for example, when the system prompt plus repository context stays unchanged). This avoids paying extra state management costs for one-off prefixes.

    3. Branch-Aware Invalidation

    When a prefix fork occurs, search along the branch tree for the nearest common ancestor checkpoint and recompute from that point, instead of rerunning the entire session from the start. For AI Agent scenarios, this usually means recomputing only the incremental context introduced by the most recent tool result.

    4. Tiered Storage and Differentiated Eviction

    Hot states stay in GPU memory, warm states go to host memory, and cold states sink to a distributed cache or object storage; during eviction, different weights are used for the two kinds of state to prevent large KV from monopolizing bandwidth.

    4. Engineering Gains and Implementation Notes

    In experiments replaying real AI coding traces on a single-card high-compute platform, this kind of solution raised prefill throughput to about 3x that of the baseline inference framework, and reduced p90 time-to-first-token by nearly 90%. The gains still held after adding a host memory cache on the order of hundreds of GiB, and the approach can be extended to cross-node shared hybrid state reuse.

    Three points to focus on during implementation:

    • Observability: monitor the KV hit rate and the state checkpoint hit rate separately; a divergence between the two often means the branching strategy is failing.
    • Capacity planning: estimate memory by “number of sessions × average checkpoint size” rather than reusing the estimation formula for pure KV.
    • Consistency boundaries: for cross-node reuse, clearly define the binding between state versions and model weight versions to avoid mixing them.

    5. Conclusion

    The decoding efficiency dividend brought by hybrid architectures can only be fully realized once the cache management layer is upgraded in step. Elevating the recurrent state from “auxiliary data” to a first-class cache object that is addressable, tierable, and reusable across nodes is a key step toward cutting costs and improving efficiency for long-context AI Agent workloads. For teams building long-chain applications such as AI coding and automated operations, this approach can be mapped directly onto the cache architecture design of a self-built inference service or a cloud-based containerized inference platform.