Redesigning State Caching and Accelerating Prefill for Hybrid Architecture LLMs

    Large Language Models (LLMs) increasingly adopt hybrid architectures combining full attention and linear layers to balance long-range dependency modeling with linear complexity. While this reduces KV cache size and decoding costs, it significantly complicates inference system cache management, particularly for prefix caching. This article explores the challenges of managing heterogeneous states (KV cache and recurrent states) in hybrid models and introduces a redesigned caching framework. By implementing unified indexing, a cost-driven reuse model, tiered storage with asynchronous prefetching, and cross-node state migration, this approach achieves up to 3.14x prefill throughput and reduces p90 Time-To-First-Token (TTFT) by 88.4%. We also provide practical engineering recommendations for deploying hybrid architecture models in production.

    Redesigning State Caching and Accelerating Prefill for Hybrid Architecture LLMs

    I. Background: Why Hybrid Architectures Are Becoming Mainstream

    In recent years, a new generation of Large Language Models (LLMs) has widely adopted hybrid architectures that alternately stack “full attention layers + linear layers.” Full attention layers handle precise long-range dependency modeling, while linear layers (such as linear attention and state space model variants) process sequences with linear complexity and a fixed-size state. This combination offers direct benefits:

    • Faster Decoding: Linear layers do not need to maintain a KV cache that grows with the context, keeping single-step decoding overhead constant.
    • Smaller KV Cache Footprint: Only a few full attention layers need to save KV pairs, significantly reducing VRAM usage.
    • Lower Long-Context Costs: The longer the context, the more pronounced the inference cost advantage of hybrid architectures over pure attention models.

    As a result, hybrid architecture models are rapidly gaining traction in scenarios requiring ultra-long contexts, such as AI coding assistants and automated agents. However, the flip side is that the cache management complexity for inference systems is significantly elevated.

    II. Problem Analysis: Why Prefix Caching is Hard for Hybrid Models

    In workloads like coding agents, requests exhibit two distinct characteristics: multi-turn conversations continuously append to the context, and adjacent requests share large amounts of common prefixes (system prompts, tool definitions, historical code snippets, etc.). Prefix caching leverages this by reusing previously computed intermediate states to avoid redundant prefilling.

    For pure attention models, prefix caching only needs to manage the KV cache, for which mature industry solutions exist: hash indexing by token block and skipping computation upon a hit. However, hybrid architecture models simultaneously maintain two types of states:

    1. Attention Layer KV Cache: Splittable by token granularity and partially reusable.
    2. Linear Layer Recurrent State: Essentially a “compressed summary” of the entire prefix. It is unsplittable and can only be computed sequentially from the beginning.

    This introduces several棘手 challenges:

    • State Alignment Dilemma: The KV cache can be reused at any token boundary, whereas the linear layer state can only be reused when aligned with a checkpoint computed exactly to that position. The reuse granularities of the two are inherently inconsistent.
    • Checkpoint Placement Strategy: Although the linear layer state is small, the timing of saving it requires trade-offs—saving too frequently wastes storage, while saving too sparsely results in low hit rates.
    • Coordinated Cache Eviction: When VRAM is tight and caches must be evicted, the eviction decisions for KV blocks and state checkpoints must be coordinated. Otherwise, invalid space usage occurs (e.g., “KV exists but state is lost” or vice versa).
    • State Migration in Distributed Scenarios: In multi-node inference clusters, cross-node reuse of mixed states involves consistency scheduling of two types of heterogeneous data, which is far more complex than single KV transfers.

    Traditional inference engines are mostly designed around pure attention models. Applying them directly to hybrid architectures means either reusing only the KV cache while recomputing the linear state, or abandoning prefix caching altogether, preventing prefill throughput from reaching its full potential.

    III. Design Approach: A Cache Management Framework for Mixed States

    To address these issues, an effective solution is to redesign the cache subsystem by treating mixed states as first-class citizens. The core philosophy can be summarized in four layers:

    3.1 State Layering and Unified Indexing

    Incorporate both the KV cache and the linear layer state into a unified cache management layer, but use different indexing granularities:

    • The KV cache is organized into fixed-size token blocks, supporting fine-grained partial hits.
    • The linear layer state is saved at preset checkpoint boundaries. The checkpoint interval can be dynamically adjusted based on workload characteristics (e.g., prioritizing checkpoints at natural boundaries like conversation turns or tool call return points).

    The unified indexing layer exposes a query interface that “returns the longest reusable state for a given prefix.” Internally, it simultaneously matches the KV block chain and the nearest valid checkpoint, returning the optimal combination of the two.

    3.2 Cost Model for Reuse Decisions

    Not all cache hits are worth reusing. Assuming the remaining unmatched prefix length is L, the cost of recomputing the prefill must be compared against the transfer cost of loading the remote cache:

    1. reuse_benefit = compute_cost(L) - transfer_cost(kv_blocks + state)

    Reuse is only executed if the benefit is positive. For the linear layer state, reuse is almost always worthwhile due to its small size and fast transfer. For large segments of the KV cache, more cautious cost evaluation is required in cross-node scenarios.

    3.3 Tiered Storage and Asynchronous Prefetching

    Mixed states can be distributed across multi-level storage: GPU VRAM, CPU RAM, and remote distributed caches. The system automatically promotes or demotes data based on access heat. During the request scheduling phase, it performs asynchronous prefetching of states likely to be hit, hiding transfer latency under queuing and scheduling overhead. Experiments show that even when integrating hundreds of GiB of CPU-side cache, prefill benefits remain significant due to the small size of the linear layer state and the pipelineable nature of KV block transfers.

    3.4 Cross-Node Mixed State Reuse

    In multi-node clusters, the framework needs to maintain a global state directory recording which nodes hold the states for each prefix. The scheduler prioritizes routing requests to the node holding the longest matching prefix (cache affinity scheduling). If it cannot hit locally, it pulls the remote state via high-speed interconnects. This extends state reuse from a single machine to the entire cluster, which is particularly critical for long-session agent workloads.

    IV. Experimental Results: Prefill Throughput and TTFT

    The research team conducted replay tests based on real coding agent session traces, comparing this framework against widely used open-source inference engines on the latest generation of data center GPUs:

    • Prefill Throughput: Reached up to 3.14x that of the baseline solution. The improvement primarily stems from linear state reuse avoiding massive redundant computation, along with scheduling optimizations under cache hits.
    • Time-To-First-Token (TTFT): The p90 percentile decreased by up to 88.4%, significantly improving the response experience for interactive coding agents.
    • Scalability: After integrating large-capacity CPU-side caches, the hit rate increased further, and cross-node reuse maintained stable benefits in distributed deployments.

    Notably, the longer the context and the more turns there are, the greater the relative benefit of mixed state reuse—which perfectly aligns with the development trend of agent workloads.

    V. Engineering Deployment Recommendations

    For teams planning to deploy hybrid architecture models in production environments, the following points are worth considering:

    1. Profile Workload Features First: Analyze the prefix overlap rate and session length distribution between requests to determine checkpoint strategies and cache capacity ratios.
    2. Prioritize Linear State Reuse: Its small size and guaranteed ROI make it the optimization point with the highest cost-effectiveness.
    3. Link Cache with Scheduling: Cache affinity scheduling is often more effective than simply expanding cache capacity.
    4. Leverage General Cloud Platform Capabilities: When deploying in the cloud, container platforms can be used for elastic scaling, while object storage or distributed memory storage can carry cold states. Coupled with logging services and monitoring alerts, teams can continuously observe cache hit rates and TTFT metrics, forming an iterative optimization loop. For example, building inference clusters on cloud platforms like Baidu AI Cloud can provide elastic state caching capabilities at lower operational costs.

    VI. Conclusion and Outlook

    Hybrid architecture models trade smaller cache sizes and faster decoding for state management complexity, and prefix caching is the key to resolving this contradiction. By unifying the management of KV cache and linear layer states, driving reuse decisions with a cost model, and extending reuse to cross-node clusters, both prefill throughput and TTFT can achieve order-of-magnitude improvements. As agent-based applications continue to stretch context lengths, cache design tailored for mixed states will become one of the core competencies of inference systems, warranting deep research and practice from every inference engine engineer.