Redesigning State Caching for Hybrid Architectures: 3x Higher Prefill Throughput

    This article explains why hybrid architectures that combine full attention with linear layers make caching more complex, and how to redesign the cache around the two different reuse semantics of KV cache and recurrent state. It covers prefix consistency rules, decoupled scheduling, a four-layer cache design with a scheduling pipeline, the sources of prefill throughput gains, engineering pitfalls, and a general capability combination for cloud deployment. Readers will get a practical checklist for cache key design, eviction policy, and capacity tiering.

    1. Why Hybrid Architectures Make Caching Harder

    In recent open-source LLM designs, linear attention and state space layers have moved from experimental components to standard configuration. Typical examples include gated delta-rule linear attention, gated incremental network structures, and structured state space sequence models. Stacked alternately with standard full attention layers, they form a hybrid architecture of “full attention + linear layers.” The motivation is clear: full attention layers provide precise global retrieval, while linear layers carry long-range history in a constant-size state, reducing per-step compute during decoding and significantly shrinking cache footprint.

    The problem is that caching in a hybrid architecture is no longer a single shape. A pure standard attention model has only a KV cache, which grows linearly with sequence length and follows relatively uniform management logic. A hybrid model holds two kinds of state at the same time:

    • Per-token KV cache, present only in full attention layers, which can be split and reused precisely by prefix position.
    • Recurrent state, present in linear layers, which compresses history into a fixed-size matrix or vector and cannot be split simply by token position.

    The conflict is amplified by workloads such as coding assistants and multi-turn agents: requests share long system prompts and repository context, turns keep appending content, prefixes are highly repetitive, yet every turn requires a fresh prefill. If you reuse the paged cache design built for pure attention, linear layer states get recomputed repeatedly or invalidated as a whole block. Prefill becomes the bottleneck of the entire path, and the long tail of time to first token (TTFT) is especially visible.

    2. Core Insight: The Two State Types Have Different Reuse Semantics

    Before redesigning the cache, the semantics need to be stated clearly.

    KV cache is “concatenable”: the KV of prefix A concatenated with the KV of suffix B is equivalent to one prefill over A+B, so prefix caching can hit and reuse block by block.

    Recurrent state is “advanceable”: the state is a compressed summary of what has already been read, and it can only be reproduced by replaying exactly the same prefix. Once the prefix is rewritten or the block boundaries differ, the state must be rolled back and recomputed. This means state cache hits are naturally coarser in granularity and sensitive to computation order.

    This yields three design principles:

    1. Prefix consistency first: all cache blocks (KV blocks and state blocks) must be split with the same chunking rule, so hit determination can be done in one pass.
    2. Decouple state and KV scheduling: swap KV in and out at fine block granularity, and save and restore state at coarse “checkpoint” granularity.
    3. Choose between recomputation and migration: when state is unavailable, compare the cost of “replaying from the nearest checkpoint” against “pulling state across nodes” and take the cheaper path.

    A schematic cache key design can be expressed as:

    1. cache_key = hash(model_id, layer_type, block_size, prefix_token_ids_chunk)
    2. entry = {
    3. kv_blocks: [block_0, block_1, ...], # full attention layers only
    4. state_ckpt: {step: k, tensor: ...}, # linear layer checkpoint
    5. ref_count: int
    6. }

    3. Redesign: Layered Cache and Scheduling Pipeline

    On top of these principles, a practical hybrid state cache typically has four layers.

    The first layer is a chunked prefix index. A hash index is built with a fixed token block as the smallest unit. Block size is a tradeoff: too small inflates index overhead and metadata, too large wastes the tail on a hit. In practice this is often combined with longest common prefix probing, locating the KV block sequence and the state checkpoint position in a single lookup.

    The second layer is a device-side cache pool. GPU memory keeps only hot blocks, evicted by reference counting and an approximate least recently used policy. State checkpoints are small and have high reuse value, so they can be given higher priority to avoid being pushed out by KV blocks.

    The third layer is host memory and a remote cache pool. CPU memory on the order of 512GiB serves as a second-level cache, with object storage or a distributed cache as a third-level fallback. The key here is not capacity itself but the transfer strategy: state tensors are contiguous and small, suitable for batched prefetch; KV blocks can be streamed layer by layer, overlapping computation with data movement.

    The fourth layer is the scheduler. When a prefill request arrives, the scheduler first determines the hit, then chooses one of three execution paths: full hit assembles directly, partial hit replays the tail from the nearest checkpoint, and a miss performs a normal prefill and writes back to the cache. To avoid long requests blocking others, chunked prefill is usually introduced, splitting a long sequence into multiple compute blocks inserted into batches, balancing throughput with latency fairness.

    1. on_request(req):
    2. hit = index.lookup(req.prefix, block_size)
    3. if hit.full:
    4. return assemble(hit.kv, hit.state)
    5. if hit.partial:
    6. state = load_checkpoint(hit.state_ckpt)
    7. kv, state = replay(req.suffix, state) # replay the tail only
    8. else:
    9. kv, state = prefill(req.tokens)
    10. cache.writeback(kv, state, async=True)

    4. Where the Performance Gains Come From

    Raising prefill throughput by several times is not a single-point optimization but the sum of three gains.

    First, repeated computation is eliminated. In multi-turn agent workloads the prefix repetition rate is often very high, and every block that hits saves a matrix multiplication and normalization pass. Because linear layer state is also reused correctly, the half-invalid case of “KV hits but state is recomputed” is avoided.

    Second, batching efficiency improves. Chunked prefill lets long and short requests be batched together, keeping device utilization steadier, so a long tail request no longer monopolizes compute and p90 TTFT drops noticeably.

    Third, the storage tiers work together. Small state fits on the fastest tier, while large KV sinks to host memory and the remote pool; once prefetch overlaps with computation, cross-tier access latency is hidden inside compute time.

    Note that the specific multiple depends heavily on the model layer ratio, block size, prefix repetition rate, and hardware bandwidth. Engineering evaluation should be based on your own trace replay data rather than copying someone else’s numbers.

    5. Implementation Notes and Common Pitfalls

    • Chunking rules must be globally consistent. Any change to the prompt template, special tokens, or truncation policy invalidates the cache as a whole.
    • Define a clear policy for state precision. Some implementations store state at lower precision for capacity, and the cumulative impact on output quality needs evaluation.
    • Eviction must distinguish object types. KV blocks and state checkpoints have different reuse cycles, and a uniform policy loses hit rate.
    • Multi-tenant isolation cannot be ignored. The cache key must include model and tenant dimensions to avoid cross-user prefix hits that leak data.
    • Observability should come first. Monitor hit rate, replay length, swap-in and swap-out bandwidth, and p50/p90 TTFT with alerting and log analysis, and tune block size and capacity parameters from data.

    6. A General Capability Combination for Cloud Deployment

    To reproduce similar capabilities on your own platform, combine general capability categories: use a container platform to host inference services and elastic scaling, object storage to hold checkpoints and model weights, a distributed cache or message queue for cross-node state distribution and task decoupling, and monitoring, alerting, and logging services to observe hit rate and latency tails. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as a reference foundation for capacity planning and tiered storage design.

    7. Summary

    A hybrid architecture is not simply about a “smaller cache,” but about two semantically different states that need two coordinated mechanisms. Unify prefix chunking, decouple KV and state scheduling, make recomputation and migration selectable paths, and combine them with chunked prefill and tiered storage to turn the value of repeated prefixes into real throughput and latency gains. For teams building coding assistants, multi-turn agent services, and long-context applications, this maps directly into a checklist for cache key design, eviction policy, and capacity tiering.