State Cache Refactoring and Prefill Acceleration for Hybrid-Architecture LLMs
This article explains why cache management becomes harder in hybrid LLM architectures that combine full attention layers with linear layers such as linear attention, gated recurrence, and state space models. It contrasts token-level KV caches with fixed-size recurrent states, introduces a unified hybrid state cache abstraction, and details prefix fingerprinting, prefill scheduling weighted by state recomputation cost, tiered storage, and consistency controls. Engineering guidance and an evaluation method are included to help teams improve prefill throughput and tail latency in multi-turn, long-context workloads.
1. Background: Why Cache Management Gets Harder When Hybrid Architectures Go Mainstream
Over the past year, open-source LLM architectures have shifted noticeably. So-called “linear layers”—represented by linear attention, gated recurrence units, and state space models—are now stacked alongside standard full attention layers, forming a hybrid “full attention + linear layers” design. The motivation is straightforward: reduce computational complexity during decoding, shrink memory footprint, and achieve more stable throughput on long sequences.
However, as workloads move from single-turn question answering to multi-turn, long-context scenarios such as coding agents that frequently reuse prefixes, cache management in hybrid architectures becomes significantly more complex. The reason is that full attention caches grow along the token dimension as key-value pairs, while linear layer caches are fixed-size “states” that are recursively updated as the sequence advances. The two cache types differ completely in lifecycle, reuse conditions, and migration cost, so traditional KV-cache-centric management strategies cannot be applied directly.
This article takes a general technical perspective and abstracts a practical design methodology for hybrid state caching, covering cache abstraction, prefix matching, scheduling, tiered storage, and evaluation.
2. Cache Characteristics of Hybrid Architectures: Two State Types, Two Rule Sets
2.1 Full Attention Layers: Concatenable, Truncatable KV Caches
Full attention caches accumulate per token and naturally support prefix sharing: if the prefix tokens match exactly, the cache can be reused directly; if a branch occurs, computation only needs to be appended after the branch point. The main cost is that memory usage grows linearly with context length.
2.2 Linear Layers: Fixed-Size Recurrent States That Cannot Be Freely Concatenated
Linear attention and state space layers use fixed-size state matrices or vectors updated recursively. They have two key properties:
- The state is a “compressed result of history” and cannot be truncated per token and still used for correct inference like a KV cache.
- State updates are tightly bound to the specific input; any prefix difference makes the state unreusable.
2.3 The Core Conflict After Mixing
In a hybrid model, a single prefix reuse must satisfy both conditions at once: the full attention cache is reused with token-level alignment, and the linear state is reused as a whole only for a “fully identical prefix.” If even one token in the prefix differs, the linear state must be recomputed from the branch point, which invalidates optimizations that appear to hit the prefix.
Illustrative pseudocode:
# Hybrid cache reuse check (illustrative)def can_reuse(attn_cache, ssm_state, prefix_tokens, cached_prefix):if prefix_tokens != cached_prefix:return False # Linear states cannot be partially reusedreturn attn_cache.matches(cached_prefix)
3. Design Goal: Treat “State” as a First-Class Cache Object
Traditional approaches equate the cache with key-value pairs. Under hybrid architectures, this needs to be upgraded to a “hybrid state cache” abstraction:
- Unified naming: maintain a combined handle of “attention cache + linear state” for each request.
- Unified lifecycle: both share the same prefix identifier to avoid one hitting while the other is invalidated.
- Unified migration: when moving across nodes or storage tiers, serialize both object types as a single unit.
- Unified eviction: base eviction on “reuse value” rather than memory footprint alone.
4. Key Mechanisms
4.1 Prefix Identification and Branch Point Location
Compute a prefix fingerprint for each request and locate the longest matching prefix on a fingerprint tree. After the branch point, the attention cache can be appended incrementally, while the linear state must be recomputed entirely. Therefore, the scheduler should prefer reuse paths where the branch point is as late as possible.
4.2 Prefill Scheduling: Weighting by State Recomputation Cost
Prefill batching should consider not only token count but also the amount of state recomputation. The cost function can be abstracted as:
cost = α * missed_tokens + β * layers_to_recompute * state_size
The scheduler uses this to order and batch requests, preventing a few long-branch requests from slowing down the entire batch.
4.3 Tiered Caching: GPU Memory, Host Memory, and Distributed Storage
Hybrid states can be placed in tiers: hot data stays in GPU memory, warm data goes to host memory, and cold data is pushed down to distributed or object storage. Because linear states are fixed-size and relatively small, cross-tier migration bandwidth pressure is usually lower than for long KV caches, leaving room for high-capacity scaling.
4.4 Consistency and Concurrency
For multi-replica inference, ensure that the hybrid state version corresponding to the same prefix fingerprint stays consistent. It is recommended to introduce version numbers and read-only snapshots to prevent concurrent updates from polluting recurrent states.
5. Engineering Implementation Notes
- Interface layer: design cache handles as serializable objects that hide the differences between the two state types.
- Monitoring layer: track attention cache hit rate and linear state reuse rate separately to locate bottlenecks.
- Capacity layer: use a combination of general-purpose object storage and distributed caching for cold states, tiered by access heat.
- Load testing layer: replay real multi-turn traces, focusing on p90 time-to-first-token and prefill throughput.
6. Sources of Gains and Evaluation Method
In replays of real agent workloads, optimization gains come mainly from three areas: reducing linear state recomputation, improving the completeness of prefix hits, and expanding reusable capacity through tiered caching. For evaluation, keep the model and hardware fixed and compare three configurations—“KV cache reuse only,” “whole hybrid state reuse,” and “hybrid state + tiered expansion”—observing changes in prefill throughput and tail latency to quantify the contribution of each optimization layer.
7. Conclusion
The shift brought by hybrid architectures is not simply “smaller caches,” but an upgrade of the cache object from a single key-value pair to a composite of “key-value + recurrent state.” Whoever manages state as a first-class cache object will achieve stable prefill throughput and lower tail latency in multi-turn, long-context workloads. For teams building coding assistants, long-document analysis systems, and multi-turn dialogue systems, this design approach offers direct reference value.
