Hybrid Architecture KV Cache Redesign: A 3x Jump in Prefill Throughput
This article explains why conventional KV cache management breaks down in hybrid architectures that interleave full-attention layers with linear state layers, and how to redesign the cache to multiply prefill throughput. It covers the three structural mismatches behind the bottleneck, a layered and chunk-addressable cache design with page-level cache and segment-level state, chunked prefill with rollback to the last valid segment, memory layout for write-heavy state, the scheduling changes required to realize the gains, capacity planning guidance, and a practical implementation checklist for long-context, multi-turn agent workloads.
1. Background: Hybrid Architectures Are Mainstream, and the Cache Became the New Bottleneck
Over the past year, mainstream large language models have increasingly adopted hybrid architectures that interleave full-attention layers with linear state layers. The motivation is straightforward: full-attention layers preserve precise long-range retrieval, while linear state layers (state space models and linear attention variants) compress the key-value cache that grows with sequence length into a fixed-size state tensor. This substantially reduces memory usage during decoding and improves memory access efficiency per decoding step.
Once these models are put to work in agent scenarios, however, the engineering focus shifts. Agent workloads are characterized by very long system prompts and tool definitions, context that keeps growing across multiple tool-calling turns, and a high degree of prefix repetition within the same session. As a result, the bottleneck in an inference cluster moves from decoding back to prefill: after every tool response, the new content has to be run through a forward pass together with the entire history.
The models that already ship with hybrid architectures are only technical background here. Rather than focusing on specific model names, this article abstracts the properties these architectures share and addresses a general question: under a hybrid architecture, how should the state cache be redesigned so that prefill throughput improves by several times?
2. Why Conventional KV Cache Thinking Fails in Hybrid Architectures
Cache management for conventional full-attention models is already mature: the cache grows one record per token, can be split into blocks by a paging mechanism, swapped in and out on demand, and reused across requests by prefix hashing. This system works because of one premise: the cache is a linear function of sequence length, and every position is independent of the others.
Hybrid architectures break both premises and introduce three structural mismatches:
Inconsistent state granularity. In a full-attention layer, the cache is one record per token; in a linear layer, the state is an entire sequence compressed into a fixed-length tensor. Managing both with the same paging and addressing logic means either the linear state is copied in full over and over, or the full-attention cache is forced to reserve space for the maximum length. Both waste space badly.
Inconsistent update semantics. Appending a token adds one record to the full-attention cache and leaves history untouched; the linear state must be updated recursively in place, overwriting the old state. Cache pages therefore stop being append-only immutable blocks and become stateful, live objects.
Inconsistent reuse boundaries. Prefix cache reuse assumes that an identical prefix produces an identical cache. Full-attention layers satisfy this naturally. Linear states are also reusable under specific initial-value conditions, but once a different tool result is inserted midway, every subsequent state is invalidated, and the invalidation range is wider than for full attention.
Ignore these three points and apply a “unified paging plus whole-block swap in and out” implementation, and you get a large amount of avoidable state movement. Prefill time ends up dominated by memory copies rather than matrix math.
3. Core Redesign: Layered, Chunked, and Addressable
A practical redesign can be summarized in three moves.
3.1 State layering: put the two cache types in separate management domains
Model the cache as two tiers that cooperate but are addressed independently:
- Page cache: holds key-value records for full-attention layers, paged by a fixed number of tokens, immutable, hashable, and shareable across requests.
- Segment state: holds the fixed-length state of linear layers, with a prefill chunk as its lifecycle unit, mutable, versioned, and not shared across requests by default.
A sketch of the data structures (illustrating layout only, not a specific framework API):
@dataclassclass PageBlock:hash_key: bytes # Hash of the prefix content, used for cross-request reusekv_slots: Tensor # [num_layers_full, page_tokens, kv_dim]ref_count: int@dataclassclass SegmentState:seg_id: intstate_slots: Tensor # [num_layers_linear, state_dim]version: int # Incremented on every recursive updateparent_seg: int | None # Points to the previous active segment, enabling rollback
The key benefit: the page cache keeps enjoying a high prefix hit rate, while segment state avoids the cost of copying a large tensor in full just to reuse it.
3.2 Chunked prefill: split a long prompt into segments whose state can be advanced recursively
The largest source of prefill throughput gains is dropping the constraint that a full long context must be processed in one shot. Split the input into fixed-size chunks and run the forward pass chunk by chunk. After each chunk, advance the linear layer state and persist it as a new segment state, and write that chunk’s full-attention keys and values into the page cache.
This has three direct effects. First, a fixed chunk size means stable operator shapes, which makes it easier to saturate compute. Second, chunks can form a pipeline so that computation overlaps with state write-back. Third, when a tool result invalidates state, you only roll back to the most recent valid segment and recompute from there instead of restarting at the beginning of the session.
chunk_0 -> [prefill] -> state_0, pages_0chunk_1 -> [prefill] -> state_1, pages_1 (depends on state_0)chunk_2 -> [prefill] -> state_2, pages_2 (depends on state_1)tool result changed -> drop all segments from state_2 onward, resume from state_1
3.3 Cache page layout: rearrange memory for state that is write-heavy and read-light
Segment state has the opposite access pattern from the page cache: frequent writes, concentrated reads, fixed size. The layout should therefore do three things: place state tensors in contiguous memory aligned by layer so that a recursive update never crosses pages; reserve a fixed watermark for the state pool and preallocate instead of allocating dynamically; and use double buffering for state versions, writing a new version and atomically switching the pointer so concurrent inference never reads a partially updated state.
4. Required Changes on the Scheduling Side
The cache redesign has to change together with batch scheduling, or scheduler jitter will eat the gains.
- Prefix-aware routing: route requests carrying the same long prefix to the same instance to raise the page cache hit rate and cut repeated prefill.
- Chunking coordinated with continuous batching: use the chunk as the minimum scheduling unit for inserting new requests instead of waiting for a long request to finish, which flattens the long-tail latency caused by prefill.
- State affinity constraints: keep consecutive turns of a session on the instance holding its segment state; when crossing instances, transfer only the fixed-length state rather than the full key-value cache, reducing transfer volume by an order of magnitude.
- Separate watermark and eviction policies: evict page cache entries by reference count and hash popularity, and evict segment states by session activity and version chain, so the two do not interfere.
5. Where the Gains Come From and How to Plan Capacity
Overall, a several-fold prefill throughput gain does not come from a single trick but from eliminating three kinds of waste at once: repeated computation of repeated prefixes is removed by page-level reuse; shape jitter over long contexts is removed by chunking; and whole-state movement is removed by layering plus double buffering. The exact multiple depends heavily on the ratio of hybrid layers in the model, chunk size, the distribution of context lengths, and the hit rate, so benchmark against your own workload rather than copying someone else’s numbers.
For capacity planning, watch the following: the state pool is roughly the number of concurrently active segments times the per-layer state size times the number of linear layers times the double-buffering factor; size the page cache by working backward from the target hit rate to a total token capacity; and reserve separate bandwidth for state write-back. In a general-purpose compute environment such as Baidu AI Cloud, you can combine container platforms for instance orchestration, object storage for persisting session state, and monitoring and alerting services to track cache hit rate and prefill latency percentiles, closing the tuning loop.
6. Implementation Checklist
- Have you split the full-attention cache and the linear state into two independently addressed systems?
- Does prefill run in fixed-size chunks and support rollback to the most recent valid segment?
- Are state updates switched atomically so concurrent requests never observe an intermediate state?
- Does the scheduler support prefix awareness and session affinity?
- Are you running continuous load tests against real agent workloads (long system prompts, multi-turn tool calls)?
