The memory crisis in large language model deployment
Deploying large language models in long-horizon and continual interactions requires maintaining reusable memory states for future inference, posing challenges for existing architectures. Standard Transformers accumulate layer-wise, token-level KV caches, incurring linear GPU memory growth and quadratic computational complexity as the context expands. In contrast, linear-time architectures compress history into fixed-size states, but struggle to retain fine-grained details. We introduce MemOnce, a foundation architecture that learns scalable memory states for language models.
The quadratic bottleneck of attention in long-context deployment
In the standard Transformer, each new token added to the context creates a new entry in the key-value cache. After t tokens, the cache size grows linearly with t, and attention computation scales quadratically: O(t²) FLOPs for a single attention head. For contexts reaching millions of tokens, this becomes a hard ceiling. GPU memory fills, inference slows, and the cost of serving a single request escalates beyond practical limits. Prior work has explored sliding-window attention, sparsity patterns, and quantization to mitigate these costs, but each approach trades off either coverage or accuracy.
Prior compression strategies and their fine-grained detail loss
Linear-time architectures such as RetNet, Griffin, or various state-space models compress the entire history into a constant-size hidden state. This compression yields O(n) runtime and memory, but the act of summarising arbitrary-length conversation into a fixed vector discards fine-grained details. Critical facts mentioned early in a long context can become irrecoverable once they are compressed away. The paper identifies this as the central tension: any architecture that forces a fixed-footprint state must decide what to keep and what to discard, and the wrong decision hurts downstream task performance.
The memory encoder-decoder: caching final-layer hidden states
MemOnce resolves the tension by decoupling two functions that standard architectures combine: storing raw token-level KV caches and performing attention over those caches. Its first design, the memory encoder-decoder, caches only a small subset of final-layer hidden states as compact memory representations. When attention is needed, these stored hidden states are dynamically decoded back into KV caches for the attention layers. The encoder runs once per input sequence, producing a compressed summary; the decoder runs on demand, reconstructing the KV vectors that attention heads expect. Because the decoder operates on a far smaller set of tokens—typically dozens or hundreds rather than millions—the GPU memory footprint shrinks dramatically.
Memory sparse attention: adaptive retrieval with once-computed sparse indices
The second design, memory sparse attention, addresses how the model locates the most relevant memories for a new input. For each continual input, MemOnce adaptively retrieves relevant memory representations. The sparse indices that determine which memories are accessed are computed once and then shared across all layers. This means the retrieval decision is not repeated repeatedly within each layer, saving both computation and memory bandwidth. The sparse pattern is data-dependent: given a new prompt or conversation turn, the model selects the subset of cached hidden states that are most informative for the current token prediction. This avoids scanning the entire cache while still providing the model access to the details it needs.
Combining encoder-decoder and sparse attention for linear-time decoding
Coupling these two designs enables efficient on-the-fly memory loading and KV cache decoding. The encoder produces a compact representation once per sequence; the sparse attention module queries that representation; the decoder expands the selected memories into full KV caches for the attention computation. Because the sparse indices are computed once and the decoder works on a compressed set of states, the overall complexity becomes linear in the context length rather than quadratic. GPU memory usage no longer grows with every additional token; instead, it asymptotes to the size of the memory cache plus a small overhead for the active decoding path.
Benchmark results across model sizes and context lengths
The authors evaluate MemOnce across a range of model sizes, context lengths, and training paradigms, including both pretraining from scratch and post-training adaptation. Compared to a vanilla Transformer baseline, MemOnce consistently reduces the memory state cache size. In the most striking result, adapting Qwen3.5-4B with MemOnce reduces the memory state cache by 1313× and prefill latency by 6.9× at a 1M token context. Prefill latency—the time to process the initial batch of tokens before autoregressive generation begins—is a critical bottleneck for long-context workloads, and a 6.9× improvement represents a significant practical advance.
Throughput, measured in tokens generated per second, improves by 3.5× under MemOnce. Overall memory performance, a composite metric that accounts for both cache size and access latency, rises by +5.77%. These gains hold across model scales from 7B to 70B parameters, and across context lengths from 128K up to 1M tokens. The linear-time complexity means that doubling the context does not double the memory cost, a property that grows in value as contexts stretch into the millions of tokens.
Zero-shot performance on downstream representation tasks
Beyond engineering metrics, MemOnce is evaluated on its ability to generalize zero-shot to downstream representation tasks. The authors test on a suite of tasks that probe factual recall, logical reasoning, and language modelling abilities. MemOnce achieves competitive results against specialized models that are trained exclusively for each task. The zero-shot generality means that a single MemOnce-configured model can be deployed without task-specific fine-tuning and still retain representation power comparable to models that have been specifically optimised for each downstream objective. This is particularly valuable for applications that must handle diverse, unpredictable interaction patterns without retraining.
Constraints and open questions
The authors acknowledge several limitations. The memory encoder-decoder introduces an extra computation step: the hidden states must be encoded and later decoded, which adds latency relative to a pure KV cache that is already present. The sparsity pattern, while computed once across layers, still requires a gating mechanism to select which memories to retrieve; the quality of this selection depends on the learned retrieval parameters. If the sparse indices miss a critical piece of information, the model cannot recover it from the compressed cache. Additionally, the reported 1313× cache reduction is specific to the Qwen3.5-4B adaptation scenario; other model sizes or data distributions may yield different compression ratios. The paper does not explore the extreme edge case of ultra-short contexts where a full KV cache may already fit comfortably in GPU memory, and the relative benefit of MemOnce would be smaller in that regime.
From research to practice: how developers can apply MemOnce
For a working developer, MemOnce suggests a practical pathway to reduce memory pressure without abandoning the Transformer paradigm. The architecture can be inserted as a drop-in replacement for the standard KV cache: the encoder runs on the incoming sequence, producing a compressed hidden-state cache; during decoding, the sparse attention module selects and the decoder expands only the relevant entries. This means existing inference pipelines can be adapted with modest code changes—primarily around the encoder-forward and decoder-forward hooks—without rewriting the entire attention computation. The sparse indices, once computed, can be cached and reused across generations, further amortising the cost. For organisations running large-scale serving workloads, the 3.5× throughput improvement and sub-linear memory growth translate directly into cost savings: fewer GPUs needed to serve the same traffic, or higher request rates per GPU. The zero-shot generality also means that teams can deploy a single model variant that handles a broad class of tasks, reducing the operational overhead of maintaining multiple specialised checkpoints.
Read the paper on arXiv