LLM Inference Memory Writes Without Full-Network Forward Passes

    This article explores how to decouple memory writes from next-token prediction during LLM inference to reduce compute waste. It covers two core techniques: layer-truncated KV cache writes during prefill and low-rank compression of recurrent states in hybrid architectures. It also outlines engineering considerations such as layer calibration, state lifecycle management, scheduling, accuracy gating, and observability, along with reported throughput gains and trade-offs.

    1. Background: The Compute Mismatch Between Prefill and Decode

    In LLM inference serving, a request typically goes through two phases: prefill, which processes the entire input, and decode, which generates output token by token. The two phases have completely different compute profiles. Prefill is compute-intensive and runs all layers in a single pass. Decode is memory-bandwidth-intensive: each step produces only one token but still reads all weights and states.

    A common observation in the industry is that the compute required to “write memories for the future” can be far less than the compute required to “predict the next token right now.” The output of prefill is caches and states that serve the next dozens or hundreds of generation steps, while each step in the generation phase must perform a high-quality next-token prediction. Using the same deep forward pass to satisfy both needs wastes compute.

    2. Core Idea 1: Layer-Truncated Cache Writes

    Suppose the model has L layers in total (for example, 48 layers). The traditional approach runs all input tokens through all L layers and writes a complete key-value cache (KV Cache) and recurrent states. The improved approach is:

    • All input tokens except the last one run only the first k layers (for example, 31 layers);
    • A lightweight “memory write component” fills in the caches and recurrent states required for the remaining L-k layers;
    • During generation, each token still runs all L layers to ensure output quality.

    Illustrative pseudocode:

    1. # L: total number of layers, k: prefill truncation layer
    2. def prefill(tokens):
    3. h = embed(tokens)
    4. for i in range(k): # run only the first k layers
    5. h = layer[i](h)
    6. cache, recurrent = write_memory(h) # lightweight write component
    7. return cache, recurrent
    8. def decode(step_state):
    9. h = step_state
    10. for i in range(L): # decode runs all layers
    11. h = layer[i](h)
    12. return sample(h), update_state(h)

    The key point is that truncation applies only to prefill, not to decode, and only to non-final positions, because the final position participates in the first generation step immediately and needs a more complete representation.

    3. Core Idea 2: Low-Rank Compression for Recurrent State Access

    Hybrid architecture models read and write recurrent states at every step. Such states often have a dominant component close to a fixed direction, with the remainder exhibiting low-rank structure. Therefore, the state can be maintained in a decomposed form of “dominant component + low-rank correction,” and the model can read and update directly in this form, avoiding materializing the full state at every step.

    Illustration:

    1. # S ≈ u * c + U_r @ V_r
    2. def read_state(u, c, U_r, V_r):
    3. return u * c + U_r @ V_r
    4. def update_state(u, c, U_r, V_r, delta):
    5. # The dominant component direction is approximately fixed; update only the coefficient and low-rank terms
    6. c = c + proj(u, delta)
    7. V_r = V_r + proj(U_r, delta)
    8. return u, c, U_r, V_r

    The benefits are twofold: lower memory usage and lower memory access volume. Since decode is already memory-bandwidth-bound, state compression is especially friendly to decode throughput. It should be emphasized that the compression ratio is strongly correlated with quality loss, and the rank r and dominant component update frequency should be determined using a calibration set.

    4. Engineering Implementation

    1. Layer calibration: Use representative corpora to measure the gap between “depth required for memory writes” and “depth required for prediction,” and determine the truncation layer k. This varies significantly across model families.
    2. State lifecycle management: A clear strategy is needed for when to refresh and merge the dominant component and low-rank factors to avoid error accumulation.
    3. Batching and scheduling: After prefill becomes shorter, request queuing and batch assembly strategies must be adjusted accordingly; otherwise, the bottleneck shifts to the scheduling layer.
    4. Accuracy gating: Establish layered evaluation (perplexity, downstream tasks, long-context consistency) and run regression checks at each checkpoint.
    5. Observability: Set up monitoring and alerts for cache hit rate, state compression ratio, and P90 end-to-end output rate, and connect the troubleshooting chain with common capabilities such as logging services and monitoring alerts.

    5. A Rational View of Benefits and Costs

    In terms of single-card throughput, this type of optimization typically brings a gain of about 16% to 42%. At an equivalent benchmark point with a fixed P90 user end-to-end output rate, the gain is about 23% to 42%. The range difference comes from model structure, input length distribution, and concurrency pressure. On the cost side, both prefill approximation and state compression introduce controllable errors, so evaluation data must decide whether to enable them and to what extent.

    6. Conclusion

    Decoupling “writing memories” from “making predictions” is a high-leverage entry point for inference optimization: prefill runs only shallow layers plus lightweight writes, while decode maintains full depth; recurrent states are accessed in a dominant-component-plus-low-rank form. Combined, these two techniques can deliver significant per-card throughput gains on general hybrid large models while keeping accuracy risks measurable and controllable. For teams that build their own inference services or use common infrastructure such as container platforms and object storage, this approach can serve as a default candidate for cost reduction and efficiency improvement.