Redesigning State Caching in Hybrid Architectures: The Mechanics Behind Higher Prefill Throughput

    This article explains why prefix caching designed for full attention and KV cache breaks down in hybrid models that combine full attention layers with linear state layers. It covers the semantic differences between position-addressable KV cache and globally coupled linear state, the root causes of low cache hit rates, and a redesign approach based on state checkpointing by generation, unified addressing across a two-tier cache, prefetching, and layout-aware transfer. The article also outlines why these changes can multiply prefill throughput, how they reduce tail time-to-first-token, and a practical engineering checklist for implementation.

    1. Background: Hybrid Architectures Are Mainstream, but Cache Management Was Flattened

    A clear trend in model architecture over the past two years is the mixing of full attention layers and linear state layers within the same network. Linear state layers take forms such as gated convolutions, linear attention, and state space recurrences. The motivation is straightforward: full attention provides precise long-range retrieval, while linear layers trade a constant-size state for a lower per-token decoding cost. Together they substantially reduce overall cache footprint and increase decoding speed.

    The problem is that prefix caching in inference serving stacks was designed around a single paradigm: full attention plus KV cache. Its core assumption is that a cache can be reused block by block along sequence positions, with each block addressable and stitchable. In a linear state layer, the state is a fixed-size tensor updated in place over and over. It encodes a compressed summary of history and has no semantics for position-based slicing. As a result, prefix reuse for hybrid models cannot follow the old paradigm.

    This conflict is amplified in workloads such as coding agents. A single session can span dozens of turns, with system prompts, repository context, and tool results accumulating continuously. The historical prefix overlaps heavily but new content is inserted in the middle, so cache hit rate and reuse granularity directly determine serving cost and interaction quality.

    2. The Fundamental Difference Between the Two Cache Types

    Understanding the optimization space starts with the semantics of the two state types.

    • KV cache: Entries correspond one-to-one with positions. Entry i depends only on the first i tokens, which gives it a prefixable property. It naturally supports block-level hash addressing, on-demand loading, and cross-request sharing.
    • Linear state cache: A fixed-shape tensor independent of sequence length. Any write affects all subsequent outputs, making it a globally coupled state. It cannot be split into small blocks for individual reuse, and two states cannot simply be added together.

    This produces three concrete conflicts:

    1. Granularity mismatch: KV is managed in blocks while state is managed as a whole, so their invalidation boundaries do not align within a single request lifecycle.
    2. Invalidation propagation: Inserting or modifying a segment of context in the middle causes all subsequent linear state to drift semantically. Even if the KV blocks remain valid, they cannot be safely stitched.
    3. Asymmetric swap-in and swap-out cost: Only the needed KV blocks can be fetched, while state must be moved in its entirety. Transfer across layers and nodes can easily become a bottleneck.

    3. Root Cause of Invalidation: Why Hit Rates Stay Low

    In practice, prefix cache invalidation is usually not caused by “different text” but by cache keys built at too coarse a granularity. Common mistakes include:

    • Using an entire session as the key, so any change invalidates everything;
    • Ignoring mid-sequence changes introduced by tool call results and inserted retrieval snippets;
    • Hashing only token blocks without recording the corresponding state version, leading to semantic inconsistency after reuse;
    • Lacking unified addressing across memory, VRAM, and remote storage, producing “a hit that cannot be fetched.”

    Schematically, the cache key can be extended from a single hash to a combination of content hash, structural fingerprint, and state version:

    1. key = hash(block_tokens) ⊕ hash(layer_layout) ⊕ state_version

    The structural fingerprint distinguishes model layer configurations and parallelism layouts. The state version identifies the generation of the linear layer recurrence chain, preventing incorrect reuse across generations.

    4. Design Approach: Layered, Generationed, and Addressable

    The redesign addresses the problems above along four main lines.

    1. State generations and checkpointing. Instead of pursuing exact reuse at arbitrary positions, linear state is checkpointed at fixed intervals to form a chain of generations. On a reuse request, the system restores from the nearest generation-compatible checkpoint and recomputes a small number of incremental tokens. This turns an unsplittable global state into a manageable object of “limited generations plus short-range recomputation.”

    2. Two-tier cache coordination. The VRAM tier holds hot checkpoints and the most recent KV blocks. The host memory tier stores a larger set of cold checkpoints. Remote distributed storage handles state sharing across sessions and nodes. All three tiers use unified addressing, and hit determination is decoupled from transfer scheduling to avoid “a hit means a full pull.”

    3. Prefetching and pipeline overlap. Based on the locality of a request’s historical prefix, checkpoints and KV blocks are prefetched in advance so that transfer overlaps with computation, turning time-to-first-token from “waiting for data movement” into “waiting for computation.”

    4. Layout-aware transfer. The physical layout of a state tensor differs under different parallelism schemes. Aligning layouts or reassembling shards before transfer reduces redundant copies in cross-node communication.

    5. Why Prefill Throughput Can Increase Several Times

    The prefill stage is compute-intensive and highly reusable. The benefit chain from the design above is clear:

    • A hit skips a large amount of repeated attention computation and state recurrence for duplicate tokens;
    • Moderate checkpoint granularity balances the reusable ratio against recomputation cost, avoiding full recomputation;
    • Overlapping transfer with computation reduces GPU idle time;
    • Cross-node state reuse lets the same repository context be shared across multiple sessions, further raising the overall hit rate.

    The improvement in time-to-first-token comes mainly from tail requests. The p90 percentile is often dragged down by requests with a cold prefix and a large state transfer. Checkpointing and prefetching compress this long tail directly. After attaching a larger host memory cache, the gains remain substantial, which shows the bottleneck is not raw capacity but the addressing and scheduling mechanism.

    6. Implementation Recommendations and Engineering Checklist

    • Measure before optimizing: track prefix overlap, mid-sequence change frequency, and state reuse rate to locate the real bottleneck.
    • Govern cache keys uniformly: use the content, structure, and state version triple to avoid implicit invalidation.
    • Set the checkpoint interval: calibrate on the principle that “recomputation cost ≈ transfer cost,” and tune it against the session length distribution.
    • Plan capacity by tier: hot points in VRAM, warm points in memory, cross-session sharing in remote storage, combined with an eviction policy.
    • Complete observability: build monitoring, alerting, and log tracing for cache hits, swap-in and swap-out, and prefetch accuracy.
    • Combine with general cloud capabilities: use a container platform to host inference services, object storage or a distributed cache to hold cold state, and a monitoring and alerting system to track tail latency, which smoothly supports elastic scaling.