Optimizing Inference at Scale: Hierarchical Computation and State Compression for LLMs
This article explores two practical optimizations for large language model inference: hierarchical computation that separates prefilling from token generation, and low-rank compression of recurrent state to reduce memory footprint. It details how these techniques improve GPU throughput by 23–42% and compress state by over 4x while preserving output quality via distillation-based training. The discussion covers the underlying principles, engineering implementation, and measurable benefits for long-context, multi-turn scenarios.
Technical Background: The Computational Bottleneck in Inference
As large language models (LLMs) are deployed across industries, optimizing inference performance has become a central engineering challenge. In typical generative architectures, inference is split into two phases: the prefill phase, which processes the input context and generates the corresponding key-value (KV) cache, and the decode phase, which produces new tokens step-by-step using that cache. For a model with dozens or even hundreds of Transformer layers, the prefill phase requires executing every layer for every token in the input sequence. This is compute-intensive and introduces significant latency. When input sequences are long or concurrent request volumes are high, the prefill phase becomes the primary bottleneck for overall system throughput.
Importantly, not all computation in the prefill phase is equally necessary. From a task perspective, the computational complexity required to understand and remember context differs fundamentally from the complexity required to accurately predict the next token. This insight opens a theoretical path for optimizing the prefill computation.
Core Optimization 1: Hierarchical Computation with Depth Separation
Principle and Implementation Concept
A typical large model may have 48 Transformer layers. In the traditional prefill process, every token in the input passes sequentially through all 48 layers. A new optimization idea is to let the vast majority of input tokens pass through only the first 31 layers completely. For the remaining 17 layers, these tokens no longer participate in the full forward pass. Instead, a lightweight “memory write” component generates the KV cache and recurrent state needed for subsequent decoding.
This design exploits a natural division of responsibilities across depth. Shallow layers typically extract basic syntax and lexical features, while deeper layers capture complex semantic relationships and logical reasoning. For predicting the next token, deep computation is indispensable; however, for writing the necessary information required for subsequent memory tasks, features extracted by shallow layers are often sufficient.
Full Execution During Generation
Notably, during the decoding (generation) phase, every newly generated token still runs through all 48 layers. This means the optimization precisely targets the prefill phase without sacrificing the representational capacity of any generated token. For models that rely on in-memory KV caches, this “energy-saving” prefill strategy can dramatically reduce initial request latency and free up computational resources while introducing almost no accuracy loss.
Quantitative Difference and Benefit Evaluation
To validate this hierarchical approach, researchers conducted systematic measurements on a set of pre-trained hybrid-architecture LLMs. The measurement results show that the deep computation required to write memory for subsequent generation is theoretically far less than the computation needed to directly predict the next token. This quantitative difference directly guides engineering implementation: computational resources in the prefill phase are reallocated, and the savings from reduced deep-layer work are used to process more concurrent requests.
In practical inference service frameworks and standard session-trajectory evaluations, applying this scheme significantly improves per-GPU peak throughput. Under the same output-rate benchmark, throughput increases between 23% and 42%. In other words, without adding hardware, the same GPU can handle more user requests in the same time, directly reducing per-inference service cost.
Core Optimization 2: Low-Rank Compression of Recurrent State
Discovery of State Redundancy
In the decode phase, besides the KV cache, the model also reads and writes a “recurrent state” at every step. This state typically exists as a matrix and characterizes the model’s internal dynamics. However, linear algebra analysis reveals that these recurrent state matrices often contain a near-constant “principal component,” while the remainder exhibits a clear low-rank structure (i.e., information is concentrated in a few main directions).
Decomposed Storage and Direct Read/Write
Based on this structural property, engineers can store the recurrent state in a decomposed form: a fixed principal-direction vector plus a low-rank correction matrix. The inference engine can directly read and update the decomposed components without ever reconstructing the full state matrix.
The space savings are substantial. For an open-source hybrid-architecture model, the original recurrent state for a single request occupied 113.2 MB; after compression it dropped to 29.2 MB—a compression ratio of over four times. Considering that the state changes dynamically throughout inference, the average occupancy remains around 43.4 MB. The significant reduction in memory footprint not only lowers per-request resource cost but also allows more concurrent requests to reside on the GPU, multiplying throughput.
Accuracy Preservation and Training Strategy
The bottom line for any performance optimization is output quality. In both optimizations above, the original model’s weights are frozen and never modified. The newly introduced memory-write component and state-compression module are learned via distillation training. Specifically, the training process uses the original model’s complete output as a teacher signal, guiding the lightweight modules to approximate that signal. This paradigm ensures that the new modules do not disrupt the existing model’s distribution; instead, they act as peripheral cooperative components that pursue efficiency while adhering to accuracy boundaries. Evaluation results across multiple models and checkpoints show that this scheme, alongside several-fold throughput improvements, keeps the accuracy penalty within acceptable limits.
Combined Evaluation and Practical Insights
When both optimizations are applied together, their effects are not isolated. Hierarchical computation reduces the compute needed for prefill, while compressed recurrent state frees memory; together they doubly boost the inference engine’s concurrency. The advantage is especially pronounced in standard coding-conversation scenarios (long inputs, multi-turn interactions) because such workloads intensively involve prefill computation and state read/write operations.
This practice offers several insights for developers. First, deep analysis of model structure remains a golden key to performance optimization—structural redundancy often correlates with computational redundancy. Second, memory and compute are two sides of the same coin for inference cost; cleverly exploiting numerical structures (such as low-rankness) for compression is key to balancing both. Third, preserving model quality via distillation while pursuing performance is a mature and reliable engineering paradigm.
Looking ahead, as model context windows expand further and inference concurrency continues to rise, systematic optimizations that target computational patterns and state structures will likely become the mainstream path for cost reduction and efficiency gains in large-scale intelligent applications. For technical decision-makers, understanding and adopting this mindset of “hierarchical computation, explicit compression” in their own systems, and conducting equal-dimensional performance profiling, will be a critical step toward improving infrastructure efficiency.
