Speeding Up LLM Inference by Cutting Prefill Computation and Compressing Recurrent State
Long-context, high-concurrency LLM inference is often limited by two costs: the full deep computation applied to every input token during prefill, and the memory growth of recurrent states during decoding as request count rises. A recent study proposes memory write/read separation, an optimization that targets both bottlenecks and reports up to 42% higher throughput per GPU. This article explains its design, technical details, experimental results, and implementation framework.
1. The Core Problem: Prefill and Decoding Costs Are Asymmetric
In standard autoregressive generation, a model processes an input sequence in two stages. Prefill computes the input context in parallel and builds the key-value (KV) cache. Decoding then generates output tokens one at a time. The common view holds that prefill is compute-bound and decoding is memory-bound. Few approaches, however, examine a less obvious difference: writing memory and reading memory are not equally demanding tasks.
Take a typical 48-layer hybrid model. To predict the first response token, the model must run all 48 layers on the last input token. For the other input tokens, the deep layers do not help predict the next token. Their deep computation serves only to write memory for later decoding, meaning each layer’s KV cache and recurrent state. The researchers therefore hypothesized that the deep computation needed for writing memory is cheaper than the computation needed for predicting the next token. They verified this hypothesis on five trained hybrid models.
2. Strategy 1: Shallow Computation With Dedicated Memory Writes During Prefill
Hybrid LLMs combine softmax attention layers with linear attention or state-space layers. Attention layers keep a KV cache that grows with context length. Linear attention or state-space layers maintain a recurrent state of fixed size. That size does not grow with context, but it is still large. For one model, the recurrent state of a single request takes roughly as much memory as the attention cache for about 4,500 tokens.
For prefill, the study proposes deep write-path separation. The steps are:
- Layer truncation: For each input token except the last, the forward pass stops at a shallow layer. In the 48-layer example, that layer is layer 31.
- Hidden state pass-through: The hidden state output by layer 31 feeds directly into the write path of each subsequent layer. The write path consists of the projections that generate KV cache and recurrent state. The other computations in those layers, such as attention scoring and state updates, are skipped.
- Memory generation and caching: The projections produce the full KV cache and recurrent state, which are stored in the KV cache pool and the state pool.
Only the last input token runs the full 48-layer forward pass, so the model can predict the first response token correctly.
To test whether passing a shallow hidden state into deep write paths is reasonable, the researchers ran a comparison. They sent the same hidden state to the output head for early exit and to the deep write path. Early exit lost much more accuracy on next-token prediction than the deep write path did. This result supports the structural claim that the write path requires less computation than next-token prediction.
3. Strategy 2: Subspace Compression of Recurrent State During Decoding
Each decoding step also carries a significant memory cost for state updates. Before optimization, the recurrent state of a single request can reach the order of 100 MB.
The researchers found that these recurrent states are not high-entropy random vectors. They have clear structure:
- Stable principal direction: The state often contains a principal component whose direction barely changes across time steps.
- Low-rank residuals: After the principal component is removed, the remaining high-dimensional residual can be approximated with a rank far below its original dimension.
Based on this, the method introduces factorized recurrent state storage. Instead of storing the full state vector, the model stores three parts: a principal component basis, a low-rank matrix, and a residual component. On the tested model, the recurrent state of a single request drops from 113.2 MB to 29.2 MB. Including the amortized cost of compression and restoration, the average footprint is 43.4 MB, a reduction of more than 60%.
Compression affects inference in two ways:
- Lower memory footprint: With the same memory capacity, more concurrent requests fit. This is the main source of the throughput gain.
- Lower memory bandwidth pressure: Each state read and update moves less data, which eases the memory-bound bottleneck of decoding.
The model does not decompress the state before each step. It reads and updates the state directly in factorized form. This requires the state update rule to be mathematically consistent with the factorized form. The researchers achieved this by adjusting the state update equations.
4. End-to-End Workflow
Combining both strategies, the inference pipeline works as follows.
Prefill stage:
- The input sequence is embedded and passes through the shallow layers.
- Each non-final token exits at the shallow layer, passes its hidden state through to the deep write paths, and generates and caches memory for every layer.
- The final token runs the full forward pass and outputs the first response token.
Decoding stage:
- The embedding of the current token and the compressed recurrent state are fed into the model.
- Each layer reads the state, computes attention, and updates the state. The updated state is written back to the state pool in factorized form.
- The output layer produces the probability distribution for the next token.
Throughout the process, the original model weights stay frozen. All new low-rank projections, principal component bases, and pass-through structures are trained through knowledge distillation. This avoids the compute cost of retraining the large model and keeps the accuracy impact of truncation and compression within a controlled range.
5. Cross-Architecture Results
The researchers evaluated quality on five hybrid models of different sizes and architectures, covering six checkpoints. This indicates the approach is not overfitted to a single model.
For performance testing, the team used a self-developed, open-source inference framework as the experimental base. They ran coding agent session traces on a next-generation data center GPU. The results were:
- Peak throughput per GPU: The target model improved by 16% to 42%.
- Throughput at matched user-facing output speed (P90 latency): Throughput still improved by 23% to 42%.
These results show that the throughput gains do not come at the cost of latency. The gains are achieved while meeting the output speed users can perceive. This differs from many aggressive optimizations that trade time to first token or time to last token for higher throughput.
6. Takeaways
- Study the structure a model already has. The low-rank nature of recurrent state and the gap between writing memory and predicting tokens are properties of existing models. Exploiting them requires neither new modules nor larger distilled models.
- Optimize prefill and decoding separately. Their compute patterns, memory access patterns, and optimization opportunities differ.
- Count the amortized cost of compression. Compression and decompression have compute costs, and those costs must be included when measuring end-to-end gains.
For developers working on inference systems or model deployment, this approach offers a clear analysis framework. Start by examining the model’s memory structure. Then target the prefill compute path and the state storage layout. Use distillation to preserve accuracy, and measure the resulting gains in system throughput.
