Redesigning State Cache for Hybrid-Architecture LLMs and Optimizing Prefill Throughput
This article explores the engineering challenges introduced by hybrid large language model architectures that alternate full attention layers with linear layers. It details a unified state cache design that manages attention KV and linear layer states within a shared paged memory pool, and presents checkpoint-based state snapshots and operator-level pipeline fusion to address prefix reuse limitations and prefill bottlenecks. Readers will gain practical insights into improving prefill throughput and reducing memory footprint for hybrid models in production inference systems.
Why Hybrid Architectures Have Become Mainstream
In recent years, many newly released large language models have adopted a hybrid architecture that interleaves full attention layers with linear layers. The primary motivation is straightforward: achieve faster decoding speed and smaller inference cache footprint while preserving the model’s expressive capability as much as possible.
Traditional Transformers rely entirely on full attention mechanisms, whose KV Cache grows linearly with sequence length. When context reaches tens or even hundreds of thousands of tokens, the KV Cache can consume dozens of GB of GPU memory, directly limiting concurrency and the maximum context length a single GPU can handle. Linear layers—such as variants of linear attention and state space models—only need to maintain a fixed-size state vector during inference. This state does not expand with sequence length, making the memory overhead constant.
Hybrid architecture is a compromise between the two: a small number of full attention layers handle precise long-range retrieval and fine-grained dependency modeling, while a large number of linear layers perform efficient sequence compression and local pattern extraction. A typical configuration might insert one full attention layer after every several linear layers, reducing the overall KV Cache to a fraction of what a pure attention model would require, while significantly reducing per-step computation during decoding.
New Challenges Hybrid Architectures Pose to Inference Systems
The hybridization of model architecture substantially increases the complexity of cache management in inference engines. Three challenges stand out.
1. Heterogeneous cache formats. Full attention layers need to store Key and Value tensors at token granularity, supporting incremental appends at arbitrary prefixes. Linear layers maintain a fixed-shape state matrix, updated through an overwrite operation of “read old state, write new state.” These two types have completely different memory layouts, lifecycles, and access patterns, meaning a conventional paged KV Cache manager cannot be reused directly.
2. Difficulty in prefix reuse. In multi-turn Agent scenarios, large common prefixes—composed of system prompts and tool definitions—should ideally be accelerated through cache reuse. Prefix reuse for full attention layers is relatively straightforward (KV blocks can be shared directly). However, linear layer states are unidirectional recurrent compressions; once new content is inserted in the middle, the subsequent states must be recomputed from scratch. They cannot be “spliced” at arbitrary boundaries like KV blocks.
3. Prefill becomes a new bottleneck. In hybrid architectures, prefill for linear layers typically relies on chunked scan algorithms, whose computation pattern differs significantly from the matrix multiplications used in full attention. If the inference framework still follows a pure attention pipeline schedule, the linear layer operators and attention operators will experience a large number of synchronization waits, causing GPU utilization to drop and prefill throughput to fall well below the hardware’s theoretical limit.
Redesigning the Unified State Cache
A practical engineering direction for addressing the above issues is to abstract both attention KV and linear layer states into a unified “State Cache” system. The core design includes the following elements.
1. Unified paged memory pool. Linear layer states can also be managed in a block-based manner: each sequence is assigned logical state blocks, backed by a single unified physical memory pool. The allocator is aware of the size and alignment requirements of both cache types, avoiding the fragmentation and waste caused by separate memory pools. This enables dynamic redistribution of the GPU memory budget between KV blocks and state blocks.
2. Checkpoint-based state snapshots. To alleviate the prefix reuse problem of linear layers, state snapshots can be saved at fixed intervals during prefill (e.g., every 2048 tokens). When a new request shares a prefix with a historical request, the system can roll back to the nearest common snapshot and only recompute the differing portion, rather than scanning the entire sequence from the beginning. This yields significant benefits in Agent scenarios, where system prompts often constitute thousands of tokens of common prefix—the snapshot mechanism allows them to be computed only once.
3. Operator-level pipeline fusion. During prefill, chunked scan operations from linear layers and computations from attention layers can be interleaved and scheduled within the same stream, eliminating synchronization bubbles between layers. For chunked scan specifically, the intra-block computation (parallelizable portion) can be decoupled from the inter-block recurrence (serial portion). The serial recurrence can then run on a separate CUDA stream, overlapping with parallel computation from other layers.
4. Tiered eviction strategy. In a hybrid architecture, the two cache types have different “value densities”: full attention KV supports precise retrieval, while linear states are compressed summaries. When GPU memory is constrained, the system may prioritize evicting intermediate copies of linear state snapshots while retaining KV and endpoint states. If needed, short-range recomputation can recover the evicted data.
Measured Improvements in Prefill Throughput
Industry practices indicate that through the unified state cache and scheduling optimizations described above, prefill throughput for hybrid architecture models can improve several-fold. The sources of gain can be decomposed as follows:
- Eliminating synchronization overhead: Pipeline parallelism across layers typically contributes more than 30% improvement;
- Prefix state reuse: On Agent-type workloads with high prefix overlap, duplicate computation is largely eliminated, yielding 2 to 3 times effective throughput gains;
- Unified memory pool: Reduced memory fragmentation enables larger batch sizes, which in turn brings additional throughput gains.
It is worth emphasizing that headline numbers like “3x improvement” are highly dependent on workload characteristics (prefix overlap ratio, sequence length distribution, batch size). Engineering evaluations should use traffic replay that closely mirrors real business patterns rather than synthetic benchmarks.
Recommendations for Engineering Implementation
For teams looking to support hybrid architectures in their own inference systems, the following progressive path is recommended: first, complete paged management of linear layer states and verify correctness; second, introduce checkpoint-based snapshots to address prefix reuse; and finally, implement operator-level pipeline optimization. For deployment, teams can leverage standard container platforms along with monitoring and alerting systems to continuously track cache hit rates, prefill latency, and GPU memory usage, forming a closed-loop optimization process that is both measurable and rollback-safe. General-purpose capabilities offered by cloud platforms—such as object storage and logging services from Baidu AI Cloud—can also support cache snapshot persistence and performance data analysis.
Hybrid architectures will not be the endpoint of efficiency exploration for large models. However, the principle of “unified management of heterogeneous states” will become a foundational capability in the design of future inference engines.
