Deep Memory Writes and State Compression for LLM Throughput

    This article examines a serving optimization strategy for large language models in long-context, coding-agent, and multi-turn dialogue workloads. It separates prefill computation into memory writing and next-token prediction, applies a lightweight write path to most input tokens, and keeps the final input token on the full network. It then describes low-rank compression of recurrent state during decoding, including a concrete 48-layer example, and discusses system-level throughput effects, quality risks, evaluation dimensions, deployment considerations, measured throughput ranges, and suitable workloads. Readers gain a structured view of how compute skipping and state compression can work together to raise per-GPU throughput while preserving the full decode computation path.

    Deep Memory Writes and State Compression for LLM Throughput

    In long-context, intelligent coding, coding-agent, and multi-turn dialogue scenarios, large model inference is typically constrained by two types of resources. First, the prefill stage must process a large number of input tokens, and computation grows rapidly with context length. Second, the generation stage repeatedly reads and writes recurrent state and KV cache, so memory capacity, bandwidth, and memory-access efficiency directly affect concurrency.

    Traditional inference flows often assume that every input token must pass through the full model network. For models with multi-layer mixed structures, this approach is simple to implement but may not fully match actual task requirements. The main goal of the input stage is to build context memory for later generation, not to immediately output a final prediction for every position. If the computation depth required for “writing memory” is lower than the depth required for “next-token prediction,” there is room to skip some deep computation.

    1. Splitting Prefill Computation into Two Task Types

    Consider a model with 48 layers. In a conventional flow, every token in the input sequence passes through all 48 layers in order, eventually forming full intermediate representations, KV cache, and recurrent state.

    A more efficient approach is as follows: for most tokens in the input stage, execute only the first 31 layers. A lightweight memory-write module then generates the KV cache and recurrent state required by the last 17 layers based on the existing representations. The last token in the input sequence still needs to complete the full 48-layer computation so that it produces an accurate starting point for the next generation step.

    The key to this design is not simply reducing the number of network layers, but re-distinguishing two computation goals:

    1. Memory writing: compress and organize input content into a state that later generation can read.
    2. Next-token prediction: combine the full context to compute the most accurate output distribution for the current moment.

    Both rely on model representations, but they differ in sensitivity to computation depth. Memory writing focuses more on whether information is effectively retained, while next-token prediction requires representations to go through the full transformation. By introducing a lightweight write path, the total prefill computation can be reduced without changing the full computation logic of the decode stage.

    Note that this approach does not mean later generation runs only part of the network. After entering the decode stage, every newly generated token still passes through the full network to maintain the model’s expressive capability and output quality. The optimization therefore focuses on input processing rather than directly weakening single-step generation capability.

    2. Why Prefill Optimization Can Improve Overall Throughput

    In server-side inference, prefill and decode have different performance characteristics.

    Prefill is usually a compute-intensive process. The system needs to process a batch of input tokens at the same time, matrix computation scale is large, and GPU compute-unit utilization is high, but long contexts introduce noticeable latency. Decode proceeds token by token. Per-step computation is relatively fixed, but it frequently accesses cache and recurrent state, making it susceptible to memory bandwidth and memory-access latency limits.

    Reducing the deep-network passes that input tokens go through can lower the prefill compute peak and shorten the wait before a request enters the generation stage. When the serving system uses continuous batching, shorter prefill time can also reduce blocking of other requests, allowing the scheduler to mix requests in different stages more flexibly and thereby improve per-GPU throughput.

    However, higher throughput does not necessarily mean a proportional drop in single-request latency. Actual benefits depend on the following factors:

    • The ratio of input length to output length;
    • Request concurrency and batching strategy;
    • GPU compute capability and memory bandwidth;
    • Read/write frequency of recurrent state;
    • Tail-latency constraints such as P90 or P99;
    • Whether the serving system is affected by scheduling, communication, or memory fragmentation.

    Therefore, evaluation should not look only at offline computation volume. It should also track end-to-end output rate, time to first token, tail latency, and throughput under stable concurrency.

    3. Recurrent State Compression During Decode

    In addition to prefill computation, recurrent state during the decode stage can also become a memory bottleneck. For some mixed-architecture models, state is not completely randomly distributed but shows clear structural characteristics:

    • There is a high-energy principal component with a relatively stable direction;
    • The remaining information is usually concentrated in a lower-dimensional subspace;
    • State changes across different time steps have some continuity.

    Based on this observation, recurrent state can be represented as a combination of “principal-direction component + low-rank residual,” rather than directly storing the full high-dimensional tensor. During inference, the system reconstructs or approximately reads the state from the decomposed parameters. During updates, it also only needs to update principal-component-related information and the low-rank residual.

    The form can be abstracted as:

    1. state ≈ basis × coefficient + residual

    Here, basis represents the stable principal directions or low-dimensional basis, coefficient stores the current state’s projections on these directions, and residual supplements details that cannot be explained by the principal directions. If the rank of the residual is much lower than the original state dimension, storage space and read/write data volume can be significantly reduced.

    Taking a 48-layer mixed-architecture model as an example, the raw recurrent state for a single request is about 113.2 MB. With a compressed representation, the state immediately after compression can drop to about 29.2 MB. Considering state updates, temporary buffers, and dynamic changes at different time points, the average occupancy over the entire compression cycle is about 43.4 MB. The average value here is higher than the instantaneous compressed size, indicating that an engineering implementation still needs to reserve extra space for updates and reconstruction.

    4. System-Level Benefits of State Compression

    The benefits of state compression are not limited to “being able to store more requests.” They also affect how the entire inference system operates.

    1. Higher Concurrency Capacity

    When per-request state occupancy falls, the same GPU can hold more active sessions. This is especially useful for multi-turn dialogue, long-running agents, and continuous generation tasks. Memory no longer becomes the concurrency limit too early, and the scheduler can reduce request evictions or batch splits caused by insufficient space.

    2. Lower Memory-Access Pressure

    During decode, each generated token may require reading and updating recurrent state. When state size shrinks, the amount of data that must be moved per step decreases, which helps relieve memory bandwidth pressure. In scenarios where computation is not the primary bottleneck, this benefit may be more noticeable than reducing compute.

    3. Better Batching Stability

    Uncompressed state can easily cause large differences in memory occupancy across requests, and batch scaling can more easily produce fragmentation. With a uniform compressed format, state management becomes more regular, which helps memory-pool reuse and dynamic batching.

    4. Lower State Migration Cost

    When requests need to migrate between different compute devices, or when the serving system performs load balancing, smaller state data can reduce transfer time. Before migration, however, it must be confirmed that the target device supports the same state format, quantization precision, and reconstruction process; otherwise, extra conversion overhead may be introduced.

    5. Quality Risks and Evaluation Methods

    Any approach that reduces computation or compresses state may cause accuracy loss. This is especially true in the memory-write stage. If the skipped deep computation contains critical modeling of long-range dependencies, boundary conditions, or special formats, the model may show degraded context understanding, worse factual consistency, or more code-generation errors.

    Therefore, evaluation should not use only a single task or average accuracy. It should cover at least the following dimensions:

    • General knowledge and reasoning tasks;
    • Long-context retrieval and information localization;
    • Multi-turn dialogue consistency;
    • Structured output and format following;
    • Code completion, modification, and bug fixing;
    • Multi-step tool calls by coding agents;
    • State stability in long-sequence generation.

    For deployed systems, results should also be compared under different context lengths, output lengths, and concurrency levels. Quality evaluation can be performed on multiple model checkpoints to confirm that the method is not effective for only one training stage. If the compression ratio is fixed, different compression cycles should also be tested to observe whether errors accumulate after repeated state compression and reconstruction.

    6. Key Engineering Considerations for Deployment

    First, the memory-write module needs to work with model training or calibration. If layers are forcibly truncated only at inference time, it is usually difficult to guarantee output quality. A more robust approach is to let the model adapt to the new memory-generation path during training, distillation, or calibration.

    Second, the compression format needs explicit precision boundaries. Principal directions, low-rank coefficients, and residuals can use different numeric precisions, but the safe range must be determined through error analysis. It cannot be decided solely based on compression ratio.

    Third, compression and reconstruction themselves have costs. If compression is too frequent, or if it requires a large number of extra matrix operations, it may offset the benefits of memory savings. A reasonable compression cycle should be set according to the request lifecycle, balancing memory occupancy, memory-access overhead, and compute overhead.

    Fourth, the scheduling system must understand the lifecycle of compressed state. State creation, update, compression, restoration, and release should all be included in unified memory management. Otherwise, problems such as excessively high temporary peaks, severe memory fragmentation, or request-switching jitter may occur.

    Fifth, performance evaluation should use end-to-end metrics. Experimental results for similar approaches show that under specific GPUs, inference runtimes, and coding-agent session traces, peak throughput per GPU can improve by about 16% to 42%. At comparison points that maintain the same P90 user end-to-end output rate, throughput improves by about 23% to 42%. These results indicate that the real gains come from the combined effect of reduced prefill computation, lower state occupancy, and improved batching efficiency, rather than from a single local optimization. Specific numbers still vary with hardware, model, input distribution, and serving configuration, and cannot be directly treated as guarantees for all production environments.

    7. Suitable Scenarios and Future Directions

    This type of method is especially suitable for applications with long input contexts, long output durations, large session-state footprints, many concurrent requests, or high sensitivity to GPU memory utilization. For requests with very short input and very short output, the benefits of prefill optimization and state compression may not be enough to cover the extra management overhead.

    Future work can continue in three directions:

    1. Dynamically choose memory-write depth based on input difficulty, rather than using a fixed number of layers;
    2. Adaptively adjust the low-rank order and compression frequency based on the magnitude of state changes;
    3. Jointly optimize computation skipping, state compression, continuous batching, and scheduling policy.

    Overall, “writing memory” and “completing prediction” do not have to use exactly the same computation path. By re-examining the task goals of the prefill stage and exploiting the low-rank structure in recurrent state, it is possible to reduce deep computation, lower memory occupancy, and improve serving throughput while preserving model quality as much as possible. This provides a generally applicable optimization approach for efficient deployment of long-context and agentic large models.