Hybrid Model Long-Context State Cache Management and Prefill Throughput Optimization
This article examines why prefix caching is more complex in hybrid models that combine full attention with linear or state-space layers. It presents a coordinated caching strategy for KV blocks and recurrent states, including adaptive checkpointing, tiered storage, and agent-aware scheduling. Tests on real coding-agent traces achieved up to 3.14× baseline prefill throughput and an 88.4% reduction in p90 time to first token.
Hybrid Model Long-Context State Cache Management and Prefill Throughput Optimization
1. Background: Hybrid Architectures Are Mainstream, but Cache Management Is the New Bottleneck
To reduce decoding costs without compromising model quality, an increasing number of large language models are adopting hybrid architectures that combine full attention layers with linear layers, linear attention, or state-space layers. These architectures offer two primary benefits:
- Lower KV cache usage: Linear layers do not maintain key-value caches that grow linearly with sequence length. Instead, they maintain fixed-size recurrent states, significantly reducing GPU memory consumption.
- Faster decoding: The per-step computation cost of linear layers is independent of context length, which reduces memory-access and computational pressure during long-context decoding.
Several recent-generation models are following this direction. Hybrid architectures have moved from experimental designs into production systems. However, when these models are deployed in real inference services—particularly for workloads such as coding agents, which involve multiple turns and extremely long contexts—engineering teams quickly encounter an underestimated challenge: prefix-cache management is much more complicated for hybrid models than for pure Transformer models.
2. Why Cache Reuse Is More Difficult in Hybrid Architectures
For a pure Transformer, prefix-cache reuse is relatively straightforward. The KV cache is organized at token granularity. When two requests share a prefix, the KV blocks for that prefix can be reused directly, with cache-hit detection and cache assembly performed using a consistent block-level representation.
Hybrid architectures break this assumption and introduce three fundamental difficulties.
1. Misaligned state granularity
The state of a linear layer is compressed: an entire prefix is folded into a fixed-size state tensor. Unlike a KV cache, it cannot be sliced and reused at an arbitrary token boundary. To resume the linear-layer computation from token N, the system must have saved a state snapshot at exactly that position. Otherwise, it must recompute the state from the beginning.
2. Different cache lifecycles
KV caches for full-attention layers can be stored in blocks and evicted as needed. Linear-layer states, by contrast, are relatively small but serve as critical checkpoints. Their capacity pressure, access frequency, and recomputation costs are fundamentally different. Managing both with a single policy can either waste KV capacity or cause frequent state recomputation.
3. Agent workloads amplify the problem
A typical coding-agent trajectory consists of multiple conversation turns. Each turn appends a small amount of new content—such as tool results or code snippets—to the previous context before triggering another inference step.
Ideally, most of the prefix should be served from cache. In practice, sparse linear-state checkpoints and misaligned KV blocks and state snapshots significantly reduce the effective hit rate. As a result, substantial compute is spent on repeated prefill operations, and the tail of time-to-first-token (TTFT) latency deteriorates noticeably.
3. Designing a New Hybrid State Cache Management Strategy
A hybrid state cache management approach proposed jointly by researchers and industry practitioners offers a systematic redesign. Its core ideas can be summarized in four areas.
1. Decouple state and KV storage while coordinating their scheduling
Linear-layer states should no longer be treated as secondary components of the KV cache. Instead, they should be managed independently as first-class cache objects.
The system maintains a dedicated index for state checkpoints and records the token position associated with each checkpoint. During prefix matching, the scheduler queries both the KV-block index and the state-checkpoint index. It then selects a recovery point that jointly optimizes the KV hit length and the available state checkpoint, minimizing the amount of recomputation.
2. Adapt checkpoint density to workload patterns
State checkpoints do not need to be saved at a fixed interval. The strategy dynamically adjusts checkpoint placement according to request-arrival patterns.
Checkpoint density is increased in regions that are frequently reused across conversation turns, such as system prompts and historical turn boundaries. In areas that are generated only once, checkpoints can be stored more sparsely. This approach substantially improves the probability of reusing linear-layer states without significantly increasing storage overhead.
3. Use tiered storage: GPU, CPU, and distributed cache
GPU memory is limited, so the cache is divided into multiple tiers:
- Hot data remains in GPU memory.
- Warm data is offloaded to host memory, including large CPU cache capacity at the scale of hundreds of GiB.
- Cold data is written to a distributed storage layer, with support for reusing hybrid states across nodes.
The key requirement is that the hybrid state—consisting of KV blocks and linear-layer checkpoints—is serialized, transferred, and restored as a unit. This preserves consistency between the two cache types during tier migration.
In testing, the system continued to deliver significant throughput and latency improvements after introducing a large external cache layer, compared with a baseline without tiered management. This indicates that the cost of the offload path was effectively hidden.
4. Optimize scheduling for agent trajectories
For multi-turn agent workloads, the scheduler prioritizes routing subsequent requests from the same session to an instance that already holds the relevant cache.
In cross-node deployments, the system retrieves the remote state directly from distributed cache instead of recomputing the entire prefix. This extends cache-hit optimization from the single-machine level to the cluster level.
4. Evaluation: Up to 3× Higher Prefill Throughput
The research team replayed real coding-agent conversation traces on the latest generation of data-center GPUs and compared the results with a widely used high-performance inference framework.
The results showed:
- Peak prefill throughput reached approximately 3.14× that of the baseline.
- p90 time to first token decreased by as much as 88.4%.
- The performance gains remained stable after adding a large CPU cache layer, validating the tiered-storage design.
For service operators, these results mean that the same amount of compute can support more concurrent agent sessions, while users experience substantially lower latency for long-context requests. These improvements come from cache-management changes rather than modifications to the model itself.
5. Engineering Recommendations
Teams planning to deploy hybrid-model inference services in the cloud should consider the following practices:
- Benchmark with realistic workload patterns: Replay multi-turn traces with long-prefix reuse instead of relying on isolated short requests. This is necessary to expose the actual bottlenecks in hybrid caching.
- Monitor linear-state checkpoints: Track checkpoint hit rate, state recomputation rate, and tier-migration latency alongside TTFT and throughput. These metrics should be included in monitoring and alerting systems.
- Use tiered infrastructure effectively: Container orchestration can be combined with inference-instance scheduling, memory-optimized nodes can provide the CPU cache tier, and object or distributed storage can hold cold states. For example, Baidu AI Cloud’s general-purpose capabilities for large-model inference deployment, object storage, and elastic computing can serve as infrastructure components for this type of tiered caching architecture and help reduce the cost of building the system independently.
- Plan for cluster-wide reuse from the beginning: Session-affinity scheduling and cross-node state sharing should be considered from the first implementation. Otherwise, a single-node cache design may need to be reworked substantially when the service scales.
6. Conclusion
Hybrid architectures achieve lower cache usage and faster decoding at the model level, but they transfer additional complexity to the inference system’s cache-management layer.
A redesigned hybrid state-cache architecture—combining coordinated management of KV blocks and linear states, adaptive checkpointing, tiered storage, and cross-node reuse—shows that this complexity can be handled systematically. As agent workloads continue to grow, these kinds of system-level innovations will become an important avenue for reducing the cost of large-model inference and improving its efficiency.
