Redesigning State Caching for Hybrid Architectures: 3x Prefill Throughput
This article explains why hybrid architectures that interleave full-attention and linear or state layers make prefix caching complex, and how to redesign state management around content-addressed objects, tiered storage, and prefetch scheduling. It covers the core design, storage tiers, scheduling pseudocode, reported throughput and latency results, and practical deployment recommendations for AI coding agent workloads.
1. Why Hybrid Architectures Make Caching Heavy
A hybrid architecture that alternates full-attention layers with linear or state layers has become increasingly common in recent model designs. The benefits are clear: linear layers do not grow the cache with context length and use less bandwidth during decoding, while full-attention layers preserve exact lookback and compensate for the recall loss of purely linear models.
Under coding agent workloads, however, prefix cache management erodes those benefits for three reasons:
- Heterogeneous state types. Full-attention layers need key-value pairs, while linear layers need recurrent state (convolution kernel state or matrix state). Their tensor shapes, lifetimes, and eviction costs are completely different.
- Mismatched reuse granularity. An agent appends tool output after the same long prefix on every turn, so the ideal reuse unit is the “turn.” Cache blocks are usually split at a fixed token count, which causes repeated recomputation at boundaries.
- Asymmetric swap-in and swap-out. Key-value caches can be partially swapped out by block, but state caches often can only be saved as a whole. Once a prefix forks, copying costs rise sharply.
2. Core Design: Unify Both State Types as Addressable Objects
The key abstraction is to stop distinguishing “cache” from “state” and model both as versioned, content-addressed objects. Each object carries metadata such as layer type, sequence position, offset within a block, and the hash of its predecessor object.
@dataclassclass StateObject:key: str # prefix hash + layer type + block indexkind: str # "kv" or "recurrent"pos_range: tuple # token range coveredparent: str | None # fork dependencydevice_tier: str # hbm / host / remote
The direct benefit is that a fork point in the prefix tree only needs to copy a few state objects instead of an entire cache segment. For cross-node reuse, the peer pulls only the missing objects by key, which naturally supports incremental alignment.
3. Tiered Storage and Prefetch Scheduling
The second layer of the design coordinates storage tiers with scheduling:
- Hot tier in GPU memory, keeping only the current turn and the previous turn’s state.
- Warm tier in host memory, sinking whole segments at turn boundaries to avoid block-level fragmentation.
- Cold tier backed by a large memory pool or distributed cache, used for prefix reuse across sessions and nodes.
The scheduler needs to be aware of “state alignment points.” After an agent’s tool call returns, it proactively triggers a prefetch that moves the prefix state likely to be hit in the next turn into the hot tier ahead of time. Pseudocode:
if event == "tool_result_ready":prefix = planner.expected_prefix(turn + 1)cache.prefetch(prefix, tiers=["host", "remote"], budget=mem_budget)scheduler.pin(prefix, until=turn + 2)
Combined with budget-aware eviction, which drops linear-layer state first when GPU memory is tight because recomputation is cheap and keeps attention key-value blocks because recomputation is expensive, this can significantly reduce jitter.
4. Results and Engineering Benefits
In experiments replaying real agentic coding traces on general-purpose GPU platforms, this design raised prefill throughput to roughly three times that of a naive baseline, while p90 time-to-first-token dropped by nearly 90%. The gains held after connecting a host memory pool of hundreds of gigabytes, indicating that the bottleneck has shifted from compute to state movement efficiency.
The practical implication for engineering teams is that the throughput gain comes mainly from “computing less,” not from “computing faster.” Cache hit rate and alignment point coverage should therefore become core observability metrics, added to logging services and monitoring alerts and linked with elastic scaling in container platforms.
5. Deployment Recommendations
- First measure the workload’s prefix reuse rate and fork depth, then choose the block granularity.
- Make sure state objects are content-addressed and versioned to avoid dirty reads.
- Order eviction by “recomputation cost” rather than “least recently used.”
- Define consistency boundaries clearly for cross-node reuse, allowing eventually consistent incremental alignment.
- Stress-test with real multi-turn traces rather than single-turn long text, which is the only way to expose state management bottlenecks.
Overall, the next stage of competition in hybrid architectures is not about the ratio of layer counts, but about the abstraction and scheduling of state caching. Unifying heterogeneous state into addressable, tierable, prefetchable objects is the key path to several-fold prefill throughput gains, and it can be deployed directly on the general container and storage capabilities of platforms such as Baidu AI Cloud.
