Rebuilding State Caching for Hybrid-Architecture LLMs: Prefix Cache Design and Scheduling
This article explains why prefix caching becomes harder in hybrid LLMs that alternate full-attention layers with linear or state-space layers, and how to rebuild the cache around that split. It covers the core difference between position-addressable attention caches and history-accumulated state caches, the three hard constraints on state reuse, and four root causes why higher hit rates fail to improve throughput: granularity mismatch, unaligned block boundaries, asymmetric swap-in/swap-out cost, and missing scheduling perspective. It then presents a layered cache design with unified blocking and dual-track snapshots, metadata-driven addressing, tiered hot/cold storage, and a prefix tree with reference counting, plus scheduling changes such as chunked prefill, first-token-priority queues, hit-rate-aware routing, and admission control. Finally, it lists measurement dimensions and an engineering rollout checklist.
1. Why Hybrid Architectures Make Prefix Caching Harder
Over the past year or two, more and more large models have moved away from a pure-attention design toward hybrid architectures that alternate full-attention layers with linear or state layers. The motivation is straightforward: attention cost in both compute and memory grows quadratically with context length, while linear structures (various linear attention variants, state space models, gated recurrence) push long-sequence complexity close to linear. That yields a lower per-step cost during decoding and a substantial reduction in cache footprint.
The problem is that these gains do not automatically carry over to the serving layer. Long-context, multi-turn workloads, such as those produced by AI coding assistants, have a few distinct traits: system prompts and repository context are carried repeatedly; each turn appends a small amount of new content after the same very long prefix; and sessions share large fragments with one another (the same codebase, the same specification text). Whether these workloads hit the cache depends almost entirely on stable reuse of the prefix cache, and hybrid architectures add extra semantic complexity at exactly that point.
The difference can be summarized in one sentence: attention caches are addressable by position, while state caches accumulate by history. Each attention entry depends only on its own position and the visible context before it, which naturally supports truncation, concatenation, and branching. A state cache is an implicit summary that is overwritten as it evolves, so any append rewrites its content. Managing both cache types with a single strategy is the root cause of the performance regressions many systems see on hybrid models.
2. How the Two Cache Types Differ and What Reuse Requires
2.1 Attention cache: addressable and truncatable
The attention cache exists as position–key/value pairs with clear semantic boundaries. Given a prefix, its entries can be reused directly in later requests; if a new request shares only part of the prefix, the cache can be safely truncated to the common length. Branching conversations (multiple continuations under the same prefix) can share one prefix cache and each maintain only its own increment.
2.2 State cache: not addressable, strongly order-dependent
The cache for linear/state layers is not a set of addressable entries but a fixed-size state that evolves token by token. It follows a recurrence: the new state is determined by the old state and the current input together. This imposes three hard constraints:
- No arbitrary truncation: keeping the state of only the first few layers cannot equivalently reconstruct the full prefix semantics.
- No arbitrary concatenation: adding or chaining two independently evolved states has no mathematical basis.
- Strict ordering: the state must be advanced in order from block boundaries; random access breaks equivalence.
2.3 Coupling effects in hybrid layers
In a hybrid model, the two cache types coexist interleaved across layers and share the same token-sequence alignment. If eviction, swap-in/swap-out, and migration use different granularities, you get a mismatch where the attention portion hits but the state portion is missing, and the only option left is a full recompute. In practice this shows up as a decent-looking hit rate while actual compute spent in the prefill stage does not drop accordingly.
3. Root Causes: Why a Higher Hit Rate Does Not Buy Throughput
First, granularity mismatch. Making cache decisions per request excludes sessions with short shared prefixes; making them per token leaves the state layer unable to locate a reusable boundary.
Second, unaligned block boundaries. The state layer can only form reusable snapshots at predefined block boundaries, so if prefix splitting shifts dynamically with request content, the snapshot never hits.
Third, asymmetric swap cost. Attention caches can be swapped in and out by page; the state cache is small but must be moved as a whole. A scheduler that treats both with the same policy generates a large amount of wasted movement.
Fourth, no scheduling perspective. Prefill is compute-intensive, and too much concurrency inside a batch stretches queueing time, which amplifies the tail of time-to-first-token. Tuning that looks only at average throughput usually makes the tail worse.
4. Redesign: A Layered Cache Built Around Hybrid State
4.1 Unified blocking with dual-track snapshots
Use a fixed-length token block as the global alignment unit, and at each block boundary persist both cache types: the attention side stores the key/value entries for that block, and the state side stores the fixed-size state snapshot as of that boundary.
block_0 | kv(block_0) | state(after block_0)block_1 | kv(block_1) | state(after block_1)...Hit rule: find the block index k of the longest common prefix,reuse kv[0..k] and state(after block_k), start prefill from block k+1
4.2 Metadata-driven addressing
Maintain lightweight metadata per block: block hash, owning session, layer-type mask, reference count, and last access time. Addressing queries only the metadata; once a hit is confirmed, the system decides which payload to move. This avoids paying a full read just to take a look.
4.3 Tiered storage and hot/cold separation
GPU memory holds only the few hottest blocks; the warm tier lives in host memory; the cold tier falls back to an external cache pool or object storage. State snapshots are small and stay resident first, while attention blocks are large and sink according to heat. When GPU memory is constrained, this sacrifices the recomputable part first rather than the state that cannot be recomputed.
4.4 Prefix tree plus reference counting
Organize multi-turn and branching conversations with a prefix tree, where shared prefix nodes are referenced by multiple branches and memory is released only when the reference count reaches zero. This raises the hit rate and avoids duplicate occupancy in branching scenarios.
5. Scheduling Coordination: Turning Cache Gains into Latency Wins
The cache is only a necessary condition; scheduling decides whether the gains materialize. Practical measures include:
- Chunked prefill: split a long prefix into blocks computed in batches, so a single request does not monopolize compute for a long stretch.
- First-token-priority queue: give higher priority to requests in their first round that have not yet produced a first token, which directly reduces the tail.
- Hit-rate-aware routing: in distributed deployments, route a request to the node that already holds the matching prefix cache, reducing cross-node movement.
- Admission and batch-width control: cap concurrency in the prefill stage so queueing inside a batch does not push time-to-first-token up.
Cross-node reuse needs additional consistency design: block metadata is maintained by a centralized index, payload can sink to a shared cache pool, nodes keep hot blocks locally, and on a miss they batch-fetch from the shared pool instead of making a round trip per block.
6. Where the Gains Come From and How to Measure Them
In replay tests on real long-context multi-turn traces, this kind of rebuild typically raises prefill throughput by several times and cuts the time-to-first-token tail by more than eighty percent. The gains hold after attaching a host-memory cache pool on the order of hundreds of gigabytes, which indicates the bottleneck has shifted from insufficient compute to cache organization and scheduling efficiency. The exact multipliers depend strongly on hardware model, model architecture, block size, and the distribution of session lengths, so fix the workload model before comparing across setups.
Recommended measurement dimensions:
- Effective hit rate: measured as prefill tokens saved divided by total prefill tokens, not as the fraction of requests that hit.
- Tail latency: p90/p99 time-to-first-token, together with a breakdown of queueing time.
- Movement overhead: bytes moved across tiers and across nodes per unit time, plus blocked duration.
- Recompute rate: the share of full recomputes caused by missing state, the metric to watch most closely in hybrid architectures.
7. Engineering Rollout Checklist
- Unify block size before optimizing anything else. Blocks that are too large lower the hit rate; blocks that are too small inflate metadata and scheduling overhead. Tune against the session-length distribution.
- State snapshots must be verifiable: write a version number and block index to storage, and run a consistency check after loading so a mismatch cannot pollute subsequent generation.
- Set eviction thresholds separately for the two cache types: keep state resident first, and sink attention blocks by heat.
- Build observability first: turn hit rate, recompute rate, movement volume, and queueing time into monitoring and alerting metrics, then iterate on the policy.
- If a container platform and a shared cache service carry the cold tier, define capacity, bandwidth, and invalidation semantics explicitly so the cold tier does not become a new source of tail latency.
8. Conclusion
The decoding gains from hybrid architectures are real, but they only turn into serving throughput and latency numbers when the addressable attention cache and the non-addressable state cache are managed together inside one blocking and scheduling framework. For teams building AI coding assistants, long-document analysis, or multi-turn conversation services, filling in the three fundamentals first, block alignment, state snapshots, and hit-rate-aware scheduling, usually pays off more than adding more hardware.
