Speeding Up Hybrid-Architecture LLM Inference: Layered Prefill and Recurrent State Compression
This article examines the computational bottlenecks of hybrid-architecture large language models (LLMs), which combine a few full-attention layers with many linear-attention or state-space layers. It introduces SEED, an optimization method that reduces inference cost through two key techniques: splitting the prefill phase into shallow computation plus a lightweight memory writer, and compressing recurrent states via principal-component low-rank decomposition. The approach preserves the original model weights and decoding path, yielding 16%–42% higher peak GPU throughput and 23%–42% higher throughput at the same P90 end-to-end output rate, particularly effective for coding-agent workloads with long inputs and continuous generation. The article also outlines evaluation methods and practical insights for inference engineering.
Speeding Up Hybrid-Architecture LLM Inference: Layered Prefill and Recurrent State Compression
Where the Cost Really Goes in Hybrid Architectures
Recent large language models increasingly adopt hybrid attention architectures. Instead of placing full attention in every layer, these networks keep only a small number of full-attention layers to maintain the KV cache that grows with context, while the remaining layers use linear attention or state-space structures that carry historical information in a fixed-size recurrent state. This design balances long-context expressiveness with computational efficiency during inference, making it popular for ultra-long input scenarios such as code repository understanding, long-document Q&A, and multi-turn agent conversations.
But a fixed state size does not mean a small state. In a typical hybrid model, the combined recurrent states for a single request occupy GPU memory roughly equivalent to thousands of tokens’ worth of attention cache. More importantly, during decoding, every generated token requires reading and updating the states of all linear-attention layers. These states compete with other concurrent requests and reusable prefix caches for scarce memory. The tighter memory becomes, the lower the concurrency capacity, and the worse the per-GPU throughput.
The prefill stage also suffers from structural waste. When processing a long input of several thousand tokens, the model must run all dozens of layers for every token. However, from the perspective of “predicting the next word,” only the deep-layer output of the last input token is actually used. For the remaining tokens, the deep layers serve mainly to write deep KV caches and recurrent states that future generation will read—deep computation here acts as memory writing, not content understanding.
These two observations raise a central question: Does writing memory really require running the entire network? The SEED method (layered prefill + recurrent state decomposition compression) answers no, and proposes targeted improvements for both phases.
Prefill Stage: Shallow Computation + Lightweight Memory Writer
Key Insight: Writing Memory and Predicting Tokens Have Different Computational Needs
SEED’s first optimization exploits a previously overlooked distinction: the deep computation required to “write memory” for later generation can be far less than that needed to “predict the next token.” Memory writing essentially compresses and encodes input information into cache structures, where the information bottleneck lies mainly in shallow feature extraction. Predicting the next token, by contrast, requires the full semantic reasoning chain, which depends on deep network capacity.
Implementation: Layer Separation and Distillation Training
The concrete approach can be summarized as an asymmetric two-phase path:
- Input side: Except for the last input token, all other tokens run only the first 31 layers of the network. A lightweight “memory writer” component then directly generates the KV caches and recurrent states for the remaining 17 layers, based solely on these shallow outputs.
- Generation side: Once decoding begins, every new token still runs the full 48-layer network, ensuring generation quality identical to the original model.
Several engineering details are worth highlighting. First, the original model weights remain frozen throughout—the pretrained parameters are never touched, so the model’s language capabilities are unchanged. Second, the memory writer is trained via distillation: it learns to reproduce the memory representations generated by the deep layers of the original model, using those deep caches as supervision signals. Third, because the decoding path remains completely unchanged, the behavior difference is strictly limited to where the caches come from, not how the model thinks.
This paradigm of “freeze the backbone, distill the accessory” is engineering-friendly for inference engines. Operators, quantization, and scheduling strategies for the backbone model can be preserved as-is; one only needs to insert an extra memory-writing logic at the end of the prefill stage.
Decoding Stage: Principal-Component Low-Rank Compression of Recurrent States
Empirical Observation of State Structure
The second optimization targets memory pressure during decoding. Structural analysis of recurrent states as they are read and updated reveals a consistent pattern: each state contains a dominant component that remains nearly constant in one direction, and the residual after removing it exhibits clear low-rank structure. In other words, although the state matrix is large, its effective degrees of freedom are far smaller than its surface dimensions.
Decomposed Storage and Direct Updates
SEED does not follow the conventional compression route of “store the full state, decompress when used.” Instead, it makes the model maintain states directly in a decomposed form—dominant component plus low-rank factors—so that reads and updates operate on the decomposed representation. This brings two advantages. First, it avoids the expensive compression/decompression round-trip for every token. Second, state updates (which are typically low-rank increments) map naturally to corrections of the low-rank factors.
The effect is substantial. On one instance of such a model, a single request’s recurrent state dropped from 113.2 MB uncompressed to 29.2 MB immediately after compression, with an average of 43.4 MB over the compression cycle. As the original text calculates, the original per-request state was equivalent to the attention cache space of about 4,500 tokens; after compression, the freed memory directly translates into higher concurrent request capacity or longer reusable prefix caches.
Throughput Gains and Quality Assurance
Performance Data
In a test setup combining high-end inference accelerators, a mainstream high-performance inference framework, and coding-agent session traces, SEED improved per-GPU peak throughput by 16%–42%. When comparing at the same P90 user-perceived end-to-end output rate—that is, measuring throughput without degrading user experience—the improvement was 23%–42%. Notably, coding-agent workloads feature extremely long inputs plus continuous generation, which simultaneously amplifies both the benefits of layered prefill and state compression, making them the best showcase for this approach.
Quality Evaluation Approach
The most common concern for any inference optimization is accuracy degradation. SEED’s validation strategy is worth examining: it evaluates quality across five models and six checkpoints, covering different scales and training stages rather than testing only a single model. Additionally, since the original weights are frozen and the decoding path is unchanged, the evaluation focuses on whether the distilled memory writer faithfully reproduces the deep caches. For teams wanting to replicate this approach, a recommended acceptance framework includes:
- Accuracy regression tests on long-context benchmark tasks.
- Perplexity comparisons bucketed by input length.
- Token-by-token output consistency analysis against the original model during decoding.
- P50/P90/P99 latency and throughput curves under high-concurrency stress tests.
Practical Implications for Inference Engineering
The biggest takeaway from SEED is to decompose inference cost by “phase × memory type” and optimize each separately. The waste in the prefill stage comes from running full deep computation on tokens that do not generate output. The waste in the decoding stage comes from storing highly redundant state representations. Both forms of waste stem from the same fact: existing models have spontaneously formed separable memory structures during training. The optimizer’s job is not to invent new structures but to make these structures explicit.
Three transferable lessons for engineers building LLM inference systems:
- Analyze before optimizing: Singular value or principal component analysis of caches and states often reveals substantial compression opportunities.
- Freeze the backbone, distill the periphery: Minimize the risk of changes and ensure rollback capability.
- Anchor comparisons to user experience: Measuring throughput at the same P90 output rate is closer to real business value than bare peak throughput.
In cloud-native deployment environments, such optimizations can also combine with container-platform elastic scheduling and latency metrics from monitoring and alerting systems, turning per-GPU throughput gains into lower unit cost and higher service capacity. As hybrid-architecture models become the mainstream choice for long-context scenarios, the idea that “writing memory does not require reading the entire network” is likely to be repeatedly validated in future inference optimization work.
