Hybrid-Architecture LLM Inference Optimization: Rethinking State Caching to Improve Prefill Throughput
This article examines the cache management challenges of hybrid-architecture large language models that combine full-attention layers with linear layers, especially in multi-turn Agent workloads. It introduces a hybrid state cache architecture that decouples KV Cache from linear-layer state cache, uses block-based KV slicing and state snapshots, and restores historical context without redundant prefill computation. The article also reviews measured gains in coding-Agent scenarios, including up to 3.14× higher prefill throughput and up to 88.4% lower P90 TTFT, and discusses CPU tiering, distributed cache reuse, and cloud-native deployment practices.
1. The Rise of Hybrid-Architecture LLMs and Cache Management Challenges
In recent years, as context windows for large language models continue to expand, traditional pure Transformer architectures face significant GPU memory pressure during inference. To achieve faster decoding and a smaller KV Cache footprint, the industry has increasingly adopted hybrid architectures that combine full-attention layers with linear layers. In such architectures, some layers use conventional self-attention to preserve global modeling capability, while other layers use linear attention or RNN-like structures that maintain a fixed-size “state” instead of a large historical KV Cache. This design significantly reduces memory overhead and makes it possible to run longer-context models under the same hardware conditions.
However, in Agent scenarios such as intelligent coding assistants that require multi-turn interaction and long-context workloads, prefix cache management for hybrid-architecture models becomes much more complex than for pure Transformer models. In a pure Transformer architecture, context reuse across multi-turn conversations is straightforward: historical conversation KV Cache can simply be retrieved from the cache pool and concatenated. A hybrid architecture, by contrast, must manage not only KV Cache but also restore the state cache of linear layers. Without an efficient state management mechanism, an Agent may be forced to recompute large historical prefixes in every interaction round, causing prefill computation to surge and first-token latency (TTFT) to remain high, which severely affects user experience.
2. Design Philosophy of a New Hybrid State Cache Architecture
To address these pain points, a new hybrid state cache management architecture has emerged. Its core design philosophy is to achieve precise decoupling and efficient coordination between KV Cache and state cache, using customized storage and recovery strategies based on the data structure characteristics of different layers.
First, the architecture applies fine-grained slicing management to the KV Cache of full-attention layers. By dividing long prefixes into fixed-size blocks that are easy to index, the system can quickly locate the context boundaries that have changed during multi-turn conversations, compute only the incremental parts, and maximize the prefix cache hit rate.
Second, for the state cache of linear layers, the architecture introduces a dedicated state serialization and deserialization mechanism. The state of a linear layer is usually a high-dimensional tensor that evolves incrementally across multi-turn interactions. By recording state snapshots, the new architecture allows the model to restore historical context directly from the snapshot state without re-executing the recursive computation of linear layers.
The following pseudocode illustrates the cache management logic:
class HybridCacheManager:def __init__(self):self.kv_cache_pool = {} # Manages full-attention layer cachesself.state_cache_pool = {} # Manages linear-layer state cachesdef restore_context(self, session_id, new_prompt):# Retrieve historical prefixhistorical_kv = self.kv_cache_pool.get(session_id)historical_state = self.state_cache_pool.get(session_id)if historical_kv and historical_state:# Cache hit: compute only the incremental promptreturn self.forward_incremental(historical_kv, historical_state, new_prompt)else:# Cache miss: perform full prefillreturn self.forward_full(new_prompt)def update_cache(self, session_id, new_kv, new_state):self.kv_cache_pool[session_id].append(new_kv)self.state_cache_pool[session_id] = new_state
3. Performance Breakthroughs in Real Agent Scenarios
In actual performance tests, the research team rigorously validated the hybrid state cache solution on latest-generation high-performance GPUs by replaying real interaction traces from an intelligent coding assistant. Test results show that, compared with current mainstream open-source inference frameworks, the solution improves prefill-stage throughput by up to 3.14×. For the latency most sensitive to users, it reduces P90 TTFT by up to 88.4%.
The fundamental reason for this performance leap is the elimination of redundant prefill computation in multi-turn conversations. In complex coding Agent tasks, users often modify part of the code or append new instructions, while the preceding system prompt and historical codebase context remain unchanged. The new cache architecture can accurately identify these invariants and compress a prefill process that might otherwise take several seconds to the millisecond level.
Moreover, the architecture still delivers significant performance benefits after introducing a large-capacity CPU tiered cache, such as at the 512GiB level. When GPU memory is insufficient to hold the caches of all active sessions, the system smoothly migrates cold data to CPU memory or even NVMe disks, using an efficient asynchronous transfer mechanism to hide I/O latency and maintain stable system throughput under very high concurrency.
4. Distributed Evolution and Cloud-Native Engineering Practices
As Agent applications scale, single-node cache capacity quickly becomes a bottleneck. Therefore, the hybrid state cache architecture natively supports distributed storage and cross-node hybrid state reuse. This means that when a user’s Agent request is scheduled by load balancing to a different compute node, the new node can pull the corresponding KV Cache and state snapshots from the distributed cache cluster, enabling seamless session migration.
In engineering practice, enterprises can use cloud-native infrastructure such as Baidu AI Cloud to build efficient inference clusters of this kind. For example, high-performance computing instances can provide sufficient GPU compute power and high-speed local NVMe disks, while Object Storage Service (BOS) can provide persistent backup for large-scale historical state snapshots. Container instances and load balancing services can flexibly handle traffic fluctuations from Agent workloads. Through cloud-native elastic scaling, enterprises can maintain very low first-token latency while effectively controlling inference costs.
5. Conclusion and Future Outlook
Hybrid architectures represent an important evolution direction for large models in long-context and high-throughput inference. However, changes in hardware architecture inevitably require synchronized innovation in the software stack. The proposed hybrid state cache design not only effectively solves the challenge of multi-turn long-context reuse in Agent scenarios, but also provides valuable ideas for inference optimization in future complex tasks such as multimodal and ultra-long video understanding.
As large model applications continue to deepen, inference framework optimization will gradually shift from purely operator-level acceleration to system-level and architecture-level global coordination. For developers and enterprises, keeping up with these underlying inference technology trends and rationally using cloud-native infrastructure to build high-performance, low-latency AI services will be key to maintaining competitiveness in the AI era.
