Reducing Inference Cost of Hybrid-Architecture LLMs by Truncating Deep Prefill Computation and Compressing Recurrent State During Decoding

    This article explains two ways to lower inference cost in hybrid-architecture large language models. In these models, cache cost is split between key-value caches in standard attention layers and recurrent states in linear attention or state-space layers. The first method skips most deep-layer computation for non-final input tokens during prefill, using a lightweight writer to generate the memory those layers would have produced. The second stores the recurrent state in a low-rank factored form during decoding. The article also covers how to evaluate throughput and output quality together, and which engineering risks to check before adoption.

    1. Background: Why Hybrid Architectures Are a Focus for Inference Optimization

    Over the past two years, long-context models have commonly adopted hybrid architectures. These models keep only a small number of standard attention layers. The remaining layers use linear attention or state-space structures. The two types of layers have different cache characteristics, so inference cost is spread across two components.

    Standard attention layers store a key-value (KV) cache. Its size grows linearly with context length, so longer inputs consume more memory. Linear attention and state-space layers maintain a recurrent state instead. The size of this state does not depend on context length, and it is updated once for every generated token. Its size is fixed, but not necessarily small. Take a typical mid-sized hybrid model as an example. The space occupied by the recurrent state for a single request may equal the attention cache for several thousand tokens.

    Inference has two stages. Prefill processes the full input in one pass and computes the caches and states for each layer. Decoding generates output tokens one at a time, reading and updating these caches and states at each step. The two stages have different computation patterns and bottlenecks, so each one needs its own optimization.

    2. Prefill Stage: Redundancy in Deep Computation

    The output of prefill serves one purpose. The model only needs the output of the last input token at the output layer to predict the first reply token. The outputs of the other tokens in the deep network mainly generate the caches and recurrent states that later generation steps need.

    This leads to a key inference. The computation needed to write memory for later generation may be much smaller than the full computation needed to predict the next token. In other words, a large part of the deep network’s computation serves to write memory, not to produce the result.

    Based on this inference, one approach splits the model into two segments. The first several layers compute normally for all tokens. The subsequent deep layers do not run for non-final tokens. Instead, a lightweight writer component generates the caches and states that the deep layers need, directly from shallow hidden states. The last token still passes through the full deep network, which keeps the computation path for the first output complete.

    The following code illustrates the data flow only. It is not a complete implementation:

    1. def prefill(tokens):
    2. h = embed(tokens)
    3. for layer in shallow_layers: # First K layers: all tokens are computed normally
    4. h = layer(h)
    5. prefix_memory = writer(h[:-1]) # Lightweight component generates cache and state for deep layers
    6. h_last = h[-1:]
    7. for layer in deep_layers: # The last token still runs through the full deep network
    8. h_last = layer(h_last, prefix_memory)
    9. return prefix_memory, head(h_last)

    This design raises three questions. First, how do errors from the writer propagate across layers? Second, which layers are suitable for truncation, and where should the truncation point be? Third, how much does truncation affect quality in scenarios such as long inputs and multi-turn conversations? These questions can only be answered through experiments.

    For training, the original model weights stay frozen, and only the newly added writer component is trained. The training objective is usually distillation: the caches and states produced by the writer should match, as closely as possible, those produced by the full network for the same input. This approach leaves the original model’s capabilities unchanged, concentrates risk in the new component, and makes rollback straightforward.

    3. Decoding Stage: Low-Rank Representation of Recurrent State

    During decoding, the recurrent state is the main problem. It is read and written at every step, and it competes for memory with active requests and prefix caches. As concurrent requests increase, memory pressure quickly becomes the limit on throughput.

    A useful observation is that the structure of the recurrent state is not random. In many trained models, the state matrix contains a dominant component whose direction stays close to fixed. After removing this component, the remainder shows clear low-rank characteristics. Low rank means that a few basis vectors can approximate this content well.

    Based on this, the state can be stored in a factored form. Let the state be the matrix S. It can be written as a dominant-direction component plus a low-rank residual:

    S ≈ μ·d + L·R

    Here, d is the unit dominant direction, μ is a scalar, and L and R are factor matrices of rank r. When r is much smaller than the state dimension, storage drops substantially. More importantly, the model can perform reads and updates directly on the factored form, without reconstructing the full matrix at each step.

    The following code shows the idea:

    1. def compress_state(S, r):
    2. d = dominant_direction(S) # Dominant direction
    3. mu = dot(S, d) # Strength of the dominant component
    4. residual = S - outer(mu, d)
    5. U, s, Vt = truncated_decompose(residual, r) # Truncated low-rank decomposition
    6. return d, mu, U * s, Vt # Store in factored form

    Low-rank approximation introduces error, and that error can accumulate over multiple update steps. It is therefore necessary to determine an acceptable rank r and to verify how the error grows over long sequences. Compression and decompression costs must also be counted in the total benefit. Otherwise, they may offset the memory savings in small-batch scenarios.

    As an example from a public study, the recurrent state of a single request in a 48-layer hybrid model dropped from about 113 MB to about 29 MB. The average occupancy across the full compression cycle was about 43 MB. These figures depend on model scale, precision format, and sequence length. They indicate the order of magnitude of the method only and should not be applied directly to other models.

    4. How to Evaluate: Look at Throughput and Quality Together

    A common mistake in evaluating inference optimizations is looking only at peak throughput. Peak throughput is usually measured when the system is heavily loaded. At that point, queuing delay and tail latency may already be poor. For online services, users experience the output rate of each request, especially at high percentiles such as P90.

    A more complete evaluation should therefore include three types of metrics.

    Metric Meaning Notes
    Peak throughput per accelerator card Tokens processed per second by one accelerator card Describe how the workload is constructed
    Throughput at the same P90 output rate Throughput compared after fixing the tail experience Closer to the real constraints of online services
    Quality regression Accuracy changes across multiple tasks and model checkpoints Cover long-context and multi-turn scenarios

    In the study above, the workload came from multi-turn sessions of a programming assistant. Such workloads feature long contexts, high prefix reuse, and continuous state across turns. Under the same hardware and framework, peak throughput improved by about 16% to 42%. At a comparison point with the same P90 user-facing output rate, throughput improved by about 23% to 42%. The gap between the two sets of results shows that the comparison basis can significantly change conclusions, so both should be reported together.

    The quality evaluation covers five models and six checkpoints. Because the original model weights are frozen, quality changes mainly come from write errors in the new component and from state compression errors. The evaluation should examine both average scores and worst-subset performance, because errors often concentrate on long inputs or rare patterns.

    5. Key Points for Engineering Deployment

    Truncation points need offline sweeps. The deeper the truncation, the greater the savings, but the larger the error. Train writer components for several candidate truncation points, plot quality against savings, and choose a configuration near the knee of the curve.

    Cache layout needs redesign. The writer’s output must align with the existing cache structure. If the system already supports prefix caching, confirm that newly generated memory can be reused correctly and that states from different prefixes are not mixed.

    Schedulers need to account for both cost types. Once prefill computation decreases, scheduling policies need to rebalance the share of prefill and decoding. Otherwise, the system may hit a bottleneck in one stage while overall utilization stays the same.

    Monitoring should cover quality and tail behavior. After launch, monitor output length distribution, repetition rate, refusal rate, and human ratings in addition to throughput and memory. Quality issues often appear in subtle forms, and averages alone can miss them.

    A rollback path must be kept. Because the original model weights are unchanged, rollback usually only requires switching to the full-network inference path. The serving layer must keep both paths and be able to switch between them per request or per version.

    6. Applicability Boundaries and Risks

    This approach relies on one premise: the model’s intermediate representations contain redundancy, so the main role of deep computation can be approximated from shallow information. If the model is highly sensitive to deep computation, the benefit of truncation will be limited and the quality cost will be high.

    The second risk is training cost. The writer component requires distillation training, and the training data must cover the actual business use. If the business scenario differs substantially from the training data, online quality may drop noticeably.

    The third risk is the accumulation of numerical error. Low-rank approximation error is small at each step but adds up over long conversations. Validation should use sessions long enough to expose this effect, not only short samples.

    Before deciding whether to adopt this approach, check the following in order: whether the model has a hybrid structure and whether the recurrent state accounts for a significant share of the cost; which stage, prefill or decoding, is the actual bottleneck; whether the evaluation includes tail latency; and whether the quality regression set covers the long-context and multi-turn scenarios of the target business.