Multi-Round Decoding: KV Cache Design and GPU Memory Management
Multi-round decoding increases effective reasoning depth by repeatedly processing hidden states, but naively duplicating key-value caches can make long-context inference prohibitively expensive. This article explains why KV memory grows across rounds, compares full per-round caching, distant-cache reuse with local sliding windows, and shared-memory architectures, and outlines how to align training, inference, quantization, scheduling, and cache lifecycles with these design choices.
Iterative decoding does not simply make a network deeper. Instead, it lets a fixed set of parameters process the same hidden state multiple times. For long-context models and multi-step agents, the main deployment bottleneck is often not peak compute but the key-value cache. As the sequence grows, KV memory increases linearly with the number of layers, attention heads, and context length. If the same layers run for a second or fourth round, a naive implementation can multiply that memory by the number of rounds.
The following sections explain the underlying mechanisms, engineering trade-offs, and workload constraints.
Where the Problem Comes From
In a decoder-only autoregressive model, every layer stores keys and values for each previously seen position. During prefill, these entries are written in one pass. During decoding, new tokens are appended while the cache avoids recomputing the history. For a single forward pass, this design is efficient: the history is stored once, and incremental cost is proportional to the number of new tokens.
Recurrent execution changes what “one copy of the history” means. When the same layers run again, the queries have changed, so the keys and values that attention needs are no longer necessarily equivalent to those from the first round. If each round receives a separate full-length cache under the standard caching strategy, the memory used by recurrent layers roughly doubles for two rounds and grows further with additional rounds.
When context lengths increase from tens of thousands to hundreds of thousands or millions of tokens, this is not a minor constant-factor issue. It can determine whether the model fits on a single GPU or within one machine. At the same time, the benefit of recurrence mainly comes from additional nonlinear transformations and cross-position mixing. It does not always require every round to retain a complete, full-precision cache covering the entire context.
Separating “history that must be remembered” from “temporary local state needed by the current round” is the basis for the techniques discussed below.
Why Naive Recurrence Is Expensive
Assume that several contiguous layers from a large backbone are run twice while the remaining layers run once. The additional memory is concentrated in the recurrent layers:
- Global KV cache: Its length is close to the full sequence length, and its size scales with the number of layers and rounds.
- Activations and communication: The second round cannot simply reuse the intermediate results from the first. Pipeline execution must manage separate lifetimes for different rounds of the same layer.
- Index consistency: If sparse-attention indices are rebuilt for every round, index construction can consume the efficiency gained by reusing parameters.
In practice, the common compromise is not “store everything” versus “store nothing.” Instead, the cache is managed according to distance.
Long-range dependencies usually change more slowly, so the sparse KV entries written during the first round can often be reused. Short-range dependencies change quickly with the current hidden state, so the second round can retain only a bounded sliding window of local KV entries. Sparse indices can also be reused across rounds and updated incrementally within the sliding window.
This prevents global cache capacity from scaling strictly with the number of rounds. However, the system must maintain several types of state at once: the historical sparse table, the current sliding window, the round identifier, and the eviction policy. The implementation becomes more complex, and boundary tokens are more likely to suffer from attention gaps or inconsistent behavior.
Move Memory Forward and Recurrence Backward
A cleaner approach is to change which part of the network owns the global KV memory.
The front section of the network processes the input and sees the complete context. It writes a reusable global representation and performs any required compression or projection. The back section no longer maintains a full-context cache for every layer. Instead, it uses a fixed mapping to obtain keys and values from the front section’s output or from a shared memory. The back section keeps only the hidden states in the computation graph and, optionally, a very short local cache.
Placing multi-round recurrence in the back section has several direct effects.
Global memory becomes independent of the number of rounds
Whether the back section runs two, four, or more times, the additional cost is compute and a small amount of activation memory—not another million-token KV cache. Long-context capacity now depends primarily on the precision, head dimension, and hierarchical compression of the front section’s memory rather than on recurrence depth.
Attention responsibilities are separated
The front section answers, “What is present in the context?” The back section answers, “How should the model reason over this memory for additional steps?”
In agent workloads, tool results, plan revisions, and self-correction often require multiple internal reasoning passes over the same context. They do not necessarily require copying the full-context cache after every reasoning step. A recurrent back section matches this pattern of fixed memory and deeper reasoning.
The mapping must be learnable and stable
The back section’s queries change, while its keys and values come from fixed representations produced by the front section. The model therefore depends on the mapping retaining sufficient positional and semantic information.
In practice, the mapping generally includes:
- A linear projection from shared memory to multi-head keys and values
- Learnable scaling between layers
- A short local sliding window for tokens produced during the current round but not yet written back to global memory
The window length should be aligned with the prefill block size and decoding step size. This avoids a full global synchronization on every step.
Choosing Among Three Strategies
The design space can be summarized in three strategies. The choice should be based on system constraints rather than slogans.
Full per-round caching
This is the most straightforward implementation. Its attention behavior remains closest to standard single-pass decoding, making it suitable for short contexts, a small number of recurrent layers, and controlled ablation studies. It is not a good default for million-token contexts.
Distant-cache reuse with a local sliding window
This keeps global memory bounded but requires careful handling of reused indices, merging the sliding window with sparse tables, and distribution differences between rounds. It is appropriate for teams that already have sparse-attention infrastructure and want to preserve most of the existing model topology.
Write memory once in the front section and read it repeatedly in the back section
Global memory no longer scales with the number of rounds, and the system boundary is clearer. The trade-off is that the back section no longer has an independent full-context memory. Model capacity must instead come from recurrence depth, mapping quality, and the local window. This design is particularly suitable for agents that process long inputs and perform multiple internal reasoning steps, rather than tasks in which every layer must independently remember the entire history.
No strategy is simultaneously optimal for quality, memory usage, and throughput. If evaluation shows that recurrence mainly improves multi-hop reasoning rather than retrieval, the third strategy is a better fit. If the task depends heavily on fine-grained memory unique to each layer, reduce the number of recurrent layers or enable sliding-window caching only for selected layers instead of simply adding more rounds.
Training and Inference Must Be Designed Together
Adding recurrence only during inference while training the model as a single-pass stack creates a distribution mismatch. A more robust approach is to sample the number of rounds during training, either randomly or through a curriculum. This allows the back section to adapt to reading the same memory with different queries multiple times.
Light auxiliary supervision can also be applied to intermediate rounds so that all learning signals are not concentrated in the final round. During inference, the number of rounds can serve as a latency control: use fewer rounds for simple requests, more rounds for complex planning, and stop when the time budget is reached.
Cache lifetimes should also be part of the serving protocol. The front section’s memory can be reused within a session. When tool results are appended, only incremental writes are needed. By contrast, the sliding window produced by the back section should normally be discarded after the recurrent process and should not enter the session-level cache.
This is important for multi-user concurrency. The expensive state should be one shared memory for a common prefix, not a private full-context cache for every user and every round.
Quantization should generally be applied first to the front section’s global KV memory, followed by dedicated validation of long-range retrieval quality. The back section’s sliding window is short, so quantization provides less benefit. Excessive compression can instead damage local consistency during recurrence.
Scheduling should separate prefill from recurrent decoding. Prefill writes memory and is bandwidth-intensive. Recurrent decoding reads memory and is more compute-intensive. Mixing both workloads in the same batch can allow long prefixes to block short requests. Batching by memory readiness is often more effective than simply increasing batch size.
A Minimal State Partition
The following pseudocode illustrates the state boundaries. It is not an interface for any specific framework.
memory = front_layers.encode(prompt) # Write global KV memory oncestate = project(memory)for step in range(max_loops):local = sliding_window(state, width=w) # Local context for this round onlystate = back_layers(state, memory, local)if stop(state, budget):break# memory can persist across rounds; local is released after recurrence
This logic emphasizes three points:
- Global memory is written a constant number of times.
- The loop variable is the hidden state, not a full-context cache.
- The stopping condition depends on both the budget and intermediate state rather than always running the maximum number of rounds.
Metrics to Check Before Deployment
To determine whether recurrence is worthwhile, evaluate at least four metrics rather than looking only at parameter count or single-pass perplexity.
- KV bytes per unit of context length: Check whether memory usage changes with the number of rounds.
- Long-range retrieval: Measure recall when the model reads shared memory, ensuring that the mapping does not erase distant evidence.
- Reasoning gains by round: If improvements saturate quickly after two rounds, there is little reason to support eight rounds.
- Tail latency: Include the rate at which failed index reuse falls back to full computation.
If any metric becomes unstable, first reduce the sliding-window size, decrease the number of recurrent layers, or lower memory precision. Do not automatically add more optimization techniques or rounds.
Conclusion
The value of recurrent decoding is that repeated computation can provide greater effective depth. Its risk is that KV memory may be duplicated along with that computation.
Reusing distant sparse KV entries and maintaining a local sliding window can reduce memory growth, but they introduce a more fragmented state machine. A more structured alternative is to consolidate global memory in the front section and let the back section repeatedly read it through a learned mapping. This keeps global memory from growing with the number of rounds and better matches long-context agent workloads in which the model repeatedly reasons over the same input.
The right design should be judged by whether cache usage grows with recurrence, whether long-range retrieval remains reliable, and whether additional rounds continue to improve the task—not by the number of layers or rounds alone.
