Hybrid Architecture Cache Redesign: A Deep Dive into Prefill Acceleration
This article explains why hybrid architectures, which combine full attention layers with linear layers, make caching more complex, and how to redesign the cache for faster prefill. It covers a unified, addressable cache abstraction based on content fingerprints, prefill scheduling strategies that maximize cache hit rates, tiered storage, and distributed reuse. You will also find guidance on measuring throughput and p90 latency gains, along with a phased adoption plan.
1. Why Hybrid Architectures Make Caching Harder
A growing number of large language models now adopt a hybrid architecture that combines full attention layers with linear layers. Linear layers typically rely on recurrent states or convolution-style states, so they do not need to store key-value pairs that grow linearly with context length during inference. Full attention layers, on the other hand, preserve precise retrieval capability. Combining the two reduces state usage during decoding and eases memory pressure for long contexts.
However, workloads such as AI coding assistants are characterized by multi-turn requests, long contexts, and clearly shared prefixes. The system has to reprocess a large amount of common context every turn, making the prefill stage the bottleneck. In a hybrid architecture, the cache is no longer just key-value pairs; it also includes recurrent states, convolution states, and other forms. These have different lifecycles, addressing schemes, and eviction policies, which makes prefix reuse harder than in pure attention models.
2. Core Idea: Unify Both State Types into Addressable Cache Objects
The key to reusability is a unified abstraction for states of different forms: compute a content fingerprint for each segment of content, package the corresponding attention key-value blocks and linear states into a “state block,” and use the fingerprint as the global identifier. This way, as long as the prefix content matches, a request can hit the same cache regardless of which node it comes from.
The logic looks like this:
block_id = hash(parent_block_id, token_chunk)cache_entry = { kv_blocks, recurrent_state, conv_state, ref_count }
On top of this, three problems need to be solved. First, chunk granularity: chunks that are too small incur high metadata overhead, while chunks that are too large lower the hit rate. Second, state alignment: hybrid layer states must be split along the same chunk boundaries to avoid semantic misalignment caused by partial hits. Third, reference counting and reclamation: when multi-turn conversations share a prefix, only blocks whose reference count drops to zero can be evicted.
3. Scheduling and Execution: Prefill Orchestration Aimed at Hit Rate
After a cache hit, the scheduler only computes the uncached tail chunks and reassembles the cached states back into the inference context layer by layer. In engineering practice, you can use “longest prefix match first + chunked pipelining”: first look up the table to determine the reuse boundary, then split the remaining tokens into batches so that computation overlaps with cache reads and idle time is reduced.
You should also set capacity watermarks and a backfill policy. When cache pressure rises, prioritize keeping hot prefixes and asynchronously demote cold blocks to a storage tier with higher capacity and lower latency bandwidth. On backfill, verify each block’s fingerprint to prevent content drift from causing incorrect reuse.
4. Tiered Storage and Distributed Reuse
Single-machine memory capacity is limited, so host memory and local SSDs can be introduced as second- and third-level caches, forming a memory–host memory–disk hierarchy. In cross-node scenarios, a metadata service is needed for global indexing and consistency checks, while the data plane schedules by node affinity, keeping compute tasks as close as possible to the nodes holding the cache to reduce network transfer.
5. Sources of Gains and Evaluation Methodology
Prefill throughput gains come mainly from three sources: no repeated computation of common prefixes, overlap between state assembly and computation, and cold data being demoted so it does not squeeze memory. Tail improvements in time-to-first-token come from the simultaneous drop in queuing and computation time when the hit rate is high.
For evaluation, keep the model, hardware, and trajectory dataset fixed, and report the impact of hit rate, chunk granularity, and cache capacity on throughput and p90 latency separately. Distinguish between a pure-memory configuration and one with a second-level cache, so that differences in storage bandwidth are not mistaken for algorithmic gains.
6. Adoption Recommendations
In cloud environments such as Baidu AI Cloud, the state cache can run on a container platform, with object storage holding cold data and monitoring and alerting tracking hit rate and latency percentiles. The recommended rollout order is: first implement content fingerprinting and chunk alignment, then integrate tiered storage, and finally enable cross-node reuse, validating gains and stability step by step.
