Redesigning State Caching for Hybrid Architectures: Tripling Prefill Throughput
This article explains why hybrid architectures that combine full attention with linear layers are becoming the default for long-context LLM workloads, and why their state caching is harder to manage than the homogeneous KV cache of pure attention models. It covers three key designs—chunking and alignment, prefix indexing with state binding, and tiered caching—along with capacity estimation and cost-based reuse decisions. It also outlines the metrics and replay methods needed to validate prefill throughput and TTFT gains, plus practical rollout advice. Actual speedups depend on model structure, chunk size, parallelism, and hardware, so teams should re-measure on their own workloads.
1. Hybrid Architectures Are Becoming the Default for Long-Context Workloads
In open-source LLM designs over the past two years, linear attention and state space layers have shifted from experimental components to common configurations. Linear attention driven by the Gated Delta Rule, structured state space sequence layers, and similar structures are stacked alternately with a small number of full attention layers, forming a hybrid backbone of “full attention plus linear layers.” The motivation is straightforward: the key-value cache of a full attention layer grows linearly with context length, whereas a linear layer maintains only a fixed-size recurrent state, so compute and memory access during decoding stay roughly constant.
The gains are especially clear for workloads such as AI coding tools. A single session often includes a system prompt, repository retrieval snippets, results from multiple tool calls, and long diffs, reaching tens of thousands to hundreds of thousands of tokens, with adjacent requests sharing large prefixes. Hybrid architectures trade a smaller cache footprint for longer usable context, but the cost is that cache management logic changes from a single type to multiple heterogeneous types.
2. Why Caching Is Harder in Hybrid Models
The cache in a pure attention model is homogeneous: one key-value tensor per layer, appended by token position, with a unified eviction policy. A hybrid model has at least two kinds of state:
- Attention state: corresponds one-to-one with positions and can be appended, truncated, and reused at token granularity.
- Recurrent state: compressed from an entire prefix, retaining only a fixed-size matrix that cannot be split by token.
This creates three concrete problems. First, granularity mismatch. Prefix matching usually happens at the token level, but recurrent state can only be hit or recomputed as a whole segment, and partial hits cannot be stitched together. Second, inconsistent lifecycles. Attention cache can be released entirely when a session ends, but if recurrent state is shared across multiple branch sessions, it requires reference counting and copy-on-write. Third, difficult capacity planning. The memory footprint of the two state types varies with layer count, head count, and state dimension, so estimating simply by token count can be significantly off.
A rough capacity estimate can be written as:
kv_bytes = 2 * layers_full * kv_heads * head_dim * tokens * dtype_sizestate_bytes = layers_linear * state_heads * head_dim * state_dim * dtype_sizetotal = kv_bytes * (1 + offload_ratio) + state_bytes * branch_copies
Here offload_ratio is the fraction offloaded to host memory or remote storage, and branch_copies is the number of state copies caused by branch sessions.
3. Three Key Designs for Hybrid State
The first is chunking and alignment. Split a long prefix into fixed-length chunks, append attention cache by chunk, and take a snapshot of the recurrent state at each chunk boundary. The chunk boundary is the reuse unit: on a hit, restore the recurrent state from the nearest snapshot, then fill in the attention cache for the remaining tokens inside the chunk. Chunk length is a tradeoff: too small increases the number of snapshots and metadata overhead, while too large reduces the benefit of partial hits.
The second is prefix indexing with state binding. The index structure records not only token hashes but also the recurrent state handle for each chunk, its reference count, and a version number. Branch sessions use copy-on-write so that appends in one session do not pollute the shared prefix of other sessions.
The third is tiered caching. Keep hot chunks in GPU memory, use a host memory pool for warm chunks, and use distributed or object storage for cold chunks. The scheduler makes cost-based decisions using hit probability, recomputation cost, and transfer bandwidth:
cost_reuse = transfer_bytes / bandwidth + state_restore_overheadcost_recompute = tokens_miss * prefill_cost_per_tokenuse_cache = cost_reuse < cost_recompute
Cross-node reuse requires a stable state serialization format that is decoupled from the parallelism scheme; otherwise states cannot be migrated directly across different parallel degrees.
4. Sources of the Performance Gains and How to Validate Them
The improvement in prefill throughput comes mainly from three places: hit prefixes are not recomputed; recurrent state is restored from a snapshot instead of accumulated from scratch; and lower memory pressure allows larger batch sizes. The improvement in the tail of time-to-first-token latency comes from avoiding repeated scans of very long prefixes; the p90 percentile is more sensitive than the mean, so the improvement is usually larger there.
Validation should cover four categories of metrics: prefill throughput; mean and p90 TTFT; cache hit rate and chunk granularity; and effective bandwidth across different tiered media. Replaying real session traces is more meaningful than synthetic load tests, because branching and backtracking behavior only appears in real traces. Note that the specific multiplier depends heavily on model structure, chunk length, parallelism, and hardware, and cannot be extrapolated across environments; teams should re-measure on their own workloads.
5. Engineering Rollout Advice
Start by quantifying the baseline: measure the prefix length distribution, the shared-prefix ratio between adjacent requests, and branch depth to determine whether caching has room to help. Then start with small chunks and run offline replays, observing the crossover point between hit rate and recomputation cost. Next, add tiered offloading to move the capacity bottleneck from GPU memory to host memory and shared storage, with monitoring and alerts tracking jitter in hit rate and restore latency. If you use container platforms and object storage to hold cold state, pay attention to serialization overhead and network round trips, and compress state before offloading if necessary. General-purpose container, storage, and monitoring capabilities from cloud providers such as Baidu AI Cloud can serve as the foundation for this kind of tiered cache, but the final choice should still be based on your own load test data.
