Optimizing State Caching for Hybrid Architectures: Up to 3x Higher Prefill Throughput

    This article explains why hybrid LLM architectures that combine full attention with linear layers create new caching challenges, especially for multi-turn, long-context coding agents. It breaks down the core mismatch in granularity, lifecycle, and transfer cost between attention KV caches and linear state snapshots, then presents a layered hybrid state cache design across device, host, and remote tiers. Key mechanisms include heterogeneous chunking, prefix matching with state alignment, parallel write-back and prefetching, and tier-aware scheduling. The article also reports prefill throughput and TTFT improvements from replay tests and offers practical guidance for adopting the approach in your own inference stack.

    1. Background: New Caching Challenges in Hybrid Architectures

    Mainstream large model architectures are evolving from pure attention to hybrid designs that combine full attention with linear layers. These models have lower computational complexity during decoding and a smaller KV Cache footprint, which gives them a natural advantage in long-context scenarios. However, the problem becomes more complex when the workload shifts from single-turn Q&A to multi-turn, long-context coding agents.

    Typical coding assistants repeatedly read repositories, run commands, review historical diffs, and keep appending context across turns. This leads to two direct consequences:

    1. Highly repetitive prefixes: Within the same session, a large portion of the token prefix stays identical across adjacent turns.
    2. Heterogeneous state types: Full attention layers need per-token key-value pairs cached, while linear layers (such as state space or linear attention structures) only need a fixed-size recurrent state.

    Traditional approaches assume one caching strategy fits all layers. As a result, hybrid models achieve significantly lower prefix reuse efficiency than pure attention models. Prefill is forced to recompute, and time to first token (TTFT) deteriorates rapidly under high concurrency.

    2. The Core Conflict: Why Hybrid States Cannot Be Treated the Same

    To understand the optimization approach, it helps to break the conflict into parts:

    • Mismatched granularity: Attention caches are addressable per token, so they can be split into blocks and reused by prefix matching. Linear states are compressed over an entire segment, cannot be naturally split per token, and can only be saved as interval snapshots.
    • Mismatched lifecycle: Attention caches grow linearly with context and require eviction. Linear states stay constant in size, but recomputing them requires replaying the entire prefix from the beginning, which is extremely costly.
    • Mismatched transfer cost: Attention caches are large but can be transferred in a pipelined manner. Linear states are small but highly sensitive to when they become available.

    The key in a hybrid architecture is therefore not to cache more, but to reuse both types of state at the right level, with the right granularity, at the right time.

    3. Design Approach: A Layered Hybrid State Cache

    One proven direction is to split the cache into three cooperating tiers:

    1. Device-side hot cache: Holds the attention blocks and linear state snapshots used by the current request, optimized for the lowest access latency.
    2. Host-side warm cache: Manages large-scale prefix blocks with a page-table approach and supports reuse across requests and turns.
    3. Remote/distributed cold cache: Targets long-term reuse across nodes and sessions, with the largest capacity and highest latency.

    The core mechanisms can be summarized in four points:

    • Heterogeneous chunking: Attention layers are managed in fixed token blocks; linear layers generate state snapshots at fixed step intervals, so both types of state can be addressed uniformly.
    • Prefix matching + state alignment: After matching the longest common prefix, the attention part attaches existing blocks directly; the linear part loads a snapshot strictly aligned to the match boundary to avoid semantic misalignment.
    • Parallel write-back and prefetching: Newly generated states are asynchronously persisted in the background, while the next turn’s likely reusable prefix is predicted from session patterns and prefetched ahead of time.
    • Hot/cold tiered scheduling: States migrate across the three tiers based on reuse frequency, avoiding keeping large attention caches on low-bandwidth links for long periods.

    Illustrative pseudocode:

    1. def prefill(request):
    2. prefix = match_longest_prefix(request.tokens) # hit attention blocks
    3. state = load_aligned_state(prefix.end) # aligned linear state snapshot
    4. if state is None: # fall back to recompute if not aligned
    5. state = replay_from_nearest_snapshot(request)
    6. kv = attach_cached_blocks(prefix)
    7. return forward(request.tokens, kv, state) # compute only the unmatched part

    4. Engineering Results: Gains in Both Throughput and Latency

    In replay tests on real multi-turn coding workloads, this hybrid state cache design increased prefill throughput by up to about 3x over a general-purpose inference framework baseline, while p90 TTFT dropped by nearly 90%. The sources of these gains are clear:

    • Higher prefix hit rates directly reduce repeated prefill computation.
    • Linear states avoid full-segment replay, eliminating the most expensive recompute path.
    • Tiered transfer keeps large caches from blocking the critical path.

    When a host-side cache of hundreds of GiB was added, the gains remained, showing that the method is not only effective when GPU memory is abundant, but can scale its reuse value as cache capacity grows. This also means it naturally fits deployment patterns based on distributed storage and cross-node state reuse.

    5. Implementation Guidance: Applying It in Your Own Inference Stack

    1. Measure before optimizing: Track average prefix reuse length within sessions, inter-turn intervals, and the share of state recomputation to confirm the bottleneck is indeed prefill.
    2. Unify the addressing abstraction: Define a consistent key for both state types (session ID + prefix hash + step index); otherwise the layered cache cannot cooperate.
    3. Prioritize asynchronous write-back: Move state persistence off the critical path to prevent disk jitter from affecting TTFT.
    4. Separate capacity and eviction policies: Use least-recently-used eviction for the hot tier, reuse-frequency weighting for the warm tier, and session-lifecycle reclamation for the cold tier.
    5. Complete observability: Set up monitoring and alerts for hit rate, alignment failure rate, and prefetch accuracy, and keep tuning.
    6. Compose cloud deployment flexibly: Container platforms can host inference instances, object storage or distributed caches can host the cold tier, and logging and monitoring services can handle tracing, allowing a layered cache system to be built from general cloud product categories.

    6. Conclusion

    The real bottleneck of hybrid architecture models has shifted from compute to how state is reused. Designing attention caches and linear states as two types of objects with different lifecycles and granularities, then connecting them through layered storage and cross-node reuse, is the key path to improving prefill throughput and reducing TTFT under long-context agent workloads.