Accelerating Hybrid-Architecture Model Inference: State Cache Management and Prefill Throughput Optimization
Hybrid architectures that interleave full-attention layers with linear layers are increasingly common in large language models, but they introduce new challenges for prefix caching: linear layers maintain a fixed-size recurrent state rather than token-granular KV blocks. This article explains why state caching requires a redesign, presents core techniques such as fine-grained state checkpoints, unified indexing for heterogeneous caches, and tiered remote caching, and reports real-world gains of up to 3x prefill throughput and 88% lower p90 TTFT on coding-agent workloads, along with engineering best practices.
1. The Rise of Hybrid Architectures and New Caching Challenges
In recent years, linear attention and state-space layers have become common components in large model architectures. A widespread industry practice is the hybrid architecture that alternates “full-attention layers + linear layers”: full-attention layers handle precise long-range dependency modeling, while linear layers (such as linear attention, gated linear units, and state-space models) replace the ever-growing KV Cache with a fixed-size recurrent state, trading it for faster decoding and lower memory footprint.
This architecture performs well under workloads like single-turn dialogue and short-text generation. But for emerging workloads such as coding agents, the situation changes significantly. A coding agent’s typical working pattern is:
- Multi-turn interaction: A single task often involves dozens of rounds of tool calls and model inference, where each round’s input appends a small amount of new content to the previous context;
- Very long context: Repository files, tool outputs, and conversation history keep accumulating, and context length easily reaches tens of thousands or even over a hundred thousand tokens;
- Highly shared prefixes: Adjacent requests often share more than 90% of their prefix, making them an ideal scenario for prefix caching.
For pure-attention models, prefix caching is relatively straightforward: the KV Cache is naturally stored in per-token blocks, so KV blocks corresponding to a shared prefix can be directly reused. But the linear layers in a hybrid architecture maintain a fixed-size state compressed from the entire prefix—this state is a “full summary” of all prefix tokens, not a token-by-token concatenable structure. This means:
- State can only be reused at positions exactly aligned with the prefix, unlike the KV Cache, which supports partial reuse at arbitrary block granularity;
- State storage, retrieval, versioning, and cross-request sharing require entirely new mechanism designs;
- The two heterogeneous caches—KV cache and linear state—must be scheduled in coordination, or you end up in the awkward situation of “KV hit but state missing,” still requiring large amounts of prefix recomputation.
2. Redesigning the Hybrid State Cache
To address these problems, the industry’s direction is to elevate the hybrid state cache to a first-class citizen of the inference system, redesigning the cache management framework around “state checkpoints + chunked reuse.” The core ideas include the following.
2.1 Fine-Grained State Checkpoints
Although the linear-layer state is indivisible, intermediate state snapshots can be saved at fixed intervals during prefill. For example, a state checkpoint is persisted after every N token blocks processed. When a new request shares a common prefix with the cache, the system can find the longest cached checkpoint and continue incremental computation from that position, instead of recomputing the entire prefix from scratch.
The checkpoint interval is a classic space-for-time trade-off: smaller intervals increase reuse hit rates but cost more memory. In practice, the interval is usually tuned dynamically based on the statistical distribution of request prefix lengths.
2.2 Unified Indexing of Heterogeneous Caches
KV blocks and state checkpoints need to be managed under a single indexing and eviction policy. A reasonable approach is to organize cache entries with a prefix hash tree (or a similar dictionary structure), where each tree node records both the KV block pointer and the nearest state checkpoint pointer for that position. When a request arrives, the system matches the longest common prefix along the tree and determines in one pass “which KV blocks to reuse and which state checkpoint to resume from,” avoiding duplicated computation caused by two caches operating independently.
2.3 Scheduler-Coordinated Latency Hiding
Loading state checkpoints (especially from CPU memory or remote storage) can proceed in parallel with GPU-side KV block transfers and batch scheduling. Through prefetching and pipelining, the “context restoration” overhead after a cache hit can be hidden behind computation, further reducing time to first token (TTFT).
3. Real-World Gains: Prefill Throughput and TTFT
In evaluations based on real coding-agent trace replays (on next-generation data-center GPUs), the redesigned state caching system achieved the following compared to the default implementations of mainstream open-source inference engines:
- Up to roughly 3x higher prefill throughput. The gains mainly come from eliminating large-scale prefix recomputation—in multi-turn agent workloads, the vast majority of prefix tokens hit the cache directly, and the GPU only processes the incremental portion;
- Up to roughly 88% lower p90 TTFT. Cache hits significantly shorten the wait from request arrival to the first output token, which is especially noticeable for interactive coding experiences;
- Gains remain significant with large-capacity remote caching. When local GPU memory cannot hold all historical states, cold states can be tiered down to CPU memory pools of hundreds of GiB or to distributed storage. Through cross-node state reuse, different instances in a cluster can also share prefix computation results.
It is worth noting that these optimizations benefit workloads with “inherently high cache hit rates” the most. If your traffic has low prefix duplication, the gains will shrink accordingly—so before deployment, you should analyze the prefix distribution of your own traffic.
4. Engineering Best Practices
4.1 Observe Prefix Characteristics First
Before introducing complex caching mechanisms, use logging services and monitoring/alerting systems to measure: prefix overlap between adjacent requests, context length distribution, and request arrival rates. These data determine key parameters such as checkpoint intervals and cache capacity allocation.
4.2 Adopt a Tiered Caching Architecture
A three-level structure is recommended: “GPU memory → host memory → distributed remote storage.” Hot states stay in GPU memory, warm states sink to host memory, and cold states go to remote storage (object storage or distributed key-value stores can enable cross-node sharing). Each tier needs its own eviction policy and consistency guarantees.
4.3 Handle State Serialization and Version Compatibility
When state checkpoints need to be persisted, you must define a stable serialization format and handle cache invalidation caused by model version upgrades. It is recommended to include the model version number in the cache key, to avoid hard-to-debug errors from mixing old and new states.
4.4 Stress-Test with Realistic Workloads
Synthetic benchmarks often overestimate caching benefits. The most reliable approach is to record real production request traces and replay them for load testing, focusing on p90/p99 TTFT and end-to-end latency rather than average throughput alone.
5. Conclusion
Hybrid-architecture models trade smaller KV footprints for higher decoding efficiency, but they also elevate prefix cache management from “block reuse” to a systemic “state reuse” problem. Through fine-grained state checkpoints, unified indexing of heterogeneous caches, tiered remote caching, and scheduler coordination, it is possible to achieve roughly 3x prefill throughput improvement and nearly 90% TTFT reduction on real coding-agent workloads. For teams building long-context agent applications, state cache design deserves the same level of attention as model selection and scheduling strategy—it should be a core part of inference architecture planning.
