Redesigning Cache for Hybrid Architectures: How Prefill Throughput Gets a Multi-Fold Boost
This article explains why cache management designed for pure attention models wastes resources in hybrid architectures that alternate full attention layers with linear state layers. It breaks down the physical differences between the two state types, then presents a layered cache redesign with separate allocation, lifecycle, and parallelism strategies. Readers will find three optimization strategies, the combined sources of prefill speedup, and a practical tuning checklist.}
1. Background: Hybrid Architectures Are Mainstream, but Cache Design Still Lags
Over the past year, a growing number of large models have adopted hybrid architectures that alternate full attention layers with linear state layers. The motivation is straightforward: full attention layers handle precise global retrieval and long-range dependency modeling, while linear state layers—such as state space models, linear attention, and gated recurrent structures—trade a constant-size inference state for faster decoding and a smaller cache footprint.
When the model structure changes, however, cache management in inference engines often remains built on assumptions made for pure attention models. This leads to three typical forms of waste:
- Capacity mismatch: Placing the recurrent states of linear layers and the key-value cache of attention layers in the same memory pool, then swapping them in and out under one policy, lets small states get held hostage by large block allocations.
- Bandwidth mismatch: Prefill is compute-intensive, with the bottleneck coming from the combined load on compute and memory bandwidth. A unified cache repeatedly moves linear layer states around, taking bandwidth that could otherwise be used for attention chunking.
- Parallelism mismatch: Tensor parallelism, pipeline parallelism, and sequence parallelism do not split the two layer types equivalently. A one-size-fits-all approach causes load imbalance and pipeline bubbles.
Using “hybrid state cache redesign” as the main thread, this article lays out an explainable and implementable optimization framework, and shows why a sound cache design can deliver a multi-fold improvement in prefill throughput.
2. Physical Differences Between the Two State Types
Before redesigning the cache, it helps to lay out the physical properties of both state types:
- Attention layer key-value cache: Its size is proportional to sequence length and grows linearly with the number of layers, heads, and head dimension. Its access pattern is random reads by position, especially for global retrieval in long contexts.
- Linear layer recurrent state: Its size is independent of sequence length and depends only on state dimension and channel count. Its access pattern is strict sequential recurrence, with a read-modify-write at every step.
The conclusion is clear: one is large and random, the other is small and sequential. Managing them with the same allocator, the same eviction policy, and the same alignment granularity inevitably sacrifices one side. The first principle of the redesign is physical isolation and differentiated policies.
3. Layered Caching: Managing the Two State Types Separately
The core of layered caching is to split the memory pool into two logical domains, each with its own allocator, alignment granularity, and lifecycle:
Memory Pool├── KV Domain: large blocks, allocated by sequence/block, supports paging and on-demand swap-in└── S Domain : small blocks, fixed slots per layer, mostly resident, batched snapshots only
Key points include:
- Independent allocators: The KV domain uses paged block management with configurable block granularity; the S domain uses fixed slots plus a ring buffer to avoid fragmentation.
- Differentiated lifecycles: The KV cache can be reclaimed entirely when a request ends; S domain states must persist throughout decoding, while during prefill they can be reused as intermediate snapshots.
- Alignment and layout: The S domain is aligned to the intra-layer parallelism degree, ensuring a single transfer covers one parallel shard and reducing cross-shard synchronization.
4. Why Prefill Is Slow: Three Real Bottlenecks
The prefill stage processes an entire prompt in one pass, and its performance is constrained by three factors:
- High compute intensity: Matrix multiplications are dense and easily saturate compute, so any extra memory access directly lowers effective throughput.
- Improper chunk granularity: Chunks that are too small create scheduling overhead; chunks that are too large raise peak memory usage and limit parallelism.
- Redundant state movement: Linear layer states are repeatedly read and written across chunks. If they are scheduled in coupling with attention chunks, they create unnecessary serial waits.
5. Redesign Strategy 1: State Compression and Low-Precision Residence
Although linear layer states are “small,” their total volume is considerable under long sequences and high concurrency. Options include:
- Low-precision residence: Keep states resident at lower precision and upcast on demand during computation, with error kept within an acceptable range.
- Chunked snapshots: Advance prefill chunk by chunk, generating a state snapshot at the end of each chunk for later rollback or branch reuse.
- Sparse write-back: Lower the write-back frequency for channels that are insensitive to change, reducing bandwidth usage.
# Illustration: chunked prefill + state snapshotsfor chunk in split(prompt, chunk_size):kv = attn_prefill(chunk, kv_cache) # attention chunk computationstate = linear_step(chunk, state) # sequential recurrence of linear layerssnapshot(state) # generate a reusable snapshot
6. Redesign Strategy 2: Prefill Chunking and Pipeline Parallelism
Split prefill into multiple chunks and stagger the two layer types across a pipeline:
- Intra-chunk parallelism: Schedule attention chunks and linear chunks in parallel within the same stage so they do not block each other.
- Cross-chunk pipelining: Overlap the linear recurrence of chunk n with the attention computation of chunk n+1 to hide latency.
- Dynamic chunk size: Adapt chunk size to the remaining sequence length and memory watermark, balancing throughput against peak usage.
7. Redesign Strategy 3: Aligning Parallelism with State Properties
Parallelism strategies must align with the physical properties of the states:
- Tensor parallelism: Split along the attention head dimension; split linear layers by channel or state dimension to avoid cross-shard reduction.
- Sequence parallelism: Split along the sequence dimension for long contexts, but preserve the sequential nature of linear recurrence using prefix-style sharding.
- Pipeline parallelism: Group by layers, ensuring a balanced ratio of the two layer types within each pipeline stage to reduce bubbles.
8. Where the Gains Come From: Why It Reaches Multi-Fold
The improvement in prefill throughput does not come from a single point optimization, but from several paths stacking together:
- Bandwidth release: Less state movement leaves more effective bandwidth for attention chunking.
- Scheduling overlap: Pipeline parallelism hides recurrence latency, completing more chunks per unit time.
- Memory optimization: Domain-separated management reduces fragmentation and peak usage, allowing larger batches and longer contexts.
- Precision tradeoff: Low-precision residence reduces write-back volume with almost no loss in precision.
Multiplied together, these make the “multi-fold” result explainable rather than an accidental outcome of single-point tuning.
9. Deployment Tuning Checklist
- Separate domains first, then tune parameters: confirm the KV domain and S domain are physically isolated.
- Stress-test chunk sizes: sweep 64/128/256 and observe throughput and peak memory curves.
- Enable pipeline overlap: verify that linear recurrence and attention computation truly run in parallel.
- Monitor bandwidth: watch whether state write-back becomes the new bottleneck.
- Precision regression: run end-to-end quality regression on low-precision states and set an acceptable threshold.
10. Conclusion
The “faster decoding and smaller cache” promised by hybrid architectures is conditional: only when cache management moves from a unified pool to a redesign that separates domains, policies, and parallelism will the potential of the prefill stage be truly unlocked. For teams deploying inference services on platforms such as Baidu AI Cloud, this framework maps directly to resource planning on container platforms, metric design for monitoring and alerting, and trace practices in logging services—helping move optimization from “experience-based tuning” to a measurable, reproducible engineering loop.
