Optimizing Hybrid State Caching for Hybrid-Architecture LLM Agent Inference
This article explores the cache management challenges of hybrid-architecture large language models—combining full attention layers with linear layers—in multi-turn, long-context Agent workloads. It explains why heterogeneous KV caches and linear state tensors complicate prefix caching, presents a redesigned hybrid state caching approach with unified lifecycle management, adaptive batch loading, and state-aware paged scheduling, and shares performance results showing up to 3.14× prefill throughput and an 88.4% reduction in p90 time-to-first-token. It also discusses distributed extensions such as CPU-pooled caching and cross-node hybrid state reuse.
As large language models are increasingly applied to Agent scenarios such as deep coding and long-document analysis, co-optimizing the model architecture with the underlying inference system has become critical. To achieve faster decoding and smaller cache footprints without sacrificing model capability, mainstream LLMs have widely adopted hybrid architectures that combine full attention layers with linear layers. However, in multi-turn, long-context workloads, prefix cache management for this architecture is far more complex than for pure Transformer models.
1. Cache Pain Points of Hybrid Architectures in Agent Scenarios
In traditional pure Transformer architectures, the inference engine primarily manages a uniform KV cache. Mainstream inference frameworks already offer mature scheduling mechanisms for this—such as paged attention—which handle memory fragmentation in multi-turn conversations reasonably well.
In hybrid architectures, however, the situation changes fundamentally. Full attention layers still produce conventional KV caches, while linear layers (such as various state space models or linear RNN variants) produce implicit state tensors that evolve with each time step. These two types of caches differ significantly:
- Structural heterogeneity: The KV cache grows linearly with sequence length, whereas linear layer states are typically fixed-dimension tensors that are continuously overwritten as time steps advance.
- Different memory access patterns: KV cache reads are usually highly parallel matrix multiplications, while updates and reads of linear layer states carry strong sequential dependencies.
- Lifecycle misalignment: In multi-turn Agent interactions, as conversation history accumulates, the system must frequently perform prefix cache hit checks and restore historical states. Coordinated swapping of heterogeneous caches easily triggers memory bandwidth contention and fragmentation, causing prefill latency to spike and time-to-first-token (TTFT) to degrade severely.
2. The Solution: Redesigning Hybrid State Cache Management
To address these challenges, the industry has proposed a new hybrid state cache management scheme that reconstructs state scheduling logic for hybrid architectures from the ground up. The core idea is to build a unified view of heterogeneous states, treating the full attention KV cache and the linear layer state tensors as an inseparable “state package” under joint lifecycle management.
In terms of engineering implementation, the scheme adopts the following optimization strategies:
- Adaptive batch loading: When performing prefill operations, the system predicts the required hybrid state packages and uses an adaptive batch loading strategy to efficiently reassemble historical states from GPU memory or host memory. This effectively reduces kernel launch overhead and PCIe bus bandwidth waste caused by stitching together heterogeneous data.
- State-aware paged scheduling: Drawing on traditional paging mechanisms but customized for the particularities of linear states, fixed-dimension state tensors and variable-length KV caches are mapped to separate physical page pools and logically bound together. This enables efficient reuse while avoiding memory fragmentation.
3. Performance Validation: Breaking the Prefill Throughput Bottleneck
To validate the practical effectiveness of the scheme, the research team conducted rigorous performance tests on the latest generation of high-performance GPUs by replaying real interaction traces from an intelligent coding tool. The test environment simulated complex scenarios in which developers iterate on code and repair context across multiple rounds with an AI assistant.
The results show that, thanks to more efficient cache hits and concurrent scheduling, the scheme achieved prefill throughput of up to 3.14× that of mainstream open-source inference frameworks. More importantly, in long-context multi-turn interactions, p90 time-to-first-token (TTFT) was reduced by up to 88.4%. This means end users experience near-instant responses when waiting for the AI assistant to generate large blocks of code or perform in-depth analysis, greatly improving the continuity of Agent workflows and the overall user experience.
4. Distributed Evolution and Cross-Node Hybrid State Reuse
As context lengths continue to grow, the memory of a single GPU often cannot hold all historical states. The inference system must then rely on larger-capacity CPU memory or even distributed storage pools to extend the cache.
This new caching scheme is not limited to single-GPU optimization; it also supports CPU-pooled caches of hundreds of GiB. Under this extended architecture, the performance gains remain significant. More importantly, for distributed inference scenarios, the scheme natively supports cross-node hybrid state reuse. This means that in multi-GPU tensor parallelism or multi-node pipeline parallelism, different compute nodes can efficiently share and synchronize hybrid states, avoiding redundant computation over the same prefix.
In real-world enterprise-grade cloud-native deployments, this kind of complex state management typically needs to be tightly integrated with the underlying infrastructure. For example, cross-node state reuse depends on high-throughput container networking, while CPU-pooled caches can leverage distributed block storage for durable fallback. Baidu AI Cloud’s container platform and distributed storage services provide stable infrastructure support for hybrid-architecture inference workloads that frequently exchange large tensors across nodes, ensuring the inference engine runs efficiently.
5. Conclusion and Outlook
Hybrid-architecture LLMs represent an important technical direction in the pursuit of balancing efficiency and capability. However, heterogeneous state management has long been an invisible barrier to deploying these models in complex Agent scenarios. By redesigning hybrid state caching, it is possible not only to break the prefill performance bottleneck but also to provide a viable path for cross-node collaboration in multi-turn, long-context workloads. Looking ahead, as Agent workflows grow ever more complex, coordinated optimization of hybrid states—from low-level operators up to high-level frameworks—will become a standard component of LLM inference acceleration.
