TL;DR
MoNe (Modular Neural Memory) is a lightweight plugin that grants frozen, pretrained Transformers long-context capabilities without the need for retraining. By compressing context into layer-specific "fast-weight" neural memories during a quick preprocessing phase, MoNe achieves $O(1)$ query costs and reduces GPU memory usage by 80% at 128K tokens compared to standard in-context learning.
What Problem Does This Paper Address?
As Large Language Models (LLMs) are deployed in "agentic" roles—like personal assistants reading through years of chat history or researchers analyzing massive document sets—the "long-context problem" has become a major bottleneck.
Standard In-Context Learning (ICL) scales quadratically ($O(N^2)$) in compute and linearly in memory (the KV cache). On resource-constrained devices like phones, a 128K token context window is simply too expensive to maintain. Retrieval-Augmented Generation (RAG) helps by only looking at relevant snippets, but it often fails on complex tasks that require synthesizing information scattered across an entire document. Newer architectures like Mamba or TTT-linear offer better scaling, but they require training entirely new models from scratch.
The authors of MoNe ask: Can we give existing, frozen LLMs the efficiency of a recurrent memory without the cost of retraining the whole "brain"?
Methods
MoNe introduces a two-phase approach that treats context as something to be "learned" at inference time rather than just "stored."
- Modular Plugin: The researchers attach a small SwiGLU MLP (the "neural memory") to each layer of a frozen Transformer backbone. This adds only about 6.4% parameter overhead.
- Test-Time Learning (TTL): When a long context arrives, MoNe processes it in 512-token segments. For each segment, it performs a quick gradient update to the "fast weights" of the MLPs. Crucially, these updates are layer-localized—gradients don't flow through the whole model, making the process fast and modular. The goal of this update is "associative memory": the MLP learns to map specific keys to their corresponding values.
- Constant-Cost Inference: Once the context is processed, the original tokens are discarded. At query time, the model uses the query tokens to "read" from the neural memory. This generates the necessary keys and values for the attention mechanism. Because the model only attends to these generated "memory tokens," the inference cost is constant ($O(1)$) regardless of how long the original context was.
- Segment-local RoPE: To handle sequences much longer than the model was originally trained for, MoNe uses local positional encodings within each 512-token segment. This prevents the "positional out-of-distribution" errors that usually cause LLMs to hallucinate on very long sequences.
Datasets
The authors evaluated MoNe using the RULER benchmark, which is designed to test the "real" context limits of models beyond simple pattern matching. Specifically, they used:
- S-NIAH (Single Needle-in-a-Haystack): Finding one specific fact in a sea of filler text.
- MK-NIAH (Multi-Key Needle-in-a-Haystack): Retrieving a specific value when multiple similar key-value pairs are present.
- FWE (Frequent Word Extraction): Identifying the most common words across a massive text.
The backbone model used for all experiments was Qwen2.5-0.5B-Instruct.
Key Insights and Ideas
- Weights as Storage: The "aha moment" here is shifting from storing data (KV cache) to encoding data into weights. This decouples the cost of the query from the length of the document.
- Non-linear Memory is Key: Unlike previous attempts at fast-weight memories that used simple linear maps, MoNe uses a non-linear SwiGLU MLP. This significantly increases the "expressive capacity" of the memory, allowing it to store more complex relationships within the same parameter budget.
- Zero-Shot Extrapolation: MoNe was meta-trained on contexts only up to 4K tokens but successfully generalized to 128K tokens (a 32x increase) with almost no loss in accuracy. This suggests the "learning to learn" approach is highly robust to sequence length.
Key Results
- Massive Efficiency Gains: At a context length of 128K tokens, MoNe reduced peak GPU memory and total FLOPs by approximately 80% compared to standard ICL.
- Superior Accuracy: On the MK-NIAH task at 128K tokens, MoNe maintained a score of 0.94, while standard ICL collapsed to 0.00 and RAG plateaued at 0.71.
- Constant Footprint: While ICL's memory usage grows as the document gets longer, MoNe’s peak GPU memory remains constant (at roughly 1.41 GB for the 0.5B model) regardless of whether the context is 32K or 128K tokens.
Limitations and Future Work
- Model Scale: The current study focuses on a relatively small 0.5B parameter backbone. The authors note that testing on larger models (7B+) is a necessary next step, though they expect the efficiency benefits to be even more dramatic at scale.
- Task Variety: The evaluation relied on synthetic retrieval tasks (RULER). Future work is needed to see how MoNe handles "naturalistic" workloads like multi-document summarization or long-form creative writing.
- Memory Management: The authors suggest exploring different LoRA-based approaches to allow for the flexible management of multiple memory modules (e.g., one memory for a user's bio, another for a specific project).
Summary updated