INTRODUCTIONThe ability to process and reason over long-context information is a critical frontier for modern Large Language Models (LLMs). While Transformer-based architectures (Vaswani et al., 2017) have demonstrated remarkable capabilities, their self-attention mechanism incurs a computational and memory cost that scales quadratically with sequence length (Tay et al., 2022). This limitation presents a significant barrier to modeling extensive documents, lengthy conversations, or entire codebases. In response, a new class of architectures with near-linear complexity has emerged, most notably State Space Models (SSMs) like the Mamba architecture (Gu & Dao, 2023), which have become a promising alternative for efficient long-sequence modeling.However, the efficiency of SSMs comes at a cost. Their core mechanism, which relies on an exponential decay kernel to compress past information into a fixed-size state, inevitably leads to rapid information forgetting and challenges in length extrapolation (Yen et al., 2024;Chen et al., 2024). This makes it difficult for the model to accurately recall specific details from distant parts of a sequence, a phenomenon often termed the "lost in the middle" problem (Liu et al., 2023a). To mitigate this, one line of research has focused on enhancing the model's internal memory. This approach is inspired by advances in efficient Transformers that employ chunking or sparse attention mechanisms to preserve long-term context, such as Longformer (Beltagy et al., 2020), BigBird (Zaheer et al., 2020), and Native Sparse Attention (NSA) (Yuan et al., 2025). Following this direction, we first extend Mamba with a chunk-wise internal memory, which substantially improves its ability to retrieve information from within the input sequence.Under review as a conference paper at ICLR 2026 While strengthening internal recall is a necessary step, a more fundamental challenge is integrating vast external world knowledge without compromising efficiency. The conventional paradigm for this is Retrieval-Augmented Generation (RAG) (Lewis et al., 2020), which appends retrieved documents to the model's input. Although effective, this method is computationally expensive, as it directly inflates the sequence length (Li et al., 2025), and often results in a superficial concatenation rather than a deep fusion of knowledge (Asai et al., 2024). Pioneering work has explored pre-training models to learn to retrieve, such as REALM (Guu et al., 2020) and RETRO (Borgeaud et al., 2022), but these still rely on processing raw text during training and inference. The challenge of integrating pre-encoded external knowledge-such as knowledge graph embeddings or document vectorsdirectly into a model's core architecture during pre-training has remained largely unaddressed.To address these limitations, we propose the Plastic Unified Memory Network (PUM-Net). We argue that a truly effective long-context model must not only maintain a robust internal memory but also seamlessly fuse it with a vast, static external knowledge base. PUM-Net is designed to achieve this through a novel joint pre-training methodology. Our contributions are threefold:1. For Internal Memory: We introduce a chunk-wise long-term memory mechanism for Mamba-based SSMs. This architectural enhancement significantly mitigates the inherent forgetting problem for information within the input context and improves in-sequence recall over long distances. 2. For External Memory: We propose a novel pre-training methodology to deeply integrate a static, pre-encoded external knowledge base into the model's learning process. This is the first demonstration of how SSMs can be trained to fuse external knowledge without the costly concatenation of raw text. 3. A Unified Architecture and System: We combine these advancements in our Plastic Unified Memory Network (PUM-Net). We demonstrate that the resulting synergy from the deep integration of both internal and external memory systems leads to substantial improvements on challenging long-context benchmarks.
RELATED WORK2.1 LONG-CONTEXT MODELING IN STATE SPACE MODELS State Space Models (SSMs), adapted from control theory, have recently become competitive architectures for sequence modeling. The Structured State Space Sequence Model (S4) (Gu et al., 2022) introduced a discrete-time representation enabling parallel convolutional training and recurrent inference. However, early SSMs were largely time-invariant, limiting their ability to capture content-dependent dynamics.Mamba (Gu & Dao, 2023) advanced this line by introducing input-dependent state transitions, allowing selective remembering and forgetting, and achieving near-Transformer performance with linear complexity. Nevertheless, their reliance on exponential decay kernels restricts retention of very long dependencies, as shown in later analyses (Chen et al., 2024;Yen et al., 2024). Our work addresses this by augmenting Mamba with explicit long-term memory to mitigate natural forgetting.
MEMORY MECHANISMS IN LANGUAGE MODELSThe Transformer (Vaswani et al., 2017) faces quadratic complexity, motivating efficient attention variants. Longformer (Beltagy et al., 2020) and BigBird (Zaheer et al., 2020) approximate full attention with sparse patterns. Transformer-XL (Dai et al., 2019) introduced recurrence to propagate context beyond fixed windows. More recently, Native Sparse Attention (NSA) (Yuan et al., 2025) proposed chunking and hierarchical mechanisms for structured memory. Inspired by these, our internal memory design adapts block-based memory concepts from Transformers to the recurrent dynamics of SSMs.
RETRIEVAL AND KNOWLEDGE INTEGRATIONRetrieval-Augmented Generation (RAG) (Lewis et al., 2020) appends retrieved passages to prompts, but this inflates sequence length (Li et al., 2025) and often yields shallow fusion of knowledge (Asai et al., 2024). To improve integration, models like REALM (Guu et al., 2020) and RETRO (Borgeaud et al., 2022) jointly pre-trained retrievers with LMs, though still operating on raw text chunks. Other approaches (Liu et al., 2023b) explored injecting external knowledge but retained text-based overhead.A less explored direction is leveraging pre-encoded, static knowledge (e.g., embeddings) directly during training. PUM-Net is the first to demonstrate this for SSMs, enabling deep fusion between internal dynamic states and static external memory, avoiding the inefficiencies of text-based retrieval.
THE PUM-NET ARCHITECTUREWe propose the Plastic Unified Memory Network (PUM-Net), which addresses the limitations of State Space Models (SSMs) in capturing long-range dependencies and grounding reasoning in external knowledge. PUM-Net augments a standard SSM with a dual-memory system: (i) a dynamic internal memory that encodes input sequences as chunked representations, and (ii) a static external memory of pre-encoded knowledge. A learned interaction module retrieves and fuses both memories to enrich the recurrent state. We next formalize the memory design, describe the fusion mechanism, and present the joint pre-training and inference strategy. For clarity and reproducibility, a detailed guide to the mathematical notation used throughout this section, including indices for batches, chunks, and time steps, is provided in Appendix A.
THE DUAL-MEMORY SYSTEMThe core of PUM-Net is its dual-memory system, which consists of a static external memory for world knowledge and a dynamic internal memory for session-specific context. Both memories adhere to a unified key-value structure. Further details on the construction of the internal and external memories, along with key hyperparameters such as the memory chunk size and the number of top-k memories selected for fusion, are provided in Appendix B.
EXTERNAL MEMORY: STATIC KNOWLEDGE CORPUSThe external memory, M ext , is a static, pre-computed key-value store derived from a large corpusD ext = {d 1 , .. . , d Next }. Key-Value Generation. For each passage d i , we generate a semantic key k ext,i and a state value s ext,i . The key is produced by a frozen sentence embedding model, E key ; in this paper, all-MiniLM-L6-v2foot_0 . . The state value is the final hidden state computed by a pre-trained Mamba-2.7Bfoot_1 model with fixed parameters θ frozen .k ext,i = E key (d i ) ∈ R dkey , s ext,i = f θfrozen (d i ) ∈ R dstate .(1)The resulting memory is a set of tuplesM ext = {(k ext,i , s ext,i )} Next i=1 .Indexing. The keys {k ext,i } are organized via an Approximate Nearest Neighbor (ANN) index I ext . We use an inverted file index (IVF) with K centroids {c k } K k=1 . Given a query q ∈ R dkey , retrieval is restricted to a candidate set K cand (q) comprising keys from nearby clusters. Top-N retrieval is then:ANN-Search(q, N ) = arg N min kext,i∈Kcand(q) ∥q -k ext,i ∥ 2 .(2)
INTERNAL MEMORY: DYNAMIC CONTEXTUAL REPRESENTATIONThe internal memory, M int , is constructed on-the-fly for each input sequence U. Unlike the static external memory, its keys are not indexed into a persistent structure to avoid prohibitive computational overhead during training. Chunking and Key-Value Generation. The input U is partitioned into M chunks of length L c , {u j } M j=1 . For each chunk, a key-value pair is generated. The key k int,j ∈ R dkey is computed using the shared encoder E key . The state value s int,j ∈ R dstate is the final hidden state computed by the learnable PUM-Net backbone f θ :s int,j = f θ (u j ).(3)Parallel Computation and Caching. To compute all state values efficiently for a training batch of B sequences, the B × M chunks are processed in a single forward pass. Their token embeddings form a tensor E batch ∈ R (B×M )×Lc×dmodel . The backbone f θ operates on this tensor to produce the final states X batch ∈ R (B×M )×dstate , from which each individual state s(b)int,j is extracted. For each sequence in the batch, the collection of key-value pairs is held in a temporary cache for the duration of the forward pass:M (b) int = {(k (b) int,j , s (b) int,j )} M j=1 .(4)Retrieval from this small, session-specific cache is performed via efficient brute-force similarity search, as detailed in the following section. 3.2 TRAINING PARADIGM: STAGED PARALLEL COMPUTATION PUM-Net training is complicated by recurrent dependencies, where computations at step t rely on retrievals conditioned on the same state. To address this and enable efficient accelerator utilization, we introduce Staged Parallel Computation, which decomposes the forward pass into two parallelizable stages, preserving end-to-end differentiability and gradient flow. 3.2.1 STAGE 1: PRELIMINARY STATE SCAN First, a preliminary parallel scan is performed over the input embeddings E ∈ R B×L×dmodel to generate context-aware representations. The backbone SSM, parameterized by θ, computes:O prelim = f θ (E) ∈ R B×L×dmodel . (5) Each vector o (b) prelim,t in this tensor serves as a contextualized basis for memory querying. Under review as a conference paper at ICLR 2026 3.2.2 STAGE 2: PARALLEL RETRIEVAL AND ASSOCIATIVE INTERACTION a) Parallel Query Generation. The preliminary states are projected into query vectors for both memory systems via learnable affine transformations:Q int = O prelim W q,int ∈ R B×L×dkey , Q ext = O prelim W q,ext ∈ R B×L×dkey .(6)b) Batched Dual-Memory Retrieval. At each time step t, we retrieve the top-k most relevant states from both memories in parallel. For the static external memory, we query the pre-built ANN index I ext to efficiently retrieve the top-k candidates for each query q(b) ext,t : S (b) ext,t = {s ext,i } i∈ANN-Search(q (b) ext,t ,k) .(7)For the dynamic internal memory, an exhaustive search is performed via a single, massively parallel computation. The dot-product similarities between all query vectors and all internal memory keys in the batch are computed at once using efficient matrix multiplication. From the resulting similarity scores, we retrieve the top-k states for each time step:S (b) int,t = {s (b) int,j } j∈Top-k-Indices(q (b) int,t ,{k (b) int,j ′ } M j ′ =1 ) .(8)c) Bi-Directional Cross-Memory Interaction The Associative Interaction Module (AIM) processes the retrieved states through a sequence of similarity-weighted aggregation, bi-directional cross-attention refinement.SIMILARITY-WEIGHTED AGGREGATION. The retrieved states from each memory, Sint,t and S (b) ext,t , are aggregated into single context vectors using a standard attention mechanism. Attention weights (α) are computed via scaled dot-product similarity between the query and the retrieved keys. These weights are then used to produce a weighted sum of the retrieved states, yielding the final context vectors m(b) int,t and (analogously) m (b) ext,t :α (b) t,j = softmax j (q (b) int,t ) ⊤ k (b) int,j d key , m (b) int,t = j α (b) t,j s (b) int,j .(9)BI-DIRECTIONAL CROSS-ATTENTION REFINEMENT. To foster deep integration and mutual refinement, the aggregated context vectors interact through a bi-directional cross-attention mechanism. First, external knowledge enriches the internal context representation:Q 1 = m (b) int,t W Q1 , K 1 , V 1 = m (b) ext,t W K1 , m (b) ext,t W V1 ,(10) m′ int,t (b) = LayerNorm(m (b) int,t + Attention(Q 1 , K 1 , V 1 )).(11)Concurrently, the internal context grounds the external knowledge, producing a session-specific external representation:Q 2 = m (b) ext,t W Q2 , K 2 , V 2 = m (b) int,t W K2 , m (b) int,t W V2 ,(12)m ′ ext,t (b) = LayerNorm(m (b) ext,t + Attention(Q 2 , K 2 , V 2 )).(13)This reciprocal process produces two mutually-informed representations, m ′ int,t b) , which are then passed to the fusion stage. d) Gated Fusion for Final Output Computation. The final model output is computed in a single efficient step. The refined memory representations are first projected from the state space R dstate to the model's output space R dmodel . A sophisticated gating mechanism then adaptively integrates these memory contributions into the preliminary outputs from Stage 1. For each timestep t and batch element b:(b) and m ′ ext,t(o (b) int,t = m ′ int,t (b) W m,int , o (b) ext,t = m ′ ext,t (b) W m,ext ,(14)g (b) int,t = σ([o (b) prelim,t ; o (b) int,t ]W g,int ), g (b) ext,t = σ([o (b) prelim,t ; o (b) ext,t ]W g,ext ),(15)o (b) final,t = o (b) prelim,t + g (b) int,t ⊙ o (b) int,t + g (b) ext,t ⊙ o (b) ext,t .(16)Under review as a conference paper at ICLR 2026Here, [•; •] denotes concatenation, and all W matrices are learnable parameters. This formulation bypasses a second SSM scan, directly yielding the final output tensor O final ∈ R B×L×dmodel for prediction.
TRAINING OBJECTIVEThe model is trained end-to-end using a standard autoregressive language modeling objective. The final outputs O final are projected to the vocabulary space via a linear layer, W vocab , to produce logits L ∈ R B×L×|V| . The training loss is the cross-entropy between the predicted logits and the groundtruth target tokens:L(θ) = L t=1 CrossEntropy(softmax(L t ), target t ). (17)The gradient is backpropagated through the entire staged computation graph to update all learnable parameters θ.
INFERENCE PROCEDUREInference mirrors the training pipeline with two differences: (i) the static external memory M ext and its ANN index I ext are already built offline and never reconstructed at test time; and (ii) after a one-time forward scan over the input query sequence U q to obtain O prelim,1:|Uq| and the final recurrent state x |Uq| , answer tokens are generated autoregressively. At each decoding step, we reuse the trained query generators (W q,int , W q,ext ), dual-memory retrieval (internal via in-session brute-force over M int (U q ); external via I ext ), similarity-weighted aggregation, bi-directional cross-attention refinement (AIM), linear projections (W m, * ), and gating (W g, * ) to fuse memory signals into o final,t for prediction, thereby incurring only a small, fixed per-token overhead without any additional SSM scan. Due to space constraints, detailed pseudocode for our staged parallel training and autoregressive inference procedures is provided in Appendix C.
EXPERIMENTSWe conduct a series of experiments to validate the effectiveness of the PUM-Net architecture. Our evaluation is designed to answer two primary questions: (1) Does PUM-Net outperform standard State Space Model (SSM) baselines in long-range modeling tasks? (2) What are the individual contributions of its internal and external memory components? We address these questions through comprehensive benchmarks evaluating perplexity, in-context recall, question answering, and computational efficiency. A discussion on why our experiments do not include a direct comparison with traditional Retrieval-Augmented Generation (RAG) methods is provided in Appendix H.
LONG-RANGE LANGUAGE MODELINGSetup. We first evaluate PUM-Net on the task of long-range language modeling, using three widely recognized datasets: PG-19 (Rae et al., 2019), ProofPile (Azerbayev et al., 2023), and CodeParrot (Thomas Wolf & Zebaze, 2023). All models are trained with a 4k token context and evaluated for perplexity (PPL) on sequences up to 64k tokens to test extrapolation capabilities. Further details on the data set split, each task's external memory source, and training protocol are provided in the Appendix D.Results. Figure 2 shows that the standard Mamba-130M baseline's performance degrades sharply beyond its training length. In contrast, PUM-Net (w/o ex), which isolates our internal memory mechanism, maintains significantly lower perplexity, demonstrating its effectiveness at mitigating information decay. The full PUM-Net model achieves the best results across all contexts. The benefit of its external memory is especially pronounced on CodeParrot, underscoring its value for knowledge-intensive domains. As shown in the training loss curves (Figure 3), PUM-Net also exhibits a more favorable optimization landscape, suggesting convergence to a better local minimum.Table 1 benchmarks PUM-Net against vanilla Mamba and several Mamba variants augmented with attention mechanisms like Sliding Window Attention (SWA) and Native Sparse Attention (NSA). Under review as a conference paper at ICLR 2026  For fairness, all models are implemented based on a 130M parameter budget (see Appendix D.1 for details). The results show that PUM-Net consistently outperforms all baselines. This strong performance against the NSA-augmented model is particularly significant, as our architecture was inspired by similar principles of efficient information routing. The full PUM-Net model achieves stateof-the-art results, with its external memory showing a pronounced advantage on the knowledgeintensive CodeParrot dataset.
PASSKEY RETRIEVAL: EVALUATING INTERNAL MEMORYSetup. To specifically isolate the internal memory component, we use the passkey retrieval task, a synthetic "needle-in-a-haystack" benchmark that requires verbatim recall of information from a long sequence. Since this task relies purely on in-context information, we evaluate PUM-Net (w/o ex) against several Mamba-family baselines. Setup specifics are available in Appendix E.Results. Figure 4 shows that while baseline models fail as context extends beyond their training length, PUM-Net (w/o ex) maintains near-perfect retrieval accuracy up to 64k tokens. This result provides strong evidence that our dynamic internal memory acts as a reliable long-term buffer, overcoming the typical forgetting problem of SSMs.
PERFORMANCE ON LONG-CONTEXT QUESTION ANSWERINGSetup. We evaluate PUM-Net on a suite of question-answering tasks from the LongBench benchmark (Bai et al., 2023). These tasks require models to find and reason over information in long documents, testing the synergy between internal and external memory. We compare the full PUM-Under review as a conference paper at ICLR 2026 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] Mamba-130M Full FT Retrieval Score = 71.4% 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] DeciMamba-130M Retrieval Score = 85.7% 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] MambaExtend-130M Retrieval Score = 91.4% 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] PUM-Net (w/o ex) 130M Retrieval Score = 94.3% 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] Mamba-1.4B Full FT Retrieval Score = 82.9% 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] DeciMamba-1.4B Retrieval Score = 74.3% 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] MambaExtend-1.4B Retrieval Score = 80.0% 1K 2K 4K 8K 16K 32K 64K Context Length 0% 25% 50% 75% 100% Passkey Depth [%] PUM-Net (w/o ex) 1.4B Retrieval Score = 85.7% Failure (0) Success (1) Retrieval Outcome Net-2.8B against a fine-tuned Mamba-2.8B and our PUM-Net (w/o ex) ablation, measuring performance with F1 score. Experiment details and external memory construction for this task are available in the appendix F. 2 demonstrate PUM-Net's superior reasoning capabilities. On all tasks, PUM-Net (w/o ex) outperforms the Mamba baseline, confirming the benefit of the improved internal memory for downstream tasks. The full PUM-Net model consistently yields the best scores, showing that the external memory provides a crucial advantage for synthesizing information to answer complex questions.
Results. The results in Table
TRAINING AND INFERENCE EFFICIENCYSetup. Finally, we evaluate the computational efficiency of PUM-Net. We measure throughput (forward/backward pass time) and peak memory usage against highly optimized Transformer base-Under review as a conference paper at ICLR 2026 Table 2: Results on LongBench QA tasks after finetuning. We compare Mamba-2.8b baseline, PUM-Net without external memory, and PUM-Net with external memory. Adding external memory provides consistent further improvements, highlighting its benefits for QA tasks. LB = LongBench score, and 'N/A' means that the task does not exist in LongBench-E.Type (Metric) Benchmark Avg Len Mamba-2.8b (finetuned) PUM-Net (w/o ex) PUM-Net (full) 0-4k 4-8k 8k+ LB 0-4k 4-8k 8k+ LB 0-4k 4-8k 8k+ LB MultiDoc-QA (F1) 2wikimqa 4887 8.47 2.34 1.18 4.53 10.72 5.48 2.93 9.58 12.42 6.84 3.63 11.46 MultiDoc-QA (F1) Hotpotqa 9151 5.77 2.02 0.53 2.28 7.08 3.36 2.03 4.24 8.88 4.53 2.71 5.69 MultiDoc-QA (F1) Musique 11214 N/A N/A N/A 1.23 N/A N/A N/A 2.38 N/A N/A N/A 3.47 SingleDoc-QA (F1) NarrativeQA 18409 N/A N/A N/A 1.27 N/A N/A N/A 2.13 N/A N/A N/A 3.08 SingleDoc-QA (F1) Qasper 3619 7.52 5.17 2.14 6.09 9.14 8.29 2.73 9.28 11.18 10.07 3.63 11.84 SingleDoc-QA (F1) MultifieldQA 4559 19.28 6.73 2.93 12.46 24.12 12.28 4.64 18.87 27.76 14.47 6.24 21.73 Few-Shot (F1) TriviaQA 8209 11.46 6.38 4.52 5.83 14.23 10.07 7.17 10.36 16.87 12.82 9.58 13.69 lines: Native Sparse Attention (NSA) (Yuan et al., 2025) and Flash-Attention (Dao et al., 2022). The benchmark setup is detailed in Appendix G. Results. Figure 5 shows that PUM-Net is substantially more efficient than attention-based baselines. Its throughput is significantly higher, achieving a 3.9x speedup over NSA and a 26.5x speedup over Flash-Attention in the forward pass at 64k context length. Moreover, its memory footprint is markedly lower and scales more favorably. This efficiency is due to our architecture's avoidance of quadratic-cost operations, confirming that PUM-Net achieves state-of-the-art performance without sacrificing computational feasibility.
CONCLUSIONWe presented the Plastic Unified Memory Network (PUM-Net), a new architecture that augments State Space Models with a unified dual-memory system, combining a dynamic chunk-wise internal memory for long-range sequence retention with a static external memory for world knowledge, trained efficiently via a staged parallel computation scheme. Empirical results on long-context language modeling benchmarks demonstrate that PUM-Net substantially improves extrapolation, alleviates in-sequence forgetting, and delivers significant gains on knowledge-intensive tasks while maintaining superior computational efficiency compared to attention-based alternatives. Despite these advances, limitations remain, including the reliance on a fixed external memory, performance degradation at extreme sequence lengths, and an evaluation primarily on text. Future work will therefore focus on developing adaptive external memory, scaling PUM-Net to even longer contexts, and extending the architecture to multi-modal reasoning. We believe this unified memory perspective provides a promising foundation for building the next generation of efficient and knowledgegrounded long-context models.
ETHICS STATEMENTThe research presented in this paper focuses on a frontier LLM model architecture, PUM-Net, and primarily utilizes established, publicly available datasets for training and evaluation. We acknowledge that, like all large language models, architectures like ours could potentially be used to generate harmful, biased, or factually incorrect content, as their behavior is a reflection of the data they are trained on. A specific consideration for our dual-memory approach is the content of the external knowledge base; the quality and neutrality of this external memory can directly influence the model's outputs. Our work is intended for research purposes to advance the understanding of efficient long-context models, and we encourage the community to pursue responsible development and deployment of such technologies.Under review as a conference paper at ICLR 2026Algorithm 1 Staged Parallel Training for PUM-Net Require: Batch embeddings E ∈ R B×L×dmodel ; internal chunk keys/values {M (b) int } B b=1 with M (b) int = {(k (b) int,j , s (b) int,j )} M j=1 ; external memory M ext = {(k ext,i , s ext,i )} Next i=1 and ANN index I ext ; K, N ; parameters θ, W q, * , W m, * , W g, * , W vocab . Ensure: Loss L(θ). 1: Stage 1: Preliminary scan O prelim ← f θ (E) ∈ R B×L×dmodel . 2: Stage 2a: Parallel query generation Q int ← O prelim W q,int , Q ext ← O prelim W q,ext.3: for all b ∈ {1, . . . , B} and t ∈ {1, . . . , L} in parallel do4: Stage 2b: Retrieval 5:Internal:S (b) int,t ← {s (b) int,j } j∈Top-K-Indices(Q (b) int,t ,{k (b) int,j ′ } M j ′ =1 ) .6:External:S (b) ext,t ← {s ext,i } i∈ANN-Search(Q (b) ext,t ,N ; Iext) . 7:Stage 2c: Similarity-weighted aggregation8: α (b) t,j ← softmax j (q (b) int,t ) ⊤ k (b) int,j / d key , m (b) int,t ← j α (b) t,j s (b)int,j .9:(Analogously obtain m(b) ext,t .) 10:Stage 2d: Bi-directional cross-attention refinement (AIM)11:Q 1 ← m (b) int,t W Q1 , K 1 , V 1 ← m (b) ext,t W K1 , m (b) ext,t W V1 .12:m ′ int,t (b) ← LayerNorm m (b) int,t + Attention(Q 1 , K 1 , V 1 ) . 13: Q 2 ← m (b) ext,t W Q2 , K 2 , V 2 ← m (b) int,t W K2 , m (b) int,t W V2 . 14: m ′ ext,t (b) ← LayerNorm m (b) ext,t + Attention(Q 2 , K 2 , V 2 ) .15:Stage 3: Projection and gated fusion16: o (b) int,t ← m ′ int,t (b) W m,int , o (b) ext,t ← m ′ ext,t (b) W m,ext . 17: g (b) int,t ← σ([o (b) prelim,t ; o (b) int,t ]W g,int ), g (b) ext,t ← σ([o (b) prelim,t ; o (b) ext,t ]W g,ext ). 18: o (b) final,t ← o (b) prelim,t + g (b) int,t ⊙ o (b) int,t + g (b) ext,t ⊙ o (b) ext,t . 19: end for 20: Prediction & loss L t ← o final,t W vocab , L(θ) ← L t=1 CrossEntropy(softmax(L t ), target t ).Under review as a conference paper at ICLR 2026
C PSEUDOCODE FOR PUM-NET TRAINING AND INFERENCEAlgorithm 2 Inference for PUM-Net Require: Query sequence U q ; pre-built M ext , I ext ; top-K, top-N ; trained θ, W q, * , W m, * , W g, * , W vocab . Ensure: Generated answer tokens y 1:T .1: Phase A: One-time context preparation (no generation) 2: Build M int (U q ) = {(k int,j , s int,j )} M j=1 as in training (chunking U q , shared E key , backbone f θ ). 3: Run a single forward scan over U q to obtain O prelim,1:|Uq| and final state x |Uq| . 4: Initialize x 0 ← x |Uq| , y 0 = <ANS-START>, u 1 ← Embed(y 0 ). 5: Phase B: Autoregressive answer generation 6: for t = 1 to T do 7:Preliminary output: o prelim,t ← f θ (x t-1 , u t ).
8:Dual-query generation (frozen): q int,t ← o prelim,t W q,int , q ext,t ← o prelim,t W q,ext . 9:Memory retrieval:S int,t ← {s int,j } j∈Top-K-Indices(qint,t,{k int,j ′ } M j ′ =1 ) , S ext,t ← {s ext,i } i∈ANN-Search(qext,t,N ; Iext) . 10:Similarity-weighted aggregation: α t,j ← softmax j q ⊤ int,t k int,j / d key , m int,t ← j α t,j s int,j ; obtain m ext,t analogously.
11:Bi-directional cross-memory refinement (AIM): m ′ int,t , m ′ ext,t via the two cross-attention updates and LayerNorm.12:Projection and gated fusion:o int,t ← m ′ int,t W m,int , o ext,t ← m ′ ext,t W m,ext ; g int,t ← σ([o prelim,t ; o int,t ]W g,int ), g ext,t ← σ([o prelim,t ; o ext,t ]W g,ext ); o final,t ← o prelim,t + g int,t ⊙ o int,t + g ext,t ⊙ o ext,t . 13:Predict & recurrent update: L t ← o final,t W vocab ; y t ← Decode(L t ); u t+1 ← Embed(y t ); update SSM state to x t using (x t-1 , u t ).
14:(Optional) Online consolidation: periodically buffer recent decoder states into M int . 15: end for
D LANGUAGE MODELING EXPERIMENTAL DETAILSDataset Details We use the following datasets and splits for our finetuning experiments:• PG-19 (Rae et al., 2019): We use the official, standard splits for this dataset. The models are finetuned on the official training set and evaluated on the validation and test sets. • ProofPile (Azerbayev et al., 2023): As the full dataset is very large, we created smaller, representative splits for finetuning. We randomly selected 10,000 samples from the official training set to create our finetuning set. For validation and testing, we randomly sampled 1,000 samples from the official validation set and 1,000 samples from the official test set, respectively. • CodeParrot (Thomas Wolf & Zebaze, 2023): The official CodeParrot dataset does not provide predefined training, validation, or test splits. To create a consistent benchmark, we randomly sampled 100,000 samples for our finetuning training set, 1,000 samples for our validation set, and 2,000 samples for our test set.Training Setup We finetune each model on a total of 100M tokens. We use a constant learning rate of 1e-4, a global batch size of 128 (using batch accumulation), and the AdamW optimizer with a weight decay of 0.1 and gradient clipping of 1.0. During training, we sample a single window with a context length of 4k tokens from each example. During evaluation, for each example, we evaluate 10 windows with a maximal constant stride. We measure perplexity on only the last 100 tokens in each window to specifically test the model's extrapolation abilities.External Knowledge Base For PG-19, we constructed the external memory from an English Wikipedia snapshot (Wikimedia Foundation, 2012), which provides background knowledge about historical events, literary works, and cultural references beyond the book corpus. For ProofPile, we assembled an auxiliary mathematical reference corpus consisting of arXiv mathematics papers Under review as a conference paper at ICLR 2026 (Ginsparg, 2001) and Wikipedia mathematics pages (Wikimedia Foundation, 2012), enabling access to formal definitions, theorems, and proofs not explicitly contained in the training set. For Code-Parrot, we extracted Python-specific files from The Stack dataset (Kocetkov et al., 2022), thereby incorporating a large-scale source of open-source Python code to provide knowledge of libraries and idiomatic coding patterns beyond the CodeParrot training data.
D.1 IMPLEMENTATION DETAILS FOR COMPARATIVE MODELSTo ensure a fair and direct comparison for the perplexity benchmarks in Table 1, we standardized the experimental setup for all model variants.• Parameter Count: All models, including the Transformer full attn baseline, were configured to have approximately 130 million parameters.• Mamba Variant Construction: The attention-augmented Mamba models and our PUM-Net were constructed upon the same Mamba-130M backbone. To create each variant, we randomly selected 20 of the original Mamba blocks and replaced them with the corresponding new architectural block. For example:- This block-replacement strategy, while representing a substantial architectural modification, is designed to fairly compare the efficacy of different block types (SWA, NSA, PUM-Net) within the same 130M-parameter framework, ensuring that the primary variable under investigation is the block architecture itself.
E PASSKEY RETRIEVAL EXPERIMENTAL DETAILSTask Setup To specifically isolate and evaluate the model's long-context recall capabilities, we use the passkey retrieval task, a synthetic "needle-in-a-haystack" benchmark. Our setup follows the methodology described in Ben-Kish et al. (2024). The task requires the model to retrieve a 5-digit code embedded at a random sequence depth within a long document. The distractor text for these documents is sourced from samples in the WikiText dataset (Merity et al., 2016). Since the answer is always present in the input, success on this task depends solely on the model's ability to access and recall information from its context, not on external knowledge. Given that this task exclusively tests in-sequence recall, we use our PUM-Net (w/o ex) variant for a direct comparison against a suite of strong baseline models. These baselines include the original Mamba (Gu & Dao, 2023), as well as its variants DeciMamba (Ben-Kish et al., 2024) and MambaExtend (Azizi et al., 2025). We evaluate all models at two different scales: 130M and 1.4B parameters. To establish a strong baseline for comparison, all models were fine-tuned for one epoch on a dataset with a 4k context length. All other experimental parameters are consistent with the Training Setup detailed in Appendix D.Evaluation Protocol The evaluation is conducted across a wide range of sequence lengths and passkey depths to thoroughly probe the models' performance. We test context lengths of 1K, 2K, 4K, 8K, 16K, 32K, and 64K tokens. For each context length, the passkey is hidden at relative depths of 0%, 25%, 50%, 75%, and 100% of the sequence.A retrieval is considered successful if the model generates the passkey verbatim. We compute the overall retrieval score for each model by assigning a score of 1 for each correct retrieval and 0 for each incorrect one, and then averaging across all tested depths and context lengths. The score is presented as a percentage using the formula:Retrieval Score (%) = Total correct retrievals Total (correct + incorrect) retrievals × 100
F LONGBENCH QA EXPERIMENTAL DETAILSBenchmark and Finetuning The LongBench benchmark (Bai et al., 2023) contains a diverse suite of tasks designed to evaluate long-context understanding. Our experiments focus on the question-answering categories listed in Table 2. All models originate from the same instructiontuned checkpoint, xiuyul/mamba-2.8b-zephyr. The Mamba-2.8B baseline is a direct finetuning of this base model. Our PUM-Net (w/o ex) and full PUM-Net variants were created by modifying this Mamba-2.8B architecture, replacing each of its original Mamba blocks with our proposed PUM-Net blocks. Subsequently, all three models (the baseline Mamba, and the two PUM-Net variants) were individually fine-tuned on the official training set for each respective LongBench task, using a fixed context length of 4k tokens. All other experimental parameters are consistent with the Training Setup detailed in Appendix D.External Memory Construction To provide the model with highly relevant external knowledge for each reasoning task, we constructed a targeted corpus for the external memory. Specifically, for each question within the LongBench QA tasks, we used the question as a search query against an index of the English Wikipedia. We then took the top-1 most relevant Wikipedia page from the search results. The full text content of this page was then encoded and stored, serving as the dedicated external knowledge source for the PUM-Net (full) model when answering that specific question.
Evaluation Metrics and ResultsInterpretation Performance reported in Table 2 is measured using the F1 score, following the official LongBench protocol. To ensure clarity, we detail the metrics as follows:• The columns '0-4k', '4-8k', and '8k+' report the macro-averaged F1 score for all test samples that fall within those respective context length groups. This provides a granular view of performance as context grows.• The 'LB' column represents the official overall score for each task, serving as the primary benchmark metric.• A value of 'N/A' is used for tasks (e.g., Musique) where the official benchmark does not provide a breakdown of scores by context length, although an overall 'LB' score is still computed.While these results are based on a single training run for each model, the performance gains from PUM-Net are not isolated to a single task or context length. The improvements are observed consistently and substantially across a diverse suite of QA tasks (Single-Doc, Multi-Doc, and Few-Shot). This consistency, combined with the large margins of improvement in many cases, provides strong evidence for the robustness and effectiveness of our proposed architecture.
G EFFICIENCY BENCHMARK DETAILSBenchmark Setup To provide a fair and direct comparison of computational costs, the efficiency benchmarks shown in Figure 5 were conducted on a single, representative block of each architecture. We compare our PUM-Net block against a Native Sparse Attention (NSA) block (Yuan et al., 2025) and a Flash-Attention block (Dao et al., 2022). To ensure a fair comparison of architectural overhead, all benchmarked blocks were configured to a 130M parameter scale. All experiments were conducted on a single NVIDIA H100 GPU, measuring wall-clock time for forward/backward passes and peak allocated memory.Rationale for Baseline Selection Our choice of baselines was motivated by key conceptual similarities to our approach, allowing for a meaningful comparison of efficiency for long-context modeling:• Native Sparse Attention (NSA): The core idea in our internal memory mechanism-partitioning the sequence into chunks to process local information-was inspired Under review as a conference paper at ICLR 2026 by the block-wise sparse patterns utilized in NSA. Therefore, comparing against it is crucial to show the efficiency gains of our SSM-based approach over a sparse-attention-based one. • Flash-Attention: While it implements a mathematically equivalent dense attention, Flash-Attention's groundbreaking memory optimization is achieved by processing the computation in a block-wise or "tiled" fashion. We include it as a baseline as it represents the de facto standard for highly optimized Transformer implementations.Analysis of PUM-Net's Efficiency Advantage PUM-Net's superior efficiency, especially at longer sequence lengths, stems from two core design principles of its dual-memory system:1. LinearTime Complexity: The fundamental architecture of our PUM-Net block is derived from the Mamba model, which has linear time complexity (O(L)) with respect to sequence length L. This inherent efficiency means that its processing time and memory usage do not grow quadratically as sequence length increases, unlike attention-based mechanisms. This explains why the inference and training times scale far more favorably for PUM-Net. 2. Zero-Overhead External Memory During Training: Our external memory system is explicitly designed to avoid introducing computational overhead during the training loop. The knowledge base is pre-computed offline into a static set of encoded key-value pairs and indexed using a highly efficient Approximate Nearest Neighbor (ANN) library for fast lookups. Crucially, the retrieval process does not involve fetching raw text and prepending it to the input sequence-a common practice in retrieval-augmented models that would significantly slow down training. Instead, our retrieval mechanism is optimized directly into the model's parameters, allowing it to leverage external knowledge with no substantial additional time cost per training step. H ON THE CHALLENGES OF COMPARING WITH RAG METHODS FOR LONG-CONTEXT INPUTSWe considered including a direct comparison to traditional Retrieval-Augmented Generation (RAG) methods, as PUM-Net's use of an external memory shares a conceptual goal with retrieval augmentation. However, we concluded that a direct comparison is not straightforward due to a fundamental mismatch in the problem formulation, particularly concerning the handling of long-context inputs, which is the primary focus of our work.The Challenge of Dense Retrieval with Long Queries. Standard RAG pipelines are designed for short, focused queries. They typically employ a dense retriever (e.g., a BERT-based bi-encoder) to map a query to a vector and retrieve text chunks with high semantic similarity. This is effective for short queries that produce a distinct semantic representation, leading to clearly distinguishable similarity scores. However, this paradigm breaks down for a very long query (e.g., 64k tokens). The semantic representation of such a long query becomes diffuse and less focused. When compared against a relevant document in a corpus, a long query will often exhibit high semantic overlap with nearly all chunks from that document. This results in undifferentiated, high similarity scores across many chunks, causing a loss of the retriever's discriminative power and making it difficult, if not impossible, to select a small, targeted set of "top-k" relevant passages.The Prohibitive Cost of a Chunk-and-Retrieve Strategy. An alternative strategy would be to partition the long query itself and perform retrieval for each query chunk. However, this approach is computationally prohibitive and counter-productive. For instance, dividing a 64k-token query into 64-token chunks would result in 1024 individual queries. If we retrieve just one top-1 64-token text snippet for each of these query chunks, we would accumulate an additional 64k tokens of retrieved text. Concatenating this to the original input would create a 128k-token sequence for the model to process. This approach not only doubles the sequence length-exacerbating the very problem long-context models aim to solve-but also makes the training and inference costs untenable.Incompatibility with Pre-training Methods like REALM. This fundamental limitation also applies to pioneering methods that integrate retrieval into the training loop, such as REALM (Guu et al., Under review as a conference paper at ICLR 2026 2020). While REALM effectively demonstrates how retrieved knowledge can be used to jointly optimize a model's parameters, its mechanism still relies on concatenating retrieved documents to the original input for the forward and backward passes. This concatenation-based augmentation, while powerful for short inputs, is fundamentally challenging to scale to the very long sequence lengths explored in our work and would not be computationally feasible.
Conclusion.In summary, due to these inherent challenges in applying existing RAG paradigms to long-sequence inputs, we determined that a direct experimental comparison would not be meaningful or fair. PUM-Net is designed to address a different challenge: efficiently augmenting an already long, contiguous context with pre-encoded external knowledge, rather than augmenting a short query with retrieved text. Therefore, we focused our comparisons on other state-of-the-art long-context architectures.Figure 1 :1Figure 1: Illustration of the proposed PUM-Net. (a) The overall workflow. (b) The block design.
Fig. 11Fig. 1 illustrates the proposed PUM-Net, where (a) shows the overall workflow and (b) details the block design.
Figure 2 :2Figure 2: Perplexity (PPL) comparison on the PG-19, ProofPile, and CodeParrot test sets. All models are trained on a 4k context length and evaluated on lengths up to 64k. Lower PPL indicates better performance. PUM-Net consistently outperforms the Mamba baseline, with the performance gap widening dramatically at longer contexts. The addition of external memory provides a significant further boost, especially on the knowledge-intensive CodeParrot dataset.
Figure 3 :3Figure 3: Training loss curves for PG-19, ProofPile, and CodeParrot finetuning. Each column shows the full training run and a zoomed-in view of the final training steps. PUM-Net exhibits lower loss throughout training and demonstrates stronger late-stage advantages compared to both vanilla Mamba and the variant equipped only with internal memory, indicating a superior convergence point.
Figure 4 :4Figure 4: Passkey retrieval performance comparison. Baseline models, fine-tuned on 4k context length samples, show significant degradation on longer contexts. In contrast, our PUM-Net (w/o ex) model demonstrates robust performance, maintaining high retrieval accuracy up to 64k tokens.
Figure 5 :5Figure 5: Efficiency comparison of PUM-Net against Native Sparse Attention (NSA) and Flash-Attention. Subplots show (from left to right): forward pass time, backward pass time, and peak memory footprint relative to a pure Mamba model. PUM-Net demonstrates superior efficiency across all metrics, with its advantages becoming more pronounced as sequence length increases.
To build the Mamba w/ SWA model, 20 Mamba blocks were substituted with 20 Sliding Window Attention (SWA) blocks.-To build the Mamba w/ NSA model, 20 Mamba blocks were substituted with 20Native Sparse Attention (NSA) blocks. -To build our PUM-Net models, 20 Mamba blocks were substituted with 20 of our proposed PUM-Net blocks.

Table 1 :1Perplexity at evaluation lengths up to 64k after fine-tuning on 4k. Baselines include Transformer and Mamba variants with SWA and NSA. Our method, PUM-Net, is shown in two forms: (w/o ex) without external memory and (full) with external memory.DatasetLength Transformerfull attn Mamba-130M Mamba w/ SWArope Mamba w/ NSA PUM-Net (w/o ex) PUM-Net (full)4k16.4016.6916.4516.3816.1215.968k17.1017.3517.0116.9216.7716.63PG-1916k520.017.7917.5517.4316.9816.8632k1800.026.5425.8225.6022.3222.2364k1.0 × 10 54352.973890.243725.50619.33411.294k4.404.524.384.314.013.538k4.554.604.534.494.173.61ProofPile16k150.05.375.215.144.844.4032k1200.028.0227.1026.8327.5426.5064k5.0 × 10 476645.9569220.0067310.502425.501265.574k4.554.614.504.484.471.118k5.205.345.225.195.173.18CodeParrot16k120.07.317.207.157.184.2532k1500.026.0125.6225.5025.1422.5064k1.0 × 10 91.53 × 10 101.28 × 10 101.19 × 10 102.14 × 10 96288Perplexity (log scale)10 2 10 3PPL Comparison on PG-19 Mamba-130M PUM-Net-130M (w/o ex) PUM-Net-130M90.6%Perplexity (log scale)10 2 10 3 10 4 10 598.3% PPL Comparison on ProofPile Mamba-130M PUM-Net-130M (w/o ex) PUM-Net-130MPerplexity (log scale)10 3 10 5 10 7 10 9100.0% PPL Comparison on CodeParrot Mamba-130M PUM-Net-130M (w/o ex) PUM-Net-130M10 110 14k8k16k Context Length32k64k4k8k16k Context Length32k64k4k8k16k Context Length32k64k
			https://huggingface.co/sentence-transformers/all-MiniLM-L6-v2
			https://huggingface.co/fla-hub/mamba-2.7B-100B