Optimizing State Cache in Hybrid Architectures: 3x Prefill Throughput
This article explains why hybrid architectures that interleave full attention and linear state layers are becoming the default for long-context workloads, and why their mixed cache types make prefill the bottleneck. It covers the engineering challenges of heterogeneous caching, a redesign that manages attention and state caches as separate first-class systems, tiered storage and cross-node reuse, and reported gains of roughly 3x prefill throughput with much lower p90 time-to-first-token. A phased adoption path is included.
1. Hybrid Architectures Are Becoming the Default for Long-Context Workloads
Recent model design trends have moved beyond stacking pure attention layers. A number of newly released models now alternate full attention layers with linear or state layers. A small number of global attention layers preserve precise long-range retrieval, while the many linear state layers deliver constant-time decoding and a smaller cache footprint. For developers, the immediate payoff is lower memory pressure and more concurrent sessions per device.
Those gains are not unconditional. In workloads such as AI coding tools, a single task often involves dozens of tool calls, code re-reads, and file diffs, pushing context length past 100,000 tokens with ease. At that point the bottleneck shifts from decoding to prefill: every new turn must feed the historical prefix back into the model, scaling both computation and cache movement.
2. Why Cache Management Is Harder for Hybrid Models
Pure attention models have uniform cache semantics: each layer and head holds a tensor that grows by position, and eviction, swapping, and reuse can all be handled by the same paging logic. Hybrid architectures break that assumption by splitting the cache into two heterogeneous object types.
- Attention portion: grows linearly with sequence length, can be split into blocks, and supports exact prefix-match reuse.
- State portion: produced by recurrent updates, it is “compressed history” that cannot be sliced arbitrarily by token position or simply concatenated.
This creates three engineering problems. First, mismatched lifecycles: the invalidation boundary of state-layer cache does not align with attention blocks, so a partial prefix hit often leaves “half reusable, half must be recomputed.” Second, layout conflicts: the two object types differ in paging granularity, alignment requirements, and transfer units, so a unified memory pool generates heavy fragmentation. Third, scheduling blind spots: traditional schedulers account only for token counts and attention cache usage, ignoring the transfer cost of state cache, which leads to suboptimal batch assembly.
3. Redesign: Treat Both Cache Types as First-Class Citizens
One validated approach is to split attention cache and state cache into two independently managed pipelines, then make joint decisions at a higher layer. It has four core elements.
1) Heterogeneous paging. Attention cache keeps block-based paging; state cache uses a “layer group” as the minimum migration unit, persisted or swapped out at a fixed stride to avoid the metadata explosion of per-token granularity.
2) Layered prefix fingerprint validation. First compare a short-prefix hash for fast rejection, then validate the state segment layer by layer. Only when everything aligns is the prefix deemed reusable, preventing the numerical drift caused by partial hits.
3) Overlap prefill with cache loading. Place asynchronous prefetch of state cache in the same pipeline as the first computation of attention blocks, using computation to hide I/O latency. This is the main source of lower time-to-first-token.
4) Make the scheduler cache-heterogeneity aware. The cost function counts attention block hits, state segment hits, and transfer bandwidth usage together, as illustrated below:
def score(req, cache):hit_attn = cache.match_blocks(req.prefix) # number of hit blockshit_state = cache.match_states(req.prefix) # number of hit layer groupsload_bytes = (req.blocks - hit_attn) * BLOCK_BYTES \+ (req.layers - hit_state) * STATE_BYTESreturn hit_attn * W1 + hit_state * W2 - load_bytes / BANDWIDTH
4. Tiered Storage and Cross-Node Reuse
A single device’s memory cannot hold the entire cache for a long session, so a three-tier system spanning device memory, host memory, and remote storage is needed. On the host side, reserve a memory pool on the order of hundreds of GiB as a warm tier; use a distributed cache or object storage as the cold tier, paired with an eviction policy (such as approximate LRU weighted by session activity) to control origin-fetch frequency.
The key to cross-node reuse is not storage but consistency: state cache must be validated against the model weight version and parallelism layout, otherwise reuse can silently produce incorrect results. In practice, tag each cache with the model version and parallel topology, and treat any mismatch as a miss.
5. Results and Adoption Recommendations
In an experiment replaying real coding-tool call traces on a single high-end accelerator, this kind of redesign reached roughly 3x the prefill throughput of a general-purpose inference framework, while p90 time-to-first-token dropped by nearly 90%. After adding a host memory cache of hundreds of GiB, the gains for long sessions remained significant from the second turn onward.
For adoption, proceed in three steps: first enable attention prefix caching for baseline gains; then introduce heterogeneous paging and layered validation for state cache; finally integrate a distributed cache for cross-node reuse. Running the tiered cache on the container platform, object storage, and monitoring and alerting capabilities of platforms such as Baidu AI Cloud can significantly simplify operations, while metrics observation continuously tunes eviction policy and batch-assembly parameters.
