Reshaping KV Cache Management for Hybrid Architecture LLMs Under Agent Workloads

    The evolution of Large Language Models (LLMs) is increasingly leaning towards hybrid architectures that combine traditional attention mechanisms with linear layers to balance performance and decoding efficiency. However, this hybrid approach introduces complex KV cache management challenges, particularly under agentic workloads characterized by multi-turn interactions and extensive prefix reuse. This article explores the systematic issues of cache failures in hybrid models and introduces FlashStates—a state-aware caching architecture. By decoupling position-dependent KV caches from position-independent state caches and optimizing prefill scheduling, FlashStates significantly enhances throughput and reduces latency. The article also covers its distributed extension, hardware adaptation on platforms like the NVIDIA B200, and key considerations for production deployment.

    Background: The Rise of Hybrid Architectures and New Cache Management Challenges

    The architectural evolution of Large Language Models (LLMs) is showing a significant divergence. On one hand, pure Transformer architectures excel at long-range dependency modeling through global attention mechanisms. However, during the decoding phase, they must access the entire historical Key-Value (KV) cache for each generated token. This causes memory bandwidth pressure to grow linearly with context length, severely restricting decoding speed. On the other hand, new-generation architectures represented by linear attention replace or partially replace traditional attention computation with linear layers, achieving O(1) spatial complexity for the KV cache during decoding and significantly boosting throughput.

    Recognizing these complementary advantages, the industry has widely adopted the “full attention + linear layer” hybrid architecture design paradigm. This design retains the attention mechanism’s ability to accurately capture key information while utilizing linear layers to process redundant information in long sequences, striking a delicate balance between model quality and decoding efficiency. However, this architectural dividend comes at a cost—it introduces systematic challenges for inference infrastructure cache management that are far more intractable than those of pure Transformers.

    In pure Transformer architectures, KV cache management is relatively straightforward: the KV tensors for each request can be stored sequentially by sequence position, and prefix sharing can be implemented based on simple token sequence matching. In hybrid architectures, however, linear layers typically maintain additional State Cache—such as recurrent state vectors and feature statistics. These states are generated and consumed entirely differently from the KV cache and have more complex dependencies on sequence positions. This means cache system design must simultaneously consider the lifecycle, access patterns, and reuse value of two heterogeneous data structures, drastically increasing complexity.

    Agent Workloads: The Epicenter of Prefix Cache Failures

    To understand the elegance of the FlashStates design, one must first understand the workload characteristics it aims to solve. Agent applications, represented by intelligent coding tools, have workload patterns fundamentally different from traditional single-turn dialogues or simple document Q&A.

    During a complete Agent task execution cycle, the model undergoes multiple rounds of tool calls and reasoning iterations. Assuming an average code repository task trajectory includes 12 interaction rounds, processing an average context growth of about 4,000 tokens per round, the final context length could accumulate to 50,000 or more tokens. More critically, there is massive prefix reuse between these rounds—subsequent rounds usually append new system instructions or tool results to the context generated in previous rounds.

    For pure Transformer architectures, prefix caching can quickly locate and reuse data based on token sequence hashes. But for hybrid architectures, the situation is entirely different: due to the existence of linear layer states, the same prefix token sequence will produce different intermediate state tensors under different state initialization conditions. This means that even if a client sends an identical text prefix, the server cannot assert whether the corresponding KV cache and state cache can be directly reused.

    Further analysis reveals a more insidious cache failure scenario in Agent workloads: sliding and truncation of the context window. When the context length exceeds the window limit defined during model training, agents typically adopt a sliding window strategy, discarding the earliest tokens. For pure Transformers, this only involves an index offset in the KV cache array; but for linear layer states, window sliding means the state must be recomputed from an intermediate checkpoint, or complex state rollback operations must be executed. The cost of such operations can be much higher than recomputing a single forward pass.

    Looking at actual data, when replaying real Agent trajectories from an intelligent coding tool, it was found that directly applying the traditional “prefix hash + shared cache” scheme results in a drop of over 40% in effective cache hit rate for hybrid models compared to pure Transformers. The prefabrication phase computation amplification caused by this fractured access pattern directly leads to prefill throughput collapse and a spike in Time to First Token (TTFT).

    FlashStates Core Insight: From KV-Oriented to State-Aware

    The starting point of FlashStates is a re-examination of the root causes of cache failures in hybrid architectures. Traditional cache systems treat the KV cache as the sole state object requiring management, whereas FlashStates proposes a critical perspective: the inference state of hybrid architecture models should be decomposed into two dimensions: position-dependent and position-independent.

    The position-dependent state is the standard KV cache, whose validity is determined entirely by the token content of the sequence prefix. The position-independent state consists of the intermediate statistics maintained by linear layers, such as running means or variances of certain normalization layers, or latent variables in state-space models. The validity of these states depends on the evolutionary path of the entire sequence, rather than simple token matching. Confusing the lifecycles of these two types of states is the root cause of erroneous cache reuse decisions.

    Based on this understanding, FlashStates designed an architecture of heterogeneous state separated storage. The KV cache still uses contiguous VRAM allocation to support high-speed attention computation, while the linear layer’s state cache uses an independent, logically traceable tensor storage structure, where each state is accompanied by metadata tags describing its dependency history. This separated design allows the scheduler to independently decide the reuse strategies for both types of caches, without having to give up exploring KV cache reuse opportunities due to the uncertainty of linear states.

    Furthermore, FlashStates introduces a lightweight incremental tagging mechanism for cache consistency validation. Whenever the context content changes, the system does not need to recompute the hash of the entire sequence. Instead, it maintains a version chain based on a token-granularity operation log, determining in O(1) time whether a historical state can be safely loaded. Compared to the traditional “full prefix hash comparison” approach, this reduces verification overhead by over 60% in long-context scenarios.

    Prefill Acceleration: Coordinated Design of Scheduling and Storage

    The main bottleneck in the prefill phase is that, faced with long sequence inputs, it requires serial computation of attention and linear transformations for each layer, and all intermediate results must be retained for consumption during the decoding phase. FlashStates achieves a leap in prefill throughput through three levels of coordinated optimization.

    Level 1: Request-level scheduling optimization. Under the Continuous Batching framework, FlashStates decouples the probabilistic waiting queues for prefill and decode requests. When it detects that a request’s context prefix has a cached state, the system prioritizes moving it into the compute pipeline and utilizes the speculative nature of state sharing to balance the computation load of the missed tail sequence across the idle compute capacity of multiple devices. The essence of this design level is to approach the hardware utilization ceiling through software scheduling.

    Level 2: Compute and cache overlap. At the GPU kernel execution level, FlashStates achieves the overlapping execution of KV cache writeback and the next linear layer computation through fine-grained compute graph partitioning. In traditional schemes, cache writeback is often treated as a synchronization point at the computation boundary, where the GPU must wait for data to be persisted before releasing memory resources. FlashStates leverages the natural asynchronicity between linear layer computation and attention computation in hybrid architectures, executing cache writeback as a low-priority background stream, thereby shortening the end-to-end latency of the prefill phase.

    Level 3: Cross-request state composition. Moving towards higher concurrency scenarios, FlashStates supports splicing local state fragments owned by multiple historical requests into a new complete state, provided semantic equivalence is guaranteed. This mechanism is similar to View Materialization in databases, allowing the system to construct a starting state for a new request from multiple related but not fully overlapping historical interactions, without forcing a complete prefix match. This design is particularly effective for Agent scenarios, as it allows the system to flexibly utilize caches from different branch turns within the same session.

    The synergistic effects of these three levels were fully validated when replaying real Agent trajectories on NVIDIA B200 GPUs: FlashStates’ peak prefill throughput reached 3.14 times that of the baseline system, and p90 TTFT was reduced by up to 88.4%. It is worth noting that the performance gains are not evenly distributed—requests with context lengths exceeding 16k benefit the most, as the absolute gain from cache reuse is greater in long-sequence scenarios.

    Distributed Extension: From Single-Node Cache to Cross-Node State Pools

    Single-node optimization is only one aspect. Real production environment deployments, especially cloud services oriented towards online inference, typically face the dual challenges of large-scale concurrency and high availability. FlashStates was designed from its inception with the boundary of horizontal scaling capabilities in mind.

    After integrating a high-capacity remote cache pool, the benefits were not offset by network overhead; instead, they further expanded as the cache hit rate increased. Researchers connected the system with industry-mainstream distributed cache middleware and persisted cache data into remote storage pools. Because FlashStates’ separated state design naturally fits distributed key-value semantics, the KV cache and linear state cache can be independently addressed, greatly simplifying the implementation complexity of distributed cache sharding and replica consistency protocols.

    Further observation reveals that in remote cache hit scenarios, prefill throughput can still maintain a high multiplier gain compared to pure local computation. This conclusion has significant engineering implications: it demonstrates that by hierarchically orchestrating the storage of cold data (historical task caches) and hot data (current active request caches), the system can build a state cache system with both large capacity and high throughput, providing near-stateless elastic recovery capabilities for long-running Agent applications.

    Hardware Adaptation and Compute Efficiency: Beyond B200

    Choosing the B200 as the validation platform is representative of the industry. Its 4th-generation Tensor Core’s support for FP8/FP16 mixed precision can leverage the differentiated characteristics of numerical precision requirements between the attention layer and the linear layer in hybrid architecture models. The adjustment of operator fusion strategies in FlashStates allows the FP8 compute pipeline to be more broadly applied to matrix multiplication in linear layers, without affecting the precision sensitivity of the attention heads. This adaptability, combining flexibility and aggregate efficiency, means the design concept can also be migrated to other GPU models or dedicated inference chips.

    From the perspective of compute efficiency, the original intent of hybrid architectures was to reduce the compute overhead per generated token during the decoding phase. The gains from FlashStates further amplify this architectural advantage—since the computation volume in the prefabrication phase is effectively compressed, the average compute utilization of the entire card under continuous mixed workloads (interleaved prefill and decode) can be increased by more than 2x, with power consumption growing by only about 15%. For cloud service providers pursuing extreme cost-per-unit throughput, this means a significant increase in the number of concurrent active sessions that can be supported under the same power budget.

    Production Practices and Future Outlook

    While FlashStates has demonstrated exciting experimental results, deploying it to production environments still requires attention to several design points.

    First is the tuning of cache strategies. The KV cache and state cache occupy different proportions of storage space, and their reasonable capacity ratio and eviction strategies largely depend on the request length distribution of the business. For scenarios with a high proportion of short requests, state cache eviction can be more aggressive; whereas in long-session Agent scenarios, sufficient redundancy must be reserved for the state cache to handle context branch switching.

    Second is the challenge of multi-model version compatibility. Model upgrades in inference services cause old caches to become invalid. It is recommended to explicitly include model version identifiers in state metadata and achieve dynamic coexistence of old and new data through versioned cache structures, maintaining business continuity during model upgrade transition periods.

    Finally, there is the restructuring of the observability system. After the complexity of the cache system increases, the hit rate is no longer the sole health metric. During actual deployment, operations teams should simultaneously monitor sub-metrics such as state splicing success rate, cross-node cache transfer latency, and scheduling delays caused by additional computation carried by the cache. This data will guide the continuous optimization of cache warming strategies.

    Looking ahead, as hybrid architecture models further penetrate complex inference workloads like Agents and multimodality, cache management is no longer just a contest of storage efficiency and speed; it has become a key watershed for whether the overall architecture design of inference services can remain elegant. The insight from FlashStates is that every layer of abstraction in an inference system must be deeply aligned with the physical semantics of the model architecture. Only then can hardware dividends truly be transformed into experiential advantages on the business side.