Writing Memory Without Running the Whole Network: Optimizing LLM Inference Throughput

    Large language model inference has distinct prefill and decode bottlenecks. Prefill encodes input context into KV cache and recurrent states for later token generation, while decode reads and updates those states at every step. This article describes a layered memory-write and state-compression approach that keeps the original model weights frozen. It covers layer truncation with a lightweight memory writer during prefill, principal-component plus low-rank decomposition of recurrent state during decode, distillation-based training, quality assurance, reported throughput gains under specific configurations, and deployment boundaries.

    Writing Memory Without Running the Whole Network: Optimizing LLM Inference Throughput

    Large language model inference is typically divided into prefill and decode phases. The prefill phase processes the entire input and builds the KV cache and recurrent states needed for subsequent token-by-token generation. The decode phase reads and updates those states for every generated token. Conventional practice assumes that “writing memory” and “predicting the next token” require the same depth of network computation, but the two tasks do not have exactly the same objective. This article examines a layered write and state-compression approach that reduces prefill computation and decode-state read/write overhead without changing the original model weights, and it discusses where the gains come from, how quality is protected, and what engineering boundaries apply.

    1. Problem Background: Prefill and Decode Have Different Cost Structures

    The core task of the prefill phase is not to directly output the final answer. It is to encode the input context into memory that later generation can reuse. For standard Transformer or hybrid-architecture models, this means producing a KV cache at every layer. For models with recurrent states, it also means maintaining recurrent state. The longer the input, the deeper the model, and the larger the batch, the higher the prefill computation and memory-write bandwidth.

    Decode is a different kind of bottleneck. For every generated token, the model must read historical cache and recurrent state, update them, and write them back. Matrix computation may not be the only limit at this point. State read/write bandwidth, memory footprint, and scheduling overhead gradually become constraints on end-to-end output rate. Optimization therefore needs to target two paths separately: “prefill memory writing” and “decode state read/write,” rather than simply reducing layers or compressing context.

    2. Core Observation: Writing Memory Does Not Require Full Deep Computation

    The key observation is that writing memory for later generation can require much less deep computation than predicting the next token. The goal of prefill is to construct cache and state that decode can use, not to make a high-quality next-token prediction at every input position. Deep layers are important for semantic abstraction and next-token prediction, but their marginal benefit for “writing existing representations into cache” may be lower.

    As a result, most input tokens can use layered truncation: run only the first several layers, then use a lightweight memory-writing component to generate KV cache and recurrent state for the remaining layers. The last token usually needs special handling because it is closer to the generation starting point; keeping the full path helps maintain consistency of the initial decode state. The generation phase still runs every token through the full set of layers, so the expressive capacity of the main generation path is unchanged.

    Consider a 48-layer model configuration. All tokens except the last can run only the first 31 layers, and a lightweight component generates cache and recurrent state for the remaining 17 layers. The last token does not use this truncation strategy. In this way, most tokens in prefill skip the deep computation of the last 17 layers, while decode still uses all 48 layers. The layer allocation is not a fixed rule. It is a hyperparameter that must be adjusted according to the functional distribution of model layers, task type, and quality-regression results.

    3. Prefill Optimization: Layer Truncation and a Lightweight Memory Writer

    The flow can be summarized as follows: after input embedding, the input passes through the front layers to obtain intermediate hidden states. For non-final tokens, the lightweight writer predicts the KV cache and recurrent state needed by later layers from the intermediate hidden states. The final token takes the full path. The cache and state are then merged and passed into decode. Pseudocode:

    1. def prefill_with_memory_write(tokens, model, front_layers):
    2. hidden = embed(tokens)
    3. hidden_front = run_layers(hidden, model.layers[:front_layers])
    4. # Keep the full path for the last token to avoid bias at the generation start
    5. tail_state = run_full_path(tokens[-1], model)
    6. # The lightweight component fills later-layer memory only for non-final tokens
    7. kv_tail, recurrent_tail = memory_writer(hidden_front[:-1])
    8. kv_cache = merge_cache(hidden_front[:-1], kv_tail)
    9. recurrent_state = merge_state(hidden_front[:-1], recurrent_tail)
    10. return kv_cache, recurrent_state, tail_state

    The lightweight memory writer is not an arbitrary plug-in “approximate layer.” It is trained by distillation to fit the cache and state of the full network on representative data. The original model weights remain frozen throughout, and only the new components are trained, so the main model’s capabilities are not directly rewritten. The training objective should cover cache numerical error, state consistency, and final generation quality, rather than only minimizing the intermediate representation error of a particular layer.

    The benefits come from three areas: reducing floating-point computation in the later prefill layers; lowering memory writes for cache generation in those layers; and shortening the critical path of long-input prefill. The cost is an additional component and training pipeline, plus careful validation of the truncation ratio, last-token strategy, and cache-merge logic.

    4. Decode Optimization: Principal Component and Low-Rank Decomposition of Recurrent State

    There is another opportunity on the decode side. The recurrent state read and written at each step often contains a principal component that is close to a fixed direction, while the remaining content has a low-rank structure. In other words, the larger component of the state has a stable direction, and the part that actually changes is concentrated in a lower-dimensional subspace. Materializing and reading/writing the entire state at every step creates unnecessary memory footprint and bandwidth consumption.

    This approach stores state in a decomposed form: a principal component plus a low-rank residual. The model reads and updates the decomposed representation directly. During updates, it does not need to first restore the full matrix and then compress it; state evolution and reading are performed in the decomposed form. This reduces both per-request state footprint and the amount of state moved at each step. In a measurement on a specific model configuration, the per-request recurrent state dropped from 113.2 MB to about 29.2 MB after compression, with an average of about 43.4 MB over the full compression cycle. The 43.4 MB average means that not all moments are at the minimum compressed state; scheduling and update processes still create transient peaks. Engineering planning therefore needs to account for both cycle peaks and average footprint.

    Pseudocode:

    1. def decode_step_decomposed(state, token, model):
    2. principal, low_rank = state
    3. principal, low_rank = update_in_decomposed_form(
    4. principal, low_rank, token
    5. )
    6. logits = model.forward_with_decomposed_state(
    7. token, principal, low_rank
    8. )
    9. return logits, (principal, low_rank)

    The choice of low-rank rank is a trade-off between accuracy and benefit: a rank that is too high limits compression gains, while a rank that is too low can cause state drift in long-context and complex reasoning tasks. In practice, regression testing should account for task distribution, context length, and number of decode steps.

    5. Training and Quality Assurance: Freeze Main Weights, Distill New Components

    This approach does not change the original model weights. New components are obtained through distillation training. Distillation signals come from the cache, recurrent state, and output behavior of the full network on representative data. This treats “memory produced by full deep computation” as the teacher signal, allowing the lightweight writer to learn how to fill in the information needed by later layers with less layer computation.

    Quality evaluation needs to cover multiple models and multiple checkpoints. The original work mentions quality evaluation across five model types and six checkpoints to examine the accuracy cost of these changes. Production deployment should also add scenarios such as long context, code generation, multi-turn conversation, and structured output, while monitoring cache consistency, state drift, first-token latency, and long-sequence generation stability. Reporting throughput without quality regression does not provide reproducible deployment value.

    6. Performance Results and Sources of Benefit

    In an evaluation on a specific GPU, inference serving stack, and agentic coding session traces, the approach raised peak per-GPU throughput of the target model by 16%–42%. At the same P90 end-to-end user output rate comparison point, throughput improved by 23%–42%. These figures should be understood as observations under specific configurations, not as universal promises for all models and workloads.

    The gains mainly come from reduced prefill computation, lower cache-write bandwidth, and compressed decode-state read/write. Actual gains depend on model depth, front/back layer split ratio, batch size, context length, session traces, and hardware memory bandwidth. Scenarios with long input, high concurrency, and a high share of state read/write are more likely to show gains. Short-input, small-batch, or compute-bound scenarios may see narrower gains.

    7. Deployment Guidance and Applicability Boundaries

    Before deployment, profiling should identify the time share of prefill versus decode, and then determine the optimization focus. If prefill dominates, evaluate layer truncation and the lightweight writer first. If decode state bandwidth dominates, evaluate state decomposition and low-rank compression first. The truncation ratio, last-token strategy, low-rank rank, and compression cycle all need to be determined jointly through end-to-end SLOs and quality regression.

    The method is not unconditionally applicable. Models with uneven layer-function distribution, high sensitivity to deep representations, or obvious long-context state drift need more conservative truncation ratios and higher-rank state representations. Insufficient training of new components also carries a quality cost. A gray rollout is recommended: validate throughput, P90 output rate, and quality metrics on a small traffic share first, then expand gradually.

    Overall, the value of this approach is that it separates “writing memory” from “predicting the next token.” Prefill can complete memory writing with less deep computation, decode can reduce read/write overhead with decomposed state, and the generation phase still retains full-layer computation. For teams that want to improve inference throughput without retraining the main model, this is an engineering path worth evaluating.