Hybrid Architecture Models: Redesigning State Caching for Prefill Acceleration
Hybrid models that combine full attention layers with linear layers are becoming a mainstream choice for large language models. However, their two fundamentally different cache types—KV caches and fixed-size recurrent states—make prefix caching far more complex than in pure Transformers. This article explains the core conflict between the two cache granularities, how multi-turn agent workloads amplify it, and how a unified prefix index with checkpointed linear states, tiered storage, and careful eviction policies can convert architectural gains into real serving efficiency, with reported prefill throughput gains of up to 3x and p90 TTFT reductions of up to 88%.
Why Hybrid Architectures Are Going Mainstream
Many recent open-source large models adopt a hybrid structure that combines full attention layers with linear layers. Full attention layers preserve precise long-range dependency modeling, while linear layers—including linear attention and state space models—replace the length-growing KV cache with a fixed-size recurrent state. This combination balances modeling quality, decoding speed, and memory footprint, which is why more and more models are adopting it.
However, architectural benefits do not automatically translate into serving-side efficiency. In inference services, prefix caching is the core mechanism for reducing prefill overhead. Pure Transformer models only need to cache per-layer KV entries, which naturally split along token positions. Hybrid models, by contrast, hold two fundamentally different kinds of cache, and cache management complexity rises accordingly.
The Fundamental Difference Between the Two Cache Types
1. KV Caches in Attention Layers
KV caches map one-to-one to token positions and grow with sequence length. They can be split into fixed-size blocks, and blocks sharing the same prefix can be directly reused via hash indexing. This mechanism is mature and relatively simple to implement.
2. Recurrent States in Linear Layers
The state of a linear layer is a compressed accumulation over the entire prefix. Its size is fixed, but it does not retain per-position information that can be independently extracted. A state only represents the result of “processing up to a specific position.” If a request’s prefix only partially overlaps with a cached prefix, the state cannot be sliced like a KV cache—the system must find a state snapshot saved at exactly the same boundary.
3. The Core Conflict
The two cache types differ in granularity: KV entries are organized by blocks, while states are saved at full-prefix boundaries. With block-level matching alone, linear-layer states often miss; storing every full conversation state wastes enormous space in branching scenarios. The task of hybrid cache management is to build a consistent index that bridges these two granularities.
Access Patterns of Multi-Turn Agent Workloads
A coding agent’s typical interaction is a multi-turn loop: read context, call a tool, append the tool output to the history, and request the model again. This workload has three characteristics:
- High prefix overlap. Each turn’s input is almost always an extension of the previous turn’s input; system prompts and history are reused repeatedly.
- Frequent branching. The same history can spawn multiple follow-up requests due to retries, rollbacks, or parallel exploration.
- High prefill share. Tool outputs are often long, so the newly added portion requires substantial prefill computation, making time-to-first-token critical for interactive experience.
Key metrics for such workloads therefore include prefill throughput, effective computation after cache hits, and tail latency (e.g., p90 TTFT). Averaging latency alone masks long-tail problems.
Design Approach for a Hybrid State Cache
To resolve the conflict above, a reasonable approach is to unify both cache types under a single prefix index.
1. A Unified Prefix Key
Every cache entry uses “model signature + token prefix hash” as its key. The model signature must include the weight version, numerical precision, tokenizer version, and similar metadata to prevent erroneous reuse across different configurations.
2. Attention KV Stored by Block
KV caches continue to use fixed-size blocks. Blocks are linked through a hash chain, enabling fast lookup of the longest reusable prefix.
3. Linear States Saved as Checkpoints
State snapshots (checkpoints) of the linear layers are saved at semantically clear boundaries, such as conversation turn boundaries or the end of tool calls. These checkpoints are aligned with the corresponding KV block indices, ensuring that both cache types are available at the same boundary. Checkpoint frequency requires trade-offs: smaller intervals increase hit rates but also raise write and storage overhead.
Illustrative code:
def lookup_prefix(model_sig, tokens):# Walk backward from the longest candidate boundary, looking for a position# that has both KV blocks and a state checkpointfor boundary in candidate_boundaries(tokens, reverse=True):key = make_key(model_sig, tokens[:boundary])kv_blocks = kv_index.get(key)state = state_index.get(key)if kv_blocks is not None and state is not None:return boundary, kv_blocks, statereturn 0, None, None # No reusable prefix; compute from scratch
The key point of this logic: prefill can only be skipped when both cache types are available at the same boundary. If the KV hits but the state is missing, the linear layers must still be recomputed, negating the benefit.
Tiered Storage and Cross-Node Reuse
Single-device memory is limited, and long-context caches are evicted quickly. In practice, a tiered strategy is common:
- Tier 1: Accelerator memory, holding blocks and states for currently active requests.
- Tier 2: Host memory, holding recently hot prefixes, with capacities reaching hundreds of GiB.
- Tier 3: Distributed storage, holding historical prefixes shared across nodes.
Tiering introduces three problems. First, backfill latency: loading a state from host memory must be significantly faster than recomputing it, or the cache actually slows the service down. Second, consistency: version-mismatched state snapshots produce incorrect outputs, so reuse must pass signature validation. Third, eviction policy: combine access frequency with recency, and prioritize long prefixes and highly reused entries.
Interpreting the Performance Numbers
Public replay experiments show that, on specific hardware and real coding-agent trajectories, such approaches achieve up to roughly 3x prefill throughput and reduce p90 time-to-first-token by up to about 88% compared with general-purpose baselines. The gains remain significant even when a large host-memory cache is attached.
Three caveats apply when reading these numbers. First, results depend heavily on the workload’s prefix repetition rate. Second, the choice of baseline implementation affects the relative speedup. Third, p90 improvements correlate closely with cache hit rates. Before committing to an approach, run replay tests against your own real traffic rather than relying on published figures.
Engineering Recommendations
- Measure hit rates before optimizing. Analyze prefix length distributions and repetition rates to determine the upper bound of caching benefits.
- Build a replay benchmark. Fix the input trajectories and record prefill throughput, TTFT percentiles, and memory usage separately.
- Design fallbacks for failure paths. On cache misses, version invalidation, or concurrent write conflicts, the system must safely fall back to full computation.
- Set up monitoring and alerting. Define thresholds for hit rate, eviction counts, and backfill latency to catch performance regressions early.
Hybrid architectures make model structures more efficient, and cache systems must evolve in step. Bringing attention caches and state caches under a unified prefix management scheme is a key step toward turning architectural gains into serving efficiency.
