MemOnce: A Scalable Memory Architecture for Large Language Models

Media reports Hugging Face Papers Source language: Chinese

Researchers introduced MemOnce, a scalable memory architecture for large language models that achieves linear-time complexity and dramatically reduces GPU memory…

Full text

MemOnce: A Scalable Memory Architecture for Large Language Models

Chang Nie Affiliation: Nanjing University Chaoyou Fu Affiliation: Nanjing University Songlin Liu Affiliation: University of Science and Technology of China Yiqing Hu Affiliation: University of Science and Technology of China Caifeng Shan Affiliation: Nanjing University

Abstract

Abstract

Deploying large language models (LLMs) 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. MemOnce is based on two core designs: (a) Memory encoder-decoder: it caches only a small subset of final-layer hidden states as compact memory representations and dynamically decodes them back into KV caches for attention layers; (b) Memory sparse attention: for each continual input, MemOnce adaptively retrieves relevant memory representations, with the sparse indices computed only once across layers. Coupling these two designs enables efficient on-the-fly memory loading and KV cache decoding, drastically reducing the GPU memory footprint and achieving linear-time complexity. We conduct extensive experiments to show that MemOnce outperforms Transformers and other architectures across varying model sizes, context lengths, and training paradigms (pretraining and post-training adaptation). In particular, adapting Qwen3.5-4B with MemOnce reduces memory state cache by 1313×\times and prefill latency by 6.9×\times at 1M context, and improves throughput by 3.5×\times and overall memory performance by +5.77%. Finally, MemOnce generalizes zero-shot to downstream representation tasks, achieving competitive results against specialized models.

††date: November 20, 2026††: Main Contact: changnie@smail.nju.edu.cn, bradyfu24@gmail.com††: Github: https://clare-nie.github.io/MemOnce

Figure 1: Comparison between MemOnce and advanced architectures. (Left) Memory state cache vs. context length. MemOnce activates minimal memory states during continual inference, reducing the cache footprint by orders of magnitude compared to attention-based baselines. (Right) Overall performance vs. prefill latency and decoding throughput. Compared to existing native memory models, MemOnce significantly advances the Pareto frontier, marking the first native memory approach to surpass the full-context baseline. Performance is averaged across five memory benchmarks, while prefill time and throughput are measured at a 1M context length.

1 Introduction

Memory serves as the foundation for experiential and continual intelligence (Hassabis et al., 2017; Sumers et al., 2023; Hu et al., 2025). As large language models (LLMs) transition from single-turn processing toward continual interactions and long-horizon agent tasks, maintaining reusable memory states is essential to eliminate redundant context recomputation and ensure low-latency response generation (Xi et al., 2025; Chhikara et al., 2025; Zheng et al., 2026). However, existing architectures face a fundamental trade-off between retention fidelity and inference scalability. Transformers (Vaswani et al., 2017) with global attention retain layer-wise, token-level key-value (KV) caches, incurring linear GPU memory growth and quadratic computational complexity as the context expands. In contrast, recurrent and linear models (e.g., Mamba (Gu and Dao, 2023), RWKV (Peng et al., 2023), and GDN (Yang et al., 2025)) compress history into fixed-size states to enable constant-memory, linear-time inference; yet their bounded state capacity can induce information decay, hindering the preservation of fine-grained details over long horizons (Jelassi et al., 2024).

Extensive efforts have sought to reconcile this trade-off, broadly falling into three categories: (1) Architectural and attention optimizations: hybrid models (e.g., Kimi K3 (Kimi Team et al., 2026) and MiMo-V2.6 (Qiao et al., 2026)) interleave attention and linear layers, cross-layer sharing approaches (Sun et al., 2024b; Xu et al., 2026a) reuse intermediate KV caches, and sparse attention mechanisms (e.g., DeepSeek-V4.1-Flash (Xu et al., 2026a) and Qwen3.8-Next (Qiu et al., 2026)) restrict attention to top-kk relevant tokens. However, during continual inference, they still need to maintain or access global caches that grow linearly with context length. (2) Native memory models: parametric memory designs (e.g., Titans (Behrouz et al., 2025), M+ (Wang et al., 2025a), and Metis (Zhang et al., 2026)) compress historical context into compact memory representations via specialized training or post-training adaptation. Yet, they often suffer from performance degradation, layer-wise retrieval overhead, or catastrophic forgetting. (3) External memory systems: agentic memory frameworks (e.g., Mem0 (Chhikara et al., 2025), A-MEM (Xu et al., 2026b), and PersonaVLM (Nie et al., 2026b)) organize historical context into explicit databases that can be managed, updated, and queried. Nevertheless, constructing and maintaining these discrete stores is costly (Nie et al., 2026c) and difficult to optimize end-to-end (Wang et al., 2025b).

Despite these efforts, a central question remains open: How can we build a foundational memory architecture (or adapt an existing one) to simultaneously achieve accurate recall, linear-time inference, and bounded GPU memory cache overhead for continual inference? In this paper, we propose MemOnce, an expressive yet scalable architecture that learns reusable memory states for language models. The core idea of MemOnce is to maintain a single compact global cache and retrieve relevant memory only once during continual inference to decode layer-wise KV caches, thereby enabling memory on-demand loading and decoding. Specifically, we first develop a memory encoder-decoder that caches a small subset (e.g., 1/81/8) of final-layer hidden states as compact memory representations, dynamically decoding them via lightweight MLPs into KV caches for attention layers. This design achieves cache recurrence and an Lr×Lr\times compression across both depth and time dimensions. Second, we introduce memory sparse attention, which adaptively selects the top-KK task-relevant states for each input and shares the sparse routing indices across all attention layers and decoding steps. By coupling these two designs, MemOnce achieves strong expressiveness, linear-time complexity, and a constant active memory state (see Figure 1).

We conduct extensive experiments across diverse tasks, model sizes, and context scales to demonstrate the superiority of MemOnce. Specifically, we highlight three key results: (1) MemOnce as a foundation architecture: We train MemOnce and other foundation architectures from scratch across model sizes ranging from 150M to 1B parameters. MemOnce consistently achieves lower or comparable perplexity on validation data and performs well on downstream benchmarks compared to evaluated baselines (e.g., Transformer, GDN, and YOCO (Vaswani et al., 2017; Yang et al., 2025; Sun et al., 2024b)). (2) MemOnce as a native memory model: We adapt Qwen3.5 via post-training and evaluate it on five memory benchmarks spanning 4K to 1M tokens. As shown in Figure 1, MemOnce is the first native memory model to surpass the full-context baseline (+5.77% at the 4B scale) (Qwen Team, 2026), and outperforms prior memory methods (by +18.68% over M+ (Wang et al., 2025a) and +32.27% over Metis (Zhang et al., 2026)). At 1M context, it reduces memory state cache by 1313×\times and prefill latency by 6.9×\times, and improves throughput by 3.5×\times. Moreover, MemOnce avoids catastrophic forgetting on general benchmarks by keeping its parameters frozen during inference and inherently ignoring irrelevant decoded caches. (3) MemOnce as a representation model: We show that MemOnce’s learned memory representations transfer naturally to downstream retrieval and reranking tasks, outperforming specialized models without task-specific fine-tuning. These findings underscore the potential of MemOnce as a next-generation general-purpose architecture.

In summary, our main contributions are as follows:

•

We propose MemOnce, a foundation architecture that achieves strong expressiveness, linear-time complexity, and constant active memory for continual inference.

•

We couple two designs, memory encoder-decoder and memory sparse attention, to cache and retrieve memory representations only once for on-demand memory loading and KV cache decoding.

•

We establish through comprehensive experiments that MemOnce advances the performance–complexity Pareto frontier, marking the first native memory model to surpass the full-context baseline and generalizing zero-shot to downstream representation tasks.

2 Preliminaries

Problem Setup.

Consider an LL-layer autoregressive language model πθ\pi_{\theta} with hidden dimension DD processing an input stream x1,x2,…,xtx_{1},x_{2},\dots,x_{t} (e.g., token/chunk sequences in language modeling or interaction turns in continual tasks (Zheng et al., 2026)). At step tt, the model receives the current input xtx_{t} alongside accumulated historical context x1:t−1x_{1:t-1} of total token length NN (N≥t−1N\geq t-1), and generates the target output yty_{t}. In each layer l∈{1,…,L}l\in\{1,\dots,L\}, let Hl=[h1l,h2l,…,ht−1l]⊤∈ℝN×DH^{l}=[h_{1}^{l},h_{2}^{l},\dots,h_{t-1}^{l}]^{\top}\in\mathbb{R}^{N\times D} denote the accumulated hidden states produced for x1:t−1x_{1:t-1} (where each hilh_{i}^{l} corresponds to a token or segment, totaling NN tokens), with H0H^{0} representing the token embeddings and HLH^{L} denoting the output of the final attention layer.

Unified Perspective: Memory State Learning.

We define Memory State Learning as the problem of constructing reusable, active memory states MtM_{t} for the current input xtx_{t} during continual inference, so as to avoid recomputing the raw history x1:t−1x_{1:t-1} and ensure low-latency response generation. Formally, we reformulate the context-conditioned generation of existing methods into generation conditioned on the active memory state MtM_{t}:

πθ(yt∣xt,x1:t−1)\displaystyle\pi_{\theta}(y_{t}\mid x_{t},x_{1:t-1}) =πθ​(yt∣xt,Mt),\displaystyle=\pi_{\theta}(y_{t}\mid x_{t},M_{t}), (1)

whereMt\displaystyle\text{where}\quad M_{t} ≐fθ(xt,x1:t−1).\displaystyle\doteq f_{\theta}(x_{t},x_{1:t-1}).

Here, fθ(xt,x1:t−1)f_{\theta}(x_{t},x_{1:t-1}) denotes the memory state mapping that distills the historical context x1:t−1x_{1:t-1} and activates relevant states MtM_{t} with respect to the current input xtx_{t}. Under Eq. (1), existing methods correspond to distinct instantiations of fθf_{\theta}:

•

Multi-Layer Token KV Caches (Transformers): Standard Transformers (Vaswani et al., 2017) define a query-agnostic fθf_{\theta} by activating all token-level key-value caches across all LL layers:

MtKV={(Kl,Vl)}l=1L∈ℝL×N×2​D,\displaystyle M_{t}^{\text{KV}}=\Big\{\big(K^{l},V^{l}\big)\Big\}_{l=1}^{L}\in\mathbb{R}^{L\times N\times 2D}, (2)

Kl=Hl−1WKl,Vl=Hl−1WVl.\displaystyle K^{l}=H^{l-1}W_{K}^{l},\quad V^{l}=H^{l-1}W_{V}^{l}.

While retaining fine-grained details, MtKVM_{t}^{\text{KV}} grows linearly with both depth LL and context length NN, incurring an 𝒪⁡(L​N​D)\mathcal{O}(LND) memory footprint. Even for sparse attention (Xu et al., 2026a; Qiu et al., 2026) or retrieval-based memory models (Wang et al., 2025a) that condition fθf_{\theta} on xtx_{t} to select top-kk context per layer, they still maintain multi-layer caches and compute routing indices across layers.

•

Online Associative States (Linear Models): Linear and recurrent models (Gu and Dao, 2023; Yang et al., 2025; Kimi Team, 2025) implement fθf_{\theta} by compressing history into a fixed-size state SNlS_{N}^{l} at each layer for all subsequent inputs. Specifically, representative associative linear models (e.g., GDN (Yang et al., 2025)) maintain a state matrix Sil∈ℝd×dS_{i}^{l}\in\mathbb{R}^{d\times d} updated via the online delta rule to encode key-value associations:

MtLinear={SNl}l=1L∈ℝL×d×d,\displaystyle M_{t}^{\text{Linear}}=\big\{S_{N}^{l}\big\}_{l=1}^{L}\in\mathbb{R}^{L\times d\times d}, (3)

Sil=αil​Si−1l+βil​(vil−αil​Si−1l​kil)​kil⊤,\displaystyle S_{i}^{l}=\alpha_{i}^{l}S_{i-1}^{l}+\beta_{i}^{l}\big(v_{i}^{l}-\alpha_{i}^{l}S_{i-1}^{l}k_{i}^{l}\big){k_{i}^{l}}^{\top},

where αil\alpha_{i}^{l} and βil\beta_{i}^{l} denote the erase and write gates. Although MtLinearM_{t}^{\text{Linear}} achieves 𝒪⁡(L​d2)\mathcal{O}(Ld^{2}) constant memory complexity (independent of NN) and linear-time inference, it suffers from severe capacity bottlenecks (Jelassi et al., 2024).

•

Cross-Layer Shared States (YOCO): Architectures with cross-layer KV sharing, such as YOCO (Sun et al., 2024b) and Causal Encoder-Decoder (CED) (Xu et al., 2026a), cache hidden states at an intermediate layer (e.g., L/2L/2 in YOCO) to decode KV caches for subsequent layers:

MtYOCO=HL/2∈ℝN×D.M_{t}^{\text{YOCO}}=H^{L/2}\in\mathbb{R}^{N\times D}. (4)

This design eliminates the depth factor LL, but MtYOCOM_{t}^{\text{YOCO}} still grows linearly with context length.

For the above architectures, fθf_{\theta} is implicitly learned during the optimization of πθ\pi_{\theta} and executed at test time. Moreover, for native memory models (Wang et al., 2025a; Zhang et al., 2026), fθf_{\theta} reconstructed via post-training adaptation can also be subsumed under the aforementioned categories. However, constructing an effective and scalable MtM_{t} remains an open challenge (see Appendix G for further theoretical analysis).

Figure 2: Overview of the MemOnce architecture. (Left) The Hybrid Backbone stacks linear blocks with memory sparse attention across LL stages. (Right) The Memory Encoder-Decoder caches a trailing subset (1/r1/r) of final-layer states into a persistent memory bank, partitioned into a local short-term window and a sparse long-term pool. For each incoming input, relevant memory states are retrieved only once and dynamically decoded into KV caches for attention layers. This enables a constant active
Figure 2: Overview of the MemOnce architecture. (Left) The Hybrid Backbone stacks linear blocks with memory sparse attention across LL stages. (Right) The Memory Encoder-Decoder caches a trailing subset (1/r1/r) of final-layer states into a persistent memory bank, partitioned into a local short-term window and a sparse long-term pool. For each incoming input, relevant memory states are retrieved only once and dynamically decoded into KV caches for attention layers. This enables a constant active

Figure 2: Overview of the MemOnce architecture. (Left) The Hybrid Backbone stacks linear blocks with memory sparse attention across LL stages. (Right) The Memory Encoder-Decoder caches a trailing subset (1/r1/r) of final-layer states into a persistent memory bank, partitioned into a local short-term window and a sparse long-term pool. For each incoming input, relevant memory states are retrieved only once and dynamically decoded into KV caches for attention layers. This enables a constant active memory state for continual inference, alongside an Lr×Lr\times cache compression across both depth and time dimensions.

3 MemOnce

We introduce MemOnce, a foundation architecture that learns scalable memory states MtM_{t} in Eq. (1) for efficient continual inference. Formally, MemOnce constructs and utilizes the active memory state MtM_{t} through three functions:

Gt=gθ(x1:t−1),Mt=iθ(xt,Gt),Ct=uθ(Mt),G_{t}=g_{\theta}(x_{1:t-1}),\ \ M_{t}=i_{\theta}(x_{t},G_{t}),\ \ C_{t}=u_{\theta}(M_{t}), (5)

where gθg_{\theta}, iθi_{\theta}, and uθu_{\theta} denote the memory writing, indexing, and reading operations, respectively. We instantiate Eq. (5) through two core designs: (1) the memory encoder-decoder (gθg_{\theta} and uθu_{\theta}), which caches partial final-layer states into a persistent memory bank GtG_{t} and decodes the active memory state MtM_{t} into multi-layer KV caches CtC_{t} on demand; and (2) memory sparse attention, which retrieves the relevant memory state MtM_{t} via iθi_{\theta} only once and restricts historical attention exclusively to the decoded KV caches CtC_{t}.

MemOnce is applicable to various attention-based models. In practice, as shown in Figure 2, MemOnce adopts an LL-stage hybrid backbone by default, where each stage interleaves three linear blocks (e.g., GDN (Yang et al., 2025)) with one Memory Sparse Attention block.

3.1 Memory Encoder-Decoder

To eliminate the 𝒪⁡(L​N​D)\mathcal{O}(LND) storage bottleneck of multi-layer token caches, the memory encoder-decoder compresses historical context across both layer depth LL and sequence length NN, and reconstructs layer-specific KV caches on demand.

Cache Memory Only Once (gθg_{\theta}).

Inspired by prior cross-layer caching designs (Sun et al., 2024b; Xu et al., 2026a), MemOnce maintains a single global cache generated from final-layer hidden states, encoding historical context into compact memory representations at test time. Specifically, given historical inputs x1:t−1x_{1:t-1} of total length NN, each segment xix_{i} of length nin_{i} (∑i=1t−1ni=N\sum_{i=1}^{t-1}n_{i}=N) is processed to produce final-layer hidden states hiL∈ℝni×Dh_{i}^{L}\in\mathbb{R}^{n_{i}\times D}. Within each xix_{i}, the interleaved linear blocks and causal attention continuously aggregate sequential context toward later positions, allowing the trailing token states in hiLh_{i}^{L} to encapsulate the semantics of the entire segment. Leveraging this property, the memory encoder gθg_{\theta} retains only the last 1/r1/r fraction of token states (denoted as hi,−ni/r:Lh_{i,\,-n_{i}/r:}^{L}) from each hiLh_{i}^{L} with compression ratio rr (e.g., r=8r=8), writing a total of k=⌊Nr⌋k=\lfloor\frac{N}{r}\rfloor compact memory representations into the global cache:

Gt\displaystyle G_{t} =Concat({hi,−ni/r:L}i=1t−1)\displaystyle=\operatorname{Concat}\Big(\big\{h_{i,\,-n_{i}/r:}^{L}\big\}_{i=1}^{t-1}\Big) (6)

=[m1,m2,…,mk]⊤∈ℝk×D.\displaystyle=[m_{1},m_{2},\dots,m_{k}]^{\top}\in\mathbb{R}^{k\times D}.

This step reduces the persistent memory by Lr×Lr\times, eliminating the layer multiplier LL and compressing the sequence dimension by rr. In practice, multiple segments are processed in parallel to accelerate prefilling.

Decode KV Caches on Demand (uθu_{\theta}).

Directly sharing identical KV states across layers restricts the representational capacity of attention blocks at different depths. Instead, given the retrieved active memory state Mt∈ℝ|Mt|×DM_{t}\in\mathbb{R}^{|M_{t}|\times D}, the memory decoder uθu_{\theta} applies lightweight layer-specific MLP projections KProjlK_{\text{Proj}}^{l} and VProjlV_{\text{Proj}}^{l} to decode MtM_{t} into KV caches for all LL attention layers on demand:

Kl=KProjl​(Mt),Vl=VProjl​(Mt),l∈{1,…,L}.K^{l}=K_{\text{Proj}}^{l}(M_{t}),\ \ V^{l}=V_{\text{Proj}}^{l}(M_{t}),\ \ l\in\{1,\dots,L\}. (7)

By projecting final-layer semantic representations back to all attention blocks through layer-specific decoders, MemOnce establishes looped memory generation and utilization. As shown in Figure 3, across different compression ratios rr (even at r=8r=8) and model scales, MemOnce achieves comparable or lower validation perplexity compared to the Transformer and strong baselines (Vaswani et al., 2017; Sun et al., 2024b; Yang et al., 2025).

Figure 3: Training and scaling curves of MemOnce as a foundation architecture. (Left) Validation perplexity vs. training tokens under different compression ratios. Even at r=8r=8, MemOnce remains competitive with the Transformer and strong baselines. (Right) Validation perplexity vs. model scale (0.15B to 1.0B), where MemOnce delivers the best scaling performance.
Figure 3: Training and scaling curves of MemOnce as a foundation architecture. (Left) Validation perplexity vs. training tokens under different compression ratios. Even at r=8r=8, MemOnce remains competitive with the Transformer and strong baselines. (Right) Validation perplexity vs. model scale (0.15B to 1.0B), where MemOnce delivers the best scaling performance.
Figure 3: Training and scaling curves of MemOnce as a foundation architecture. (Left) Validation perplexity vs. training tokens under different compression ratios. Even at r=8r=8, MemOnce remains competitive with the Transformer and strong baselines. (Right) Validation perplexity vs. model scale (0.15B to 1.0B), where MemOnce delivers the best scaling performance.
Figure 3: Training and scaling curves of MemOnce as a foundation architecture. (Left) Validation perplexity vs. training tokens under different compression ratios. Even at r=8r=8, MemOnce remains competitive with the Transformer and strong baselines. (Right) Validation perplexity vs. model scale (0.15B to 1.0B), where MemOnce delivers the best scaling performance.

Figure 3: Training and scaling curves of MemOnce as a foundation architecture. (Left) Validation perplexity vs. training tokens under different compression ratios. Even at r=8r=8, MemOnce remains competitive with the Transformer and strong baselines. (Right) Validation perplexity vs. model scale (0.15B to 1.0B), where MemOnce delivers the best scaling performance.

3.2 Memory Sparse Attention

While the memory encoder-decoder substantially compresses the global cache by Lr×Lr\times, decoding the entire memory bank GtG_{t} across ultra-long horizons would still incur linear growth in cache memory and attention compute. We introduce memory sparse attention to break fixed capacity limits while maintaining constant active states and linear-time complexity. Its core idea is to retrieve relevant memory representations only once for each continual input and reuse them across layers with negligible loading overhead.

Retrieve Memory Only Once (iθi_{\theta}).

As illustrated in Figure 2, MemOnce partitions the persistent memory bank Gt=[m1,…,mk]⊤G_{t}=[m_{1},\dots,m_{k}]^{\top} into a long-term memory pool Gtlong={m1,…,ms}G_{t}^{\text{long}}=\{m_{1},\dots,m_{s}\} and a short-term memory window Gtshort={ms+1,…,mk}G_{t}^{\text{short}}=\{m_{s+1},\dots,m_{k}\}. The short-term window retains the most recent k−sk-s memory representations to preserve local continuity, whereas the long-term pool stores distant historical states that are accessed sparsely. Given the final-layer representation htLh_{t}^{L} of the continual input xtx_{t}, the indexing function iθi_{\theta} selects the top-KK task-relevant memory states from GtlongG_{t}^{\text{long}} only once:

Mtlong=Top−Kmi∈Gtlong⁡(Sim⁡(ϕ⁡(htL),ϕ⁡(mi))),M_{t}^{\text{long}}=\operatorname{Top-K}_{m_{i}\in G_{t}^{\text{long}}}\Big(\operatorname{Sim}\big(\phi(h_{t}^{L}),\phi(m_{i})\big)\Big), (8)

where ϕ⁡(⋅)\phi(\cdot) extracts the last-token representation and projects it via an MLP layer followed by ℓ2\ell_{2}-normalization, Sim⁡(⋅,⋅)\operatorname{Sim}(\cdot,\cdot) computes cosine similarity, and Top−K⁡(⋅)\operatorname{Top-K}(\cdot) selects the KK most relevant memory representations to bound the active memory budget. The retrieved long-term representations are concatenated with the short-term window to form the active memory state MtM_{t}:

Mt=iθ(xt,Gt)=[Mtlong∥Gtshort]∈ℝ|Mt|×D.M_{t}=i_{\theta}(x_{t},G_{t})=\big[M_{t}^{\text{long}}\,\|\,G_{t}^{\text{short}}\big]\in\mathbb{R}^{|M_{t}|\times D}. (9)

Sparse Attention and On-Demand Loading.

Once MtM_{t} is retrieved and decoded into layer-specific KV caches via Eq. (7), each attention block l∈{1,…,L}l\in\{1,\dots,L\} prepends the decoded (Kl,Vl)(K^{l},V^{l}) to the current input’s local key-value states (Ktl,Vtl)(K_{t}^{l},V_{t}^{l}) for attention computation:

Otl=Attn(Qtl,[Kl∥Ktl],[Vl∥Vtl]),O_{t}^{l}=\operatorname{Attn}\Big(Q_{t}^{l},\,[K^{l}\|K_{t}^{l}],\,[V^{l}\|V_{t}^{l}]\Big), (10)

where Qtl,Ktl,VtlQ_{t}^{l},K_{t}^{l},V_{t}^{l} denote the query, key, and value states of xtx_{t} at stage ll, and [⋅∥⋅][\cdot\|\cdot] denotes sequence concatenation. Unlike layer-wise memory retrievers (Wang et al., 2025a) and token-wise sparse attention mechanisms (Yuan et al., 2025; Xu et al., 2026a) that repeatedly compute routing indices, MemOnce performs Eq. (8) only once per query and reuses MtM_{t} across all LL attention blocks and subsequent decoding steps. Because the active subset size |Mt|=C≪k|M_{t}|=C\ll k is bounded by a constant budget, MemOnce restricts the active memory state cache to 𝒪⁡(C​D)\mathcal{O}(CD) (i.e., 𝒪⁡(1)\mathcal{O}(1) with respect to context length NN and depth LL) while maintaining an expandable persistent bank GtG_{t} that can be offloaded to CPU memory or SSD storage.11 1 In continual inference, only the active memory state Mt∈ℝC×DM_{t}\in\mathbb{R}^{C\times D} is maintained in GPU cache as historical context cache. In practice, memory retrieval and loading in MemOnce take only 64.2​ ms64.2\text{ ms} end-to-end, which is over 12×12\times faster than layer-wise retrieval in M+ and over 17×17\times faster than RAG pipelines (Ma et al., 2023) (see Table 10 in Appendix E).

3.3 Analysis and Optimization

Advantage Analysis.

Compared with existing foundation architectures and native memory models, MemOnce offers three key advantages: (1) Strong Performance: By maintaining an expandable memory bank GtG_{t} and retrieving final-layer representations back into multi-layer KV caches, MemOnce overcomes fixed-capacity bottlenecks and achieves accurate recall in long-context scenarios. (2) Bounded Active Memory State: MemOnce reduces the persistent cache footprint by a factor of L​rLr and achieves constant active memory state during continual inference. (3) High Inference Efficiency: As illustrated in Figure 1 (right), MemOnce operates with linear-time complexity and achieves superior inference efficiency over existing memory architectures.

Table 1: Memory state cache and prefilling time complexities. LL: layer depth, NN: context length, DD: hidden dimension, and CC: an independent constant (C≪NC\ll N).

Model State Cache Prefilling Time

Transformer (Vaswani et al., 2017) 𝒪⁡(L​N​D)\mathcal{O}(LND) 𝒪⁡(L​N2​D)\mathcal{O}(LN^{2}D)

GDN (Yang et al., 2025) 𝒪⁡(C​L​D)\mathcal{O}(CLD) 𝒪⁡(C​L​N​D)\mathcal{O}(CLND)

SWA (Beltagy et al., 2020) 𝒪⁡(C​L​D)\mathcal{O}(CLD) 𝒪⁡(C​L​N​D)\mathcal{O}(CLND)

YOCO (Sun et al., 2024b) 𝒪⁡(N​D)\mathcal{O}(ND) 𝒪⁡(L​N2​D)\mathcal{O}(LN^{2}D)

M+ (Wang et al., 2025a) 𝒪⁡(C​L​D)\mathcal{O}(CLD) 𝒪⁡(C​L​N​D)\mathcal{O}(CLND)

MemOnce 𝒪⁡(C​D)\mathcal{O}(CD) 𝒪⁡(C​L​N​D)\mathcal{O}(CLND)

Complexity Comparison.

Table 1 reports the memory state cache and prefilling time complexities of representative architectures. Standard Transformers and YOCO (Sun et al., 2024b) retain full-sequence caches (𝒪⁡(L​N​D)\mathcal{O}(LND) and 𝒪⁡(N​D)\mathcal{O}(ND)) and require quadratic prefilling time of 𝒪⁡(L​N2​D)\mathcal{O}(LN^{2}D). Linear GDN (Yang et al., 2025), SWA (Beltagy et al., 2020), and M+ (Wang et al., 2025a) reduce prefilling time to 𝒪⁡(C​L​N​D)\mathcal{O}(CLND) but still maintain LL-layer states of 𝒪⁡(C​L​D)\mathcal{O}(CLD). Moreover, fixed states limit memory capacity and degrade long-range recall, whereas M+ incurs retrieval and loading overhead. In contrast, MemOnce achieves linear prefilling time and strictly bounds the memory state cache to 𝒪⁡(C​D)\mathcal{O}(CD).

Optimization.

MemOnce supports end-to-end optimization under the standard next-token prediction paradigm for both pretraining and post-training adaptation. During pretraining, the backbone and memory encoder-decoder are jointly optimized, where historical segments are encoded in parallel into GtG_{t} and gradients flow directly through the active memory state MtM_{t} and the decoded KV caches. During post-training adaptation, we freeze the backbone and optimize only the lightweight projections in iθi_{\theta} and uθu_{\theta}, alongside low-rank adapters (LoRA) activated exclusively during memory encoding (gθg_{\theta}). Because historical context is internalized as decoded KV caches and the backbone remains frozen during response generation, MemOnce equips pretrained LLMs with native long-range memory capabilities without compromising their general task performance. More details are provided in Appendix B.

4 Experiments

4.1 Experimental Setup

Evaluation and Benchmarks.

We conduct extensive experiments to evaluate MemOnce across diverse tasks, model scales, and context lengths. Our evaluation is organized into four primary tracks: (1) Foundational Capability: We evaluate language modeling performance using perplexity (PPL) on WikiText (Merity et al., 2017) and LAMBADA (Paperno et al., 2016). We further report zero-shot accuracy across eight downstream tasks using the LM-Evaluation-Harness (Gao et al., 2021) to assess general knowledge and reasoning capabilities. (2) Long-Context Memory Capability: We evaluate continual and long-horizon memory recall across context lengths spanning 4K to 1M tokens on standard memory benchmarks, including MemBench (Tan et al., 2025), LoCoMo (Maharana et al., 2024), LongMemEval (Wu et al., 2025), and PersonaMem (Jiang et al., 2025). (3) General Capability Retention: To measure general capability retention under active memory load and verify robustness against catastrophic forgetting, we evaluate models on MMLU (Hendrycks et al., 2021), GSM8K (Cobbe et al., 2021), and GPQA (Rein et al., 2024). (4) Representation Tasks: Finally, we assess the zero-shot generalizability of MemOnce’s learned memory representations on downstream text retrieval and reranking benchmarks (Nie et al., 2026a).

Baselines.

We compare MemOnce against three distinct categories of baselines corresponding to our evaluation tracks: (1) Foundational Architectures: We compare against the standard Transformer (Vaswani et al., 2017), cross-layer KV-sharing variants including YOCO (Sun et al., 2024b) and LastKV (Cai et al., 2026), linear and efficient attention architectures including Sliding Window Attention (SWA) (Beltagy et al., 2020), Gated DeltaNet (GDN) (Yang et al., 2025), and Multi-head Latent Attention (MLA) (Liu et al., 2024), as well as the memory architecture Memory Caching (Behrouz et al., 2026).22 2 We exclude Titans (Behrouz et al., 2025) from our pretraining comparison as its official implementation is not publicly available, and our reproduction exhibited optimization instabilities. (2) Native Memory Models: For continual memory evaluation, we compare against advanced native memory methods, including M+ (Wang et al., 2025a), Metis (Zhang et al., 2026), δ\delta-Mem (Lei et al., 2026), and EvoEmbedding (Nie et al., 2026a). (3) Retrieval and Reranking Models: For downstream representation tasks, we benchmark against specialized embedding and reranking models, including BGE-M3 (Chen et al., 2024), as well as Qwen3-Embedding-4B and Qwen3-Reranker-4B (Zhang et al., 2025).

Implementation Details.

For foundational capability evaluation, all architectures are trained from scratch on the FineWeb-Edu dataset (Lozhkov et al., 2024) under unified training configurations and token budgets. For long-context memory evaluation, we adopt Qwen3.5 (Qwen Team, 2026) as the base backbone for lightweight LoRA post-training adaptation, and employ DeepSeek-V4.1-Flash (Xu et al., 2026a) as a strict judge to report final response accuracy across all methods. Unless otherwise specified, MemOnce is configured with a compression ratio of r=8r=8 and retrieves the top-K=64K=64 memory chunks during sparse attention. All experiments are conducted on a single server equipped with 8 NVIDIA H100 GPUs. Full details are provided in Appendix D.

4.2 Main Results

(1) Foundational Capability.

Joint recurrence and compression of context caches across depth and time enable MemOnce to cut the persistent cache footprint by Lr×Lr\times while delivering strong foundational performance. We report the results of pretraining different foundation architectures from scratch on FineWeb-Edu. As shown in Figure 3, MemOnce attains lower final validation perplexity than GDN, SWA, and YOCO, matches or surpasses the Transformer even at r=8r=8, and achieves the best scaling performance from 0.15B to 1.0B parameters. In downstream evaluations (Table 2), MemOncer=1\text{MemOnce}_{r=1} and MemOncer=8\text{MemOnce}_{r=8} attain the highest and second-highest average zero-shot accuracies across all evaluated architectures, while respectively achieving the lowest language modeling perplexities on WikiText-103 and LAMBADA. Notably, compressing the temporal dimension by 8×8\times (MemOncer=8\text{MemOnce}_{r=8} vs. MemOncer=1\text{MemOnce}_{r=1}) incurs virtually no performance loss, demonstrating that the model can effectively condense segment-level context into the trailing tokens while preserving essential long-range information. Crucially, whereas linear models (DeltaNet and GDN) degrade in language modeling perplexity due to fixed-state capacity bottlenecks and prior cache-sharing methods (YOCO and LastKV) lag behind in reasoning accuracy due to direct cross-layer reuse without learned decoding, MemOnce excels across both dimensions, validating its expressiveness as a foundation architecture.

Table 2: Performance of foundation architectures on language modeling and zero-shot common-sense reasoning tasks. All models are pretrained from scratch on FineWeb-Edu under fair configurations. Wiki. and LMB. denote perplexity (↓\downarrow) on WikiText-103 and LAMBADA, respectively. Best results are in bold, and second-best are underlined.

Model Wiki. LMB. LMB. PIQA Hella. Wino. ARC-e ARC-c SciQ BoolQ Avg.

ppl ↓\downarrow ppl ↓\downarrow acc ↑\uparrow acc ↑\uparrow acc_n ↑\uparrow acc ↑\uparrow acc_n ↑\uparrow acc_n ↑\uparrow acc ↑\uparrow acc ↑\uparrow ↑\uparrow

Transformers & Attention Variants

Transformer (Vaswani et al., 2017) 20.90 33.24 35.2 65.7 40.4 51.5 52.4 28.2 83.2 58.2 51.85

SWA (Beltagy et al., 2020) 20.52 32.69 34.5 65.6 41.0 51.4 50.1 27.4 83.2 59.7 51.60

MLA (Liu et al., 2024) 23.07 33.37 34.2 67.0 39.7 50.7 50.6 27.7 83.2 61.9 51.87

Linear & Recurrent Architectures

DeltaNet (Yang et al., 2024) 23.75 33.71 30.8 65.6 37.9 51.0 49.1 26.8 80.7 60.3 50.28

GDN (Yang et al., 2025) 26.03 33.37 34.0 67.6 40.6 50.3 54.1 27.2 84.2 60.6 52.31

Efficient & Memory Architectures

Hybrid 19.56 32.61 35.1 66.5 42.0 51.7 51.4 27.1 83.4 58.7 51.99

YOCO (Sun et al., 2024b) 24.38 35.18 36.1 67.4 40.7 51.1 51.6 26.5 82.6 59.7 51.97

LastKV (Cai et al., 2026) 21.12 34.04 33.7 65.5 40.0 50.5 50.9 27.8 81.5 58.8 51.09

Memory Caching (Behrouz et al., 2026) 29.84 42.47 17.6 62.6 33.5 49.9 47.5 25.7 72.8 56.6 45.78

MemOncer=8 (Ours) 21.08 32.45 34.0 67.8 41.9 51.8 52.3 27.7 81.7 61.6 52.35

MemOncer=1 (Ours) 19.28 32.69 35.2 67.6 42.2 49.6 52.4 27.5 84.7 61.9 52.63

Table 3: Performance on five memory benchmarks across varying context lengths. MemOnce is the first native memory model to surpass the full-context baseline. Best results are in bold and second-best are underlined. † denotes re-trained models for fair comparison.

Model Size MemBench LoCoMo LongMemEval PersonaMem-128 PersonaMem-1M Mem. Avg.

(∼\sim4K) ↑\uparrow (∼\sim21K) ↑\uparrow (∼\sim115K) ↑\uparrow (∼\sim128K) ↑\uparrow (∼\sim1M) ↑\uparrow ↑\uparrow

Full Context Baselines

Qwen3.5-2B 2B 72.69 64.35 41.00 45.00 23.60 49.33

Qwen3.5-4B 4B 82.64 69.55 42.20 43.50 33.60 54.30

Native Memory Models

δ\delta-Mem (Lei et al., 2026) 4B 46.72 16.88 11.20 40.00 31.60 29.28

EvoEmbedding (Nie et al., 2026a) 4B 67.08 25.97 16.40 47.30 39.00 39.15

Metis (Zhang et al., 2026) 4B 47.45 9.35 7.40 37.60 37.20 27.80

M+ (Wang et al., 2025a) 8B 66.93 46.43 27.40 38.40 27.80 41.39

δ\delta-Mem† (Lei et al., 2026) 4B 55.53 15.00 13.00 34.00 32.20 29.95

EvoEmbedding† (Nie et al., 2026a) 4B 69.13 24.68 18.60 42.50 38.80 38.74

Metis† (Zhang et al., 2026) 4B 50.03 25.06 8.80 38.90 36.00 31.76

MemOnce (Ours) 2B 73.54 59.03 35.40 48.50 39.40 51.17+1.84

MemOnce (Ours) 4B 84.34 67.01 47.40 53.60 48.00 60.07+5.77

Table 4: General reasoning performance under a 32K memory load across different memory paradigms. Best results are in bold and second-best are underlined. Subscripts indicate changes relative to the Qwen3.5-4B base model.

Model Mechanism MMLU GSM8K GPQA Gen. Avg.

Qwen3.5-4B Full Context 72.81 92.00 32.83 65.88

Qwen3.5-4Bfull sft{}_{\text{full sft}} Model Weight 51.97 40.50 22.73 38.40-27.48

EvoEmbedding (Nie et al., 2026a) Soft Prompt 68.64 39.50 34.85 47.66-18.22

Metis (Zhang et al., 2026) Linear State 71.71 23.50 34.85 43.35-22.53

δ\delta-Mem (Lei et al., 2026) Linear State 73.46 91.00 33.33 65.93+0.05

MemOnce (Ours) KV Cache 72.59 91.00 34.34 65.98+0.10

(2) Long-Context Memory Capability.

MemOnce is the first native memory model to surpass full-context baselines across model and context scales without suffering from catastrophic forgetting. Table 3 reports evaluation results across five long-context memory benchmarks spanning 4K to 1M tokens. Across both 2B and 4B scales, MemOnce surpasses its full-context Qwen3.5 counterparts with average scores of 51.17%51.17\% (+1.84%+1.84\%) and 60.07%60.07\% (+5.77%+5.77\%), respectively, as query-conditioned sparse retrieval filters out irrelevant historical context and mitigates the attention dilution inherent to ultra-long sequences. Moreover, MemOnce substantially outperforms both official and re-trained (†\dagger) native memory baselines, including M+ (41.39%41.39\%), EvoEmbedding (39.15%39.15\%), Metis† (31.76%31.76\%), and δ\delta-Mem† (29.95%29.95\%). Existing fixed-state memory methods suffer from severe representational bottlenecks when compressing long histories, losing fine-grained details required by multi-session benchmarks such as LoCoMo and LongMemEval. In contrast, our post-training adaptation maintains an expandable state pool and decodes retrieved representations into multi-layer KV caches, preserving the full expressiveness of attention without imposing the capacity limitations of linear models. Meanwhile, under a 32K memory load on general reasoning tasks (Table 4), methods based on soft-prompt injection (EvoEmbedding, −18.22%-18.22\%) and in-backbone linear states (Metis, −22.53%-22.53\%) perturb internal model activations and induce severe catastrophic forgetting, while δ\delta-Mem preserves general accuracy (65.93%65.93\%) at the cost of poor memory recall (29.28%29.28\%). By keeping backbone weights frozen during generation and internalizing history strictly as decoded KV caches, MemOnce achieves the highest general reasoning average alongside superior memory recall.

Figure 4: Inference scalability across context lengths from 32K to 1M tokens.
Figure 4: Inference scalability across context lengths from 32K to 1M tokens.

Figure 4: Inference scalability across context lengths from 32K to 1M tokens.

(3) Inference Efficiency and Scalability.

MemOnce achieves linear-time prefilling, constant active GPU cache, and steady decoding throughput up to 1M tokens. Figure 4 evaluates prefilling time, GPU cache footprint, and decoding throughput across context lengths from 32K to 1M tokens (detailed in Table 14). Beyond the quadratic prefill cost of standard Transformers, existing memory baselines also suffer from severe execution bottlenecks: δ\delta-Mem still relies on full-context attention computation during state construction in its official implementation, Metis employs coarse sequential blocks that limit GPU parallelism, EvoEmbedding requires two separate forward passes to generate memory states and retrieval keys, and M+ incurs heavy layer-wise retrieval and CPU–GPU communication overhead across all layers. By encoding historical chunks in parallel and retrieving memory only once, MemOnce scales linearly from 1.38s (32K) to 41.36s (1M), achieving a 6.9×6.9\times speedup over Hybrid and 35.8×35.8\times over M+. Meanwhile, whereas the KV caches of Transformer and Hybrid grow linearly with sequence length and exceed 32​ GB32\text{ GB} at 1M tokens, MemOnce offloads the historical pool and bounds the active GPU cache to a near-constant 25​ MB25\text{ MB} footprint across all scales (Figure 4(b)). Consequently, while surging KV cache traffic severely degrades decoding throughput in Hybrid and Transformer baselines, MemOnce attends only to a constant-sized memory subset, sustaining the highest and near-invariant throughput across all context lengths.

Table 5: Retrieval performance across diverse long-context and conversational benchmarks. We report Recall@10 (R@10) and NDCG@10 (N@10). Best results within each metric block are in bold and second-best are underlined.

Model Size Dim Metric ESG-Reports LoCoMo LongMemEval REALTALK QASPER PeerQA CovidQA MLDR Overall

BGE-M3 1.2B 1024 R@10 51.00 55.70 77.80 52.40 66.40 37.30 87.20 97.00 65.60

Qwen3-Embedding-4B 4B 2560 R@10 57.90 41.30 58.70 42.70 72.90 36.00 93.20 96.00 62.30

MemOnce (Ours) 4B 1024 R@10 72.55 52.54 86.18 44.14 76.47 35.38 88.39 98.00 69.21

BGE-M3 1.2B 1024 N@10 35.90 41.80 65.60 42.00 44.20 28.20 65.10 77.00 50.00

Qwen3-Embedding-4B 4B 2560 N@10 40.80 29.90 47.10 34.50 50.20 27.20 76.70 77.80 48.10

MemOnce (Ours) 4B 1024 N@10 55.82 38.68 72.75 31.78 53.64 25.05 64.68 82.09 53.06

Table 6: Context reranking performance across agent memory systems on the LoCoMo benchmark. All methods use All-MiniLM-L6-v2 to retrieve 256 candidate segments and restrict the final generator context to Top-20. Best results within each system are in bold and second-best are underlined.

System Method Single-hop Multi-hop Temporal Open Overall

A-MEM Original 42.91 13.71 32.29 56.48 43.57

+ Reasoning 43.26 15.26 35.42 58.98 45.52+2.0

+ Qwen3-Reranker-4B 61.70 22.12 43.75 76.46 60.39+16.8

+ MemOnce (Ours) 66.31 33.96 46.88 70.75 60.78+17.2

LightMem Original 41.13 23.36 41.67 46.85 40.58

+ Reasoning 48.23 24.92 39.58 49.94 43.77+3.2

+ Qwen3-Reranker-4B 55.32 29.28 44.79 61.12 52.40+11.8

+ MemOnce (Ours) 67.02 27.10 41.67 61.12 53.90+13.3

(4) Representation Capability.

The memory representations learned by MemOnce transfer naturally to downstream retrieval and context reranking tasks, outperforming specialized embedding and reranking models. We evaluate MemOnce on eight long-context and conversational retrieval benchmarks against dedicated embedding models, BGE-M3 and Qwen3-Embedding-4B (Zhang et al., 2025) (Table 5). Unlike standalone embedd

Images from the source

(a) Distribution of history rounds (hh).
(a) Distribution of history rounds (hh).
(b) Distribution of sequence lengths.
(b) Distribution of sequence lengths.
(c) Data source composition.
(c) Data source composition.

Sources

← Back to Daily AI Report