Hybrid-Architecture LLM Agent Inference: State Cache Optimization and Throughput Gains

    Hybrid models that combine full attention with linear layers can improve long-context decoding and reduce KV cache memory, but prefix cache management becomes much more complex in multi-turn Agent workloads. This article examines the cache bottlenecks caused by heterogeneous KV and linear-layer states, describes a unified hybrid state cache design with lifecycle management, tiered and distributed storage, and predictive prefetching, and reviews reported performance results. It also discusses cloud-native deployment considerations and provides simplified scheduling pseudocode.

    As large language models are increasingly used in complex Agent scenarios such as intelligent coding and autonomous planning, model inference faces growing pressure from long context lengths and multi-turn interactions. To balance computational efficiency and long-text processing capability, mainstream models have begun to adopt hybrid architectures that combine full attention with linear layers. At the operator level, this architecture combines the global attention mechanism of Transformers with the state-passing characteristics of linear RNN-like models, aiming to achieve faster decoding and lower KV cache memory usage. However, in real complex workloads, especially multi-turn, long-context Agent interactions, prefix cache management for hybrid models is much more complex than for pure Transformer models.

    1. Cache Management Bottlenecks in Hybrid-Architecture Models

    In pure Transformer models, mainstream inference engines typically use techniques such as PagedAttention to manage KV cache. The system can easily page historical conversation KV cache to GPU memory or CPU memory and perform prefix matching and fast restoration in the next round.

    In hybrid-architecture models, however, the inference state includes not only the KV cache of attention layers but also the hidden states passed through linear layers. This creates three core challenges:

    1. State heterogeneity: KV cache is an explicit tensor mapping, while linear-layer state is an implicit recurrent tensor. The two differ significantly in data structure, lifecycle, and update logic, making it difficult for traditional inference engines to schedule them from a unified perspective.
    2. Invalidation risk in multi-turn sessions: In Agent scenarios, tool calls or environment feedback dynamically change the context. If new tokens are inserted in the middle of a multi-turn conversation, the recurrent state of the linear layer must be recomputed from the insertion point, causing large-scale invalidation of the existing prefix cache.
    3. High cross-device migration cost: When GPU memory is insufficient and state must be offloaded to CPU memory, synchronization between linear-layer state and KV cache can easily become a performance bottleneck, slowing overall system response time.

    2. A New Hybrid State Cache Design

    To address these pain points, research teams have proposed a new hybrid state cache management scheme that redesigns the coordination mechanism between KV cache and state cache, significantly improving inference efficiency for hybrid-architecture models.

    1. Unified state abstraction and lifecycle management

    The scheme first breaks down the isolation between KV cache and linear state by designing a unified state abstraction layer. The system abstracts the context of each conversation round as a “state block” that internally maintains both the KV tensors of the attention mechanism and the recurrent state of the linear layer. Through fine-grained version control, the system can accurately track state evolution paths in multi-turn Agent conversations and effectively reduce unnecessary recomputation.

    2. Heterogeneous memory and distributed storage coordination

    For GPU memory and CPU memory interaction, the scheme optimizes data movement logic. When GPU memory reaches a threshold, the system prioritizes offloading low-frequency KV cache pages to CPU memory while keeping compact linear-layer state in GPU memory to accelerate the next decoding step. Furthermore, the scheme natively supports distributed storage, allowing state cache to be pooled and deployed across CPU clusters on multiple nodes. This means that when an Agent task is scheduled to a different compute node, it does not need to re-execute prefill and can instead pull and reuse the hybrid state directly from the distributed state pool.

    3. Intelligent state routing and prefetching

    Targeting the characteristics of multi-turn Agent interaction, the system introduces a predictive prefetching mechanism. When it predicts that a historical conversation branch may be activated again, a background thread pulls the relevant hybrid state from the cross-node CPU cache pool to local GPU memory in advance, hiding network latency and enabling seamless context restoration.

    3. Performance and Engineering Validation

    According to related industry research data, when replaying real intelligent coding Agent interaction traces on high-end GPU platforms, this new cache management scheme demonstrated notable performance improvements. Compared with traditional inference engines, its prefill throughput reached up to 3.14x. At the same time, in long-context scenarios, p90 time to first token (TTFT) was reduced by up to 88.4%.

    More importantly, when the system was connected to a large-capacity cross-node CPU cache pool, such as one at the 512GiB level, the performance benefits remained significant, demonstrating strong scalability in resource-constrained or high-concurrency scenarios.

    To deploy this technology in real cloud-native environments, enterprises can build highly available large-scale inference architectures with general infrastructure from Baidu AI Cloud:

    • Elastic compute foundation: Use Baidu AI Cloud Container Engine (CCE) to implement elastic scaling of GPU nodes. When facing sudden Agent inference spikes, the container platform can quickly launch inference Pods and directly load shared hybrid state cache through distributed storage, reducing cold-start overhead.
    • High-performance storage coordination: Use Object Storage Service (BOS) or Cloud File Storage (CFS) to store model weights and historical state snapshots. When reusing state across nodes, leverage the high bandwidth of cloud-native networks to accelerate data movement within the distributed CPU cache pool.
    • End-to-end monitoring: Use Baidu AI Cloud monitoring services to collect and alert on core metrics for each inference instance, such as prefill latency, TTFT, and cache hit rate, helping developers continuously optimize state scheduling strategies.

    The following is a simplified pseudocode example of hybrid state cache scheduling logic, showing how the system handles context management for multi-turn Agent requests:

    1. class HybridStateCacheManager:
    2. def __init__(self, gpu_memory_pool, cpu_distributed_pool):
    3. self.gpu_mem = gpu_memory_pool
    4. self.cpu_pool = cpu_distributed_pool
    5. self.state_registry = {} # Maps session IDs to state blocks
    6. def handle_agent_request(self, session_id, new_tokens):
    7. # 1. Try to hit historical state from the registry
    8. state_block = self.state_registry.get(session_id)
    9. if state_block and state_block.is_valid(new_tokens):
    10. # State is valid; check whether it is in GPU memory
    11. if not state_block.in_gpu:
    12. self._prefetch_from_cpu(state_block)
    13. # Incrementally update linear-layer state and KV cache
    14. state_block.update_incremental(new_tokens)
    15. else:
    16. # State is invalid or missing; perform prefill recomputation
    17. state_block = self._recompute_prefix(new_tokens)
    18. self.state_registry[session_id] = state_block
    19. # 2. Eviction strategy when GPU memory is insufficient
    20. if self.gpu_mem.is_full():
    21. self._evict_to_cpu_pool()
    22. return state_block
    23. def _prefetch_from_cpu(self, state_block):
    24. # Asynchronously pull state from the distributed CPU cache pool to local GPU
    25. self.gpu_mem.load(state_block.kv_cache)
    26. self.gpu_mem.load(state_block.linear_state)
    27. def _evict_to_cpu_pool(self):
    28. # Find the least recently used state block for eviction
    29. lru_block = self.gpu_mem.get_lru_block()
    30. self.cpu_pool.store(lru_block)

    4. Conclusion and Outlook

    By combining the advantages of different operators, hybrid-architecture models provide a promising path for deploying large models in long-context and Agent scenarios. However, hardware architecture evolution must be complemented by inference engine software stack design. The new hybrid state cache scheme successfully overcomes the bottlenecks of traditional cache management by reconstructing state lifecycle management and introducing distributed storage and cross-node reuse, delivering multiple times higher throughput.

    In the future, as Agent applications push context length requirements toward millions of tokens or more, inference system design will increasingly depend on efficient coordination of heterogeneous memory. When selecting or building inference frameworks, developers should focus on the flexibility of hybrid state management and make full use of elastic storage and compute scheduling capabilities from cloud-native platforms such as Baidu AI Cloud to build AI infrastructure that combines high performance with low cost.