Optimizing Agent Inference for Hybrid Architecture Models: State Caching and Throughput Improvement
This article explores the inference challenges of hybrid architecture models combining full attention with linear layers in long-context, multi-turn Agent scenarios. It analyzes why heterogeneous state management complicates prefix caching, presents a state cache reconstruction approach featuring separated memory management, on-demand computation, and hardware-software co-optimization, and shares benchmark results showing up to 3.14x prefill throughput improvement and 88.4% p90 TTFT reduction, along with distributed cross-node state reuse practices for enterprise deployment.
As large language models take on increasingly complex tasks, the latest frontier models have widely adopted a hybrid architecture combining full attention mechanisms with linear layers. The core advantage of this design is that it accelerates decoding and dramatically shrinks the KV Cache that a pure Transformer model would otherwise need to maintain. However, when these hybrid models are applied to Agent workloads such as intelligent coding tools—which involve multi-turn, long-context interactions—prefix cache management at the underlying layer faces far more complex challenges than with pure Transformer models.
1. Analyzing the Complexity of State Caching in Hybrid Architectures
In a traditional pure Transformer architecture, the model’s state is primarily maintained through the KV Cache. For multi-turn conversations or coding Agent scenarios, the system only needs to load the KV Cache of historical tokens into GPU memory during the prefill phase to quickly restore context. In a hybrid architecture of “full attention + linear layers,” however, state management becomes fragmented. Linear layers, which typically exhibit RNN-like recursive characteristics, maintain an implicit state rather than explicit key-value pairs.
This heterogeneous state creates a dual challenge for cache management. First, the KV Cache of full attention layers requires high-capacity, high-bandwidth memory, while the linear layer states are small in size but involve complex update logic. Second, in multi-turn Agent interactions, each round of input requires not only concatenating historical tokens but also accurately reconstructing the recursive state of the linear layers. If prefix caching is mismanaged, frequent state reconstruction and data movement will severely degrade prefill efficiency, causing Time to First Token (TTFT) to remain stubbornly high.
2. Design of an Innovative State Caching Solution
To address these pain points, a joint research team from academia and industry proposed a new state cache reconstruction solution. The core idea is to break away from the traditional single-cache-pool mindset and perform fine-grained decoupling and reconstruction tailored to the characteristics of hybrid architectures.
- Separated management of heterogeneous states: The KV Cache of full attention layers and the internal states of linear layers are physically isolated in memory layout. The KV Cache uses a page-based memory management mechanism to accommodate its large capacity and on-demand allocation needs, while linear layer states are managed in compact, contiguous memory blocks to ensure low-latency reads and writes during state updates.
- On-demand computation and cache reuse: In multi-turn interactions, the system no longer blindly recomputes all historical tokens. Instead, it builds a state index to precisely locate and reuse previously computed intermediate states of the linear layers. Incremental computation is triggered only when context truncation occurs or states become invalid.
- Hardware-software co-optimization: Leveraging the memory hierarchy of next-generation GPUs, the data flow path of states between SRAM and HBM is optimized, reducing memory access bottlenecks caused by state initialization during the prefill phase.
3. Measured Performance Gains in Throughput and Latency
To validate the effectiveness of this state cache reconstruction solution, the research team replayed real execution traces from intelligent coding tools on next-generation high-performance GPUs. Test results show significant improvements over mainstream open-source inference engines across several core metrics.
In terms of prefill throughput—thanks to the fast recovery mechanism for linear layer states and the sharp reduction in data movement overhead—the solution achieved up to 3.14x the throughput of mainstream inference engines. This means that when handling context inputs from extremely large codebases, the system can prepare for generating the first token much faster.
In terms of latency, p90 TTFT was reduced by up to 88.4%. For coding Agents, low latency is essential to the developer experience, and this substantial improvement marks a new level of usability for hybrid architecture models in real-time interactive scenarios. More importantly, when a CPU cache tier of up to 512 GiB was added to further extend context capacity, the throughput and latency gains remained significant, demonstrating the robustness of the solution across different storage tiers.
4. Distributed Evolution: Cross-Node State Reuse and Cloud-Native Practice
Building on single-machine optimization, extending the massive hybrid state cache to distributed clusters is critical for enterprise-grade deployment. The solution further supports distributed storage and cross-node reuse of hybrid states. This means that when multiple users concurrently invoke an Agent, different compute nodes can share cached states of common prefixes—such as system prompts or shared codebases—avoiding redundant computation.
In enterprise deployments, combining this architecture with the underlying capabilities of general cloud platforms such as Baidu AI Cloud can further amplify its advantages. For example, by relying on high-performance distributed storage systems and container computing platforms, developers can build elastic state cache resource pools. When Agent workloads surge, cloud-native auto-scaling can dynamically allocate compute nodes, while high-speed networking (such as RDMA) enables low-latency synchronization and reuse of states across nodes. This architecture not only improves resource utilization but also provides foundational support for building large-scale intelligent coding service platforms.
5. Conclusion and Outlook
The hybrid architecture of “full attention + linear layers” represents an important direction in the pursuit of extreme efficiency for large language models. However, architectural innovation inevitably brings adaptation challenges for the underlying system software. By reconstructing KV and state cache management, the innovative state management solution successfully breaks through the prefill bottleneck of hybrid architectures in long-context Agent scenarios.
For developers and enterprises, this technical practice reveals an important trend: in future LLM infrastructure, relying solely on hardware compute improvements will no longer be sufficient to handle complex workloads. Only by starting from the characteristics of the model architecture, deeply customizing the cache scheduling and distributed coordination mechanisms of the inference engine, and leveraging the elastic compute and storage capabilities of mature cloud platforms such as Baidu AI Cloud can the productivity of hybrid architecture models be fully unleashed. As related technologies become open-sourced and widely adopted, we can reasonably expect the next generation of intelligent coding tools to make new leaps in both response speed and depth of context understanding.
