Hybrid-Architecture LLM Inference: State Caching Optimization and Agent Serving Acceleration
Hybrid-architecture models that combine full attention layers with linear layers offer faster decoding and smaller caches, but their prefix caching is far harder to manage than in pure attention models. This article explains how to treat KV cache and recurrent linear-layer states as first-class citizens—using aligned state checkpoints, tiered caching, and cache-aware scheduling—to significantly improve prefill throughput and time-to-first-token for long-context Agent workloads, along with practical engineering guidance for deployment.
Hybrid-Architecture LLM Inference: State Caching Optimization and Agent Serving Acceleration
Background: The Rise of Hybrid Architectures and the Caching Challenge
In recent years, several mainstream large language models have adopted a hybrid architecture that combines full attention layers with linear layers. These models alternate traditional global self-attention with efficient sequence modeling layers of linear complexity (such as linear attention or state space models), aiming to preserve model capability while substantially reducing inference cost.
Hybrid architectures deliver two direct benefits:
- Faster decoding: Linear layers do not require a key-value cache (KV Cache) that grows linearly with context length during autoregressive decoding, so the compute cost per generated token is nearly constant.
- Smaller cache footprint: The KV Cache exists only in a small number of full attention layers, while the remaining linear layers maintain a fixed-size recurrent state, dramatically reducing overall memory usage.
However, there is a trade-off: prefix caching for hybrid models is far more complex than for pure attention models. In pure attention architectures, prefix caching is equivalent to “saving and reusing the KV tensors for a token sequence,” and the cached content depends only on the prefix text, not on where it is inserted. In hybrid architectures, by contrast, the recurrent state of linear layers evolves step by step along the sequence—the state value depends not only on the input content but also implicitly on sequence order and length. This means:
- Reusing a prefix’s linear-layer state requires that subsequent requests resume inference from exactly the same break point;
- The state and KV Cache must be saved and restored as a pair—any mismatch between them silently corrupts outputs;
- Reading, writing, and evicting state requires cross-layer coordination, so simple block-wise KV caching strategies cannot be applied directly.
This problem is especially acute in long-context workloads such as coding Agents and multi-turn tool calling. These workloads typically share extremely long system prompts and conversation histories across turns, with only a small amount of new content appended per turn. When prefix cache hit rates are high, most prefill computation can be skipped; otherwise, every request must re-prefill tens or even hundreds of thousands of tokens, making time-to-first-token (TTFT) and GPU costs unsustainable.
Core Approach: Redesigning State Caching for Hybrid Models
To address these pain points, an effective approach is to manage the hybrid architecture’s “KV cache + linear-layer state” as a first-class citizen, rather than patching an existing KV caching framework. The key design points are as follows.
2.1 State Checkpoints: Aligned Boundaries as the Reuse Unit
Prefix reuse in hybrid architectures must be based on checkpoints that are aligned across layers. The concrete approach: during prefill, at fixed token intervals (for example, at each chunk boundary), synchronously snapshot the KV tensors of all full attention layers together with the recurrent states of all linear layers. A checkpoint is valid and reusable only when both kinds of state come from the same sequence position.
The cost is the extra storage for linear-layer states, but since these states have a fixed size (independent of context length), their storage overhead is much smaller than the KV Cache at the same position—so the trade-off remains favorable overall.
2.2 Tiered Caching and Asynchronous Offloading
In real-world workloads, hot prefixes are hit frequently while long-tail prefixes are accessed only once. A well-designed cache system should therefore use a tiered strategy:
- GPU memory tier: Stores the latest checkpoints of currently active sessions, enabling zero-copy restoration;
- Host memory tier: Stores recently used historical checkpoints, moved asynchronously between GPU and host memory over high-speed interconnects;
- Remote storage tier: Mounts very large caches on a distributed CPU memory pool or object storage, supporting cross-node sharing.
The key is overlapping data movement with computation: while decoding the current request, prefetch the prefix states that the next request is likely to hit, hiding data transfer latency. Measurements show that even when a remote CPU cache pool at the scale of hundreds of GiB is attached, prefill throughput gains remain significant as long as scheduling is done properly—the benefits do not disappear because the cache sits on slower media.
2.3 Cache-Aware Scheduling for Agent Workloads
Coding Agent request streams exhibit strong locality: consecutive requests from the same session have almost identical prefixes. The scheduler should be aware of this:
- Session affinity scheduling: Route requests from the same session to nodes that hold copies of their state, avoiding cross-node fetching;
- Cache-aware queuing: Prioritize requests with high expected cache hit rates to amortize prefill costs;
- Proactive state retention: When a multi-turn conversation is still in progress, delay evicting that session’s checkpoints even if it is temporarily not the hottest.
Evaluation and Results
In replay tests using real coding Agent session traces, a hybrid state caching system built on these ideas achieved substantial gains on the latest generation of data center GPUs:
| Metric | vs. mainstream open-source inference framework baseline |
|---|---|
| Peak prefill throughput | Up to ~3.1x |
| p90 time-to-first-token | Reduced by up to ~88% |
| With a 512 GiB remote CPU cache attached | Throughput and latency gains remain significant |
It is worth emphasizing that these numbers come from long-context Agent workloads with high prefix overlap—the most favorable scenario for this technique. In short-context, low-reuse general chat workloads, the gains will be correspondingly smaller. Whether to adopt this optimization should therefore be evaluated based on your own workload’s session length distribution and prefix overlap rate.
Engineering Best Practices
For teams looking to implement hybrid state caching in their own inference services, consider the following:
- Quantify before optimizing: Collect production data on token length distribution, prefix overlap rate, and session turn distribution to estimate the theoretical upper bound of cache hit rate, and avoid over-engineering.
- State consistency checks: Add lightweight validation on the cache restoration path (for example, hash comparison of the token sequence recorded in a checkpoint) to prevent silent state mismatches from degrading output quality.
- Capacity allocation across tiers: Determine the capacity ratio of GPU memory, host memory, and remote storage based on the “knee” of the hit-rate curve; remote storage can be elastically expanded using cloud object storage and elastic memory pool services.
- Load-test the long tail: Beyond average throughput, always watch p90/p99 TTFT, since the user experience of Agent products is often determined by the slowest requests.
- Plan for distributed scaling: When single-node cache capacity is insufficient, cross-node state reuse and shared cache pools are key to smooth scaling—factor them into the architecture design from the start.
Conclusion and Outlook
Hybrid-architecture models combine full attention with linear layers to achieve clear advantages in decoding efficiency and memory footprint, but they also upgrade prefix cache management from “simple tensor reuse” to “coordinated management of KV cache and recurrent states.” A hybrid state caching scheme built around checkpoints, backed by tiered caching and accelerated by session-affinity scheduling, can multiply prefill throughput and compress tail time-to-first-token latency by nearly an order of magnitude under real Agent workloads.
As Agent applications continue to see longer sessions, state caching will evolve from an internal inference engine optimization into a core capability of the inference infrastructure. Investing early in cache tiering, state consistency, and distributed reuse mechanisms will be a key step toward building the next generation of cost-effective LLM inference services.
