Redesigning State Caching in Hybrid Architectures: A Critical Path to Higher Prefill Throughput

    This article explains why hybrid architectures that combine full attention layers with linear layers complicate KV cache management for long-context, multi-turn workloads. It contrasts attention state with linear layer state, identifies why prefix reuse fails, and outlines four redesign principles: unified addressing with tiered storage, consistency binding between state and KV blocks, hot and cold aware eviction, and cache aware scheduling. It also covers evaluation methods and a staged rollout approach.

    1. Background: Why Hybrid Architectures Dominate Long-Context Workloads

    Recent model designs widely adopt a hybrid stack of full attention layers and linear layers. The motivation is straightforward: full attention layers handle precise global information retrieval, while linear layers (in state space or linear attention form) replace the growing key-value sequence with a fixed-size recurrent state, reducing both computation and memory usage during decoding.

    For single-turn question answering and short prompts, this trade-off is almost pure upside. But with workloads such as AI coding assistants and multi-turn agents, the picture changes. Requests become multi-turn, long-context, and heavily overlapping in their prefixes, so the system must repeatedly prefill the same prefix. Cache management in hybrid architectures is then significantly more complex than in pure attention models.

    2. Two Fundamentally Different Kinds of Cache

    A pure attention model has a homogeneous cache: every layer and every position maps to one key-value vector. The cache can be split at token granularity, appended block by block, shared via reference counting, and evicted simply by dropping trailing blocks.

    Hybrid architectures hold two states with completely different semantics at the same time:

    • Attention state: one-to-one with positions, precisely truncatable by prefix length, and naturally suited to prefix sharing.
    • Linear layer state: a fixed-size tensor that evolves over time, semantically equivalent to “a summary after reading the first n tokens.” It cannot be split per token, and concatenating states from two different branches does not produce a correct result.

    This leads to three direct consequences. First, cache granularity is inconsistent, so block-level management strategies cannot be applied as-is. Second, prefix sharing must reuse state and key-value blocks as a pair, with matching versions; otherwise the model output drifts in ways that are hard to notice. Third, state is small but accessed frequently, while key-value blocks are large but accessed sparsely, so the two have opposite hot and cold characteristics.

    3. Why Prefix Reuse Breaks Down

    In practice, a falling cache hit rate is usually an indexing and lifecycle problem rather than a capacity problem:

    1. Coarse index key design. Using only a text hash as the key ignores dimensions such as model version, quantization scheme, and parallel sharding strategy, causing incorrect reuse across configurations.
    2. Lifecycle mismatch. In long sessions a prefix is referenced repeatedly, while caches from short requests are evicted first, so hot data gets evicted and cold data stays resident.
    3. State and key-value blocks managed in separate stores. Their eviction rhythms fall out of sync, so the whole entry eventually has to be invalidated and the hit rate is dragged down by the weakest link.
    4. Missing affinity in distributed deployments. Requests are scheduled to nodes that do not hold the corresponding state and must recompute.

    Illustrative cache key construction:

    1. def cache_key(prefix_tokens, model_cfg, parallel_cfg):
    2. h = hash(prefix_tokens) # fingerprint of the prefix content
    3. return (h, model_cfg.version, # weight and architecture version
    4. model_cfg.quant, # quantization configuration
    5. parallel_cfg.tp, parallel_cfg.pp)

    4. Four Key Points for Redesigning the State Cache

    First, unified addressing with tiered storage. Build one naming and referencing mechanism for both attention blocks and linear state, keep only the hottest portion in GPU memory, and let a larger memory pool and host-side cache hold warm and cold data, forming a GPU memory, memory, and external storage hierarchy.

    Second, consistency binding between state and key-value data. Treat linear state as a checkpoint bound to a specific prefix length, and allow reuse only when the checkpoint matches the version of the prefix blocks; on a mismatch, fall back to the most recent common checkpoint and recompute.

    Third, hot and cold aware eviction. Score entries by reference frequency, last access time, and remaining session activity, avoiding the thrashing a single LRU policy causes in long sessions.

    Fourth, scheduling and cache affinity. In cross-node deployments, route requests to the node already holding the longest reusable prefix, and support cross-node state migration and reuse. On platforms such as Baidu AI Cloud, this typically relies on container platform orchestration, object storage or distributed file systems for persistence, plus monitoring, alerting, and logging services to observe hit rate and latency percentiles.

    5. Where the Gains Come From and How to Evaluate

    Prefill throughput gains come from three places: the longer the reusable prefix, the less repeated computation; tiered hits avoid recomputing some state back into GPU memory; and scheduling affinity reduces cross-node transfer. Long-tail improvement in time to first token depends more on the second point, since p90 cases are often long-prefix requests that miss the cache.

    For evaluation, hold these variables fixed: replay of real multi-turn traces, the same concurrency and input length distribution, and a uniform GPU and memory capacity configuration. Report throughput, TTFT at p50/p90/p99, cache hit rate, state migration bandwidth, and peak GPU memory. Looking at average latency alone hides long-tail regressions.

    6. Rollout Recommendations

    First, quantify prefix overlap to see whether there is room to optimize the cache. Then unify cache keys and version management, the step with the most certain payoff. Next, introduce tiered storage and hot and cold eviction. Finally, add cross-node affinity scheduling. Each step should have its own controlled experiment, so scheduling gains are not mistaken for cache gains.