Redesigning State Caching for Hybrid Architectures: Up to 3x Higher Prefill Throughput
This article explains why conventional KV Cache reuse falls short for hybrid architectures that alternate full attention and linear layers, and how a unified state cache addresses the mismatch. It covers unified addressing and checkpointing, tiered placement across GPU memory, host memory, and remote storage, lifecycle and eviction scoring, and version isolation, along with sample pseudocode. Reported results show up to roughly 3x prefill throughput and nearly 90% lower p90 time-to-first-token on replayed coding agent traces, followed by a staged adoption path for inference services.
1. Why Hybrid Architectures Dominate Long-Context Workloads
Recent model designs widely adopt a hybrid architecture that alternates full attention layers with linear layers. The motivation is straightforward: full attention layers handle precise global information retrieval, while linear layers (such as state space models and linear attention) carry long-range information at a constant state cost. Combining the two means decoding compute no longer grows linearly with context length, and KV Cache memory usage drops significantly.
Problems surface when the workload shifts from single-turn question answering to multi-turn, long-context coding agents. A typical coding tool trajectory involves many tool calls, file reads, code write-backs, and failed retries. Context length easily reaches hundreds of thousands of tokens, and adjacent turns share a large reusable common prefix. At that point the bottleneck is no longer decoding but prefill: every request must recompute the entire historical prefix.
2. Why Pure Transformer Prefix Caching Is Not Enough
The conventional approach centers on KV Cache reuse: persist the key and value tensors of the common prefix and skip redundant computation on a hit. This mechanism is mature for pure attention models, but on hybrid architectures it shows three mismatches.
First, the state shapes differ. An attention layer’s cache is a history sequence that grows with length, while a linear layer’s cache is a fixed-size state snapshot. The former can be sliced at token granularity and reused for any aligned prefix; the latter is a tensor updated repeatedly in place and cannot be split by prefix in any simple way.
Second, the update semantics differ. A linear state is the result of sequential recurrence and is equivalent only when advanced from the same initial state over the same token sequence. If two requests share a prefix but diverge at different points, reusing the whole state directly introduces drift.
Third, lifecycle management is missing. If the eviction policy only manages KV, linear states may be evicted too early or stay resident too long, wasting GPU memory and collapsing the hit rate.
3. Design of a Unified State Cache
The solution is to abstract both cache types into the same kind of addressable, versioned, and migratable state object, managed by a unified tiered cache.
Unified addressing and chunking. Introduce fixed-stride checkpoints for the linear state. Each checkpoint, together with its corresponding prefix length, model version, and parallel sharding scheme, forms the cache key. On a hit, restore from the nearest checkpoint and advance a few tokens sequentially to align.
Tiered placement. The GPU memory tier holds the hottest checkpoints and recent KV blocks; the host memory tier provides much larger capacity; a remote distributed storage tier handles cross-node sharing. Tiers are connected by asynchronous prefetch and background write-back so the main compute path is not blocked.
Lifecycle and eviction. Replace plain least-recently-used with a combined score of prefix reference count and reuse interval, so long-tail common prefixes are not pushed out by frequent short sessions.
Consistency and version isolation. The cache key must include the model weight version and quantization configuration to avoid silent errors from mixing.
Illustrative pseudocode:
def prefill(request, cache):key = cache.key(prefix=request.prefix, model_ver=VER, tp_size=TP)hit = cache.lookup(key) # returns (kv_blocks, state_ckpt, pos)if hit is None:kv, state = model.init_state()pos = 0else:kv, state, pos = hitkv, state = model.forward(request.tokens[pos:], kv, state)cache.store(key, kv, state, checkpoint_stride=256)return kv, state
4. Where the Gains Come From
In an experiment replaying real coding agent traces on a single GPU, the unified state cache reached up to roughly 3x prefill throughput over a baseline with only basic prefix reuse, and p90 time-to-first-token dropped by nearly 90%. The gains come from three places: common prefixes are reused across turns and across sessions, cutting redundant computation; linear states are restored from checkpoints instead of being recomputed in full; and tiering plus prefetch overlaps data movement with computation, hiding access latency. After adding a host memory cache of hundreds of gigabytes, the gains held, indicating the bottleneck has shifted from compute to cache capacity and scheduling quality.
5. Adoption Recommendations
To apply this in your own inference service, proceed in order: first unify cache keys and version isolation to guarantee correctness; then implement linear state checkpoints and chunked storage; then add tiering and asynchronous prefetch; finally enable cross-node reuse with monitoring and alerting to track hit rate, checkpoint restore time, and time-to-first-token percentiles. On platforms such as Baidu AI Cloud, general capabilities like container platforms, object storage, logging services, and monitoring and alerting can carry the tiered cache and observability described above without binding to a specific hardware form.
