MLP Memory: A Retriever-Pretrained Memory for Large Language Models

Rubin Wei, Jiaqi Cao, Jiarui Wang, Jushi Kai, Qipeng Guo, Bowen Zhou, Zhouhan Lin

TL;DR

MLP Memory is a novel, lightweight parametric module that internalizes external knowledge by learning to mimic the behavior of a $k$-nearest neighbor ($k$NN) retriever. By compressing massive retrieval datastores into a compact neural network, it delivers the accuracy and hallucination-reduction benefits of Retrieval-Augmented Generation (RAG) but runs 2.5× faster and completely avoids the catastrophic forgetting typical of standard fine-tuning.

What Problem Does This Paper Address?

When enhancing Large Language Models (LLMs) with factual knowledge, researchers usually face a frustrating trade-off between two paradigms:

  1. Non-parametric methods (like RAG): These fetch relevant documents dynamically at inference time. While flexible, RAG introduces massive latency due to expensive vector searches and bloated context windows. Furthermore, RAG can easily be derailed by "contextual distractors"—irrelevant text within retrieved documents that misleads the model.
  2. Parametric methods (like Continued Pre-training or LoRA): These bake knowledge directly into the model's weights. While fast at inference time, they risk catastrophic forgetting, often degrading the LLM's general reasoning and language capabilities.
Different approaches to enhancing factual accuracy and knowledge utilization.

The authors introduce MLP Memory to bridge this gap, creating a differentiable, fully parametric module that acts like an internal retriever without ever explicitly accessing external documents during inference.

Methods

MLP Memory functions by training a stack of Multi-Layer Perceptrons (MLPs) to map an LLM's internal hidden states directly to a target vocabulary distribution generated by a $k$NN retriever.

Overview of the MLP Memory architecture during inference and training.

Key components of the approach include:

  • Token-Independent Architecture: The memory module consists purely of stacked MLP layers (Feed-Forward and Add & Norm) without any token-mixing attention mechanisms. This makes it computationally lightweight.
  • Hybrid Training Objective: To accurately capture the retriever's behavior, the authors use a two-part loss function: $$\mathcal{L} = \alpha \mathcal{L}_{KL} + (1 - \alpha) \mathcal{L}_{CE}$$ The Kullback-Leibler (KL) divergence term forces the MLP to match the full, information-rich probability distribution of the $k$NN retriever, while the Cross-Entropy (CE) loss ensures ground-truth token accuracy.

  • Inference Interpolation: During generation, the native output distribution of the base LLM is simply interpolated with the distribution from the MLP Memory using a hyperparameter $\lambda$: $$p_{final} = \lambda p_{MLP} + (1 - \lambda) p_{LM}$$

Datasets

The authors validated their approach using a wide array of datasets for both pretraining and downstream evaluation:

  • Pretraining & Scaling Laws: WikiText-103 and a large, mixed Web dataset (combining WikiText-103, Amazon Reviews, CC-NEWS, and IMDB).
  • Open-Domain & Long-Form QA: Natural Questions (NQ), WebQA, TriviaQA, TruthfulQA, and HotpotQA.
  • General NLP Benchmarks: Nine tasks spanning sentiment classification, textual entailment, and topic classification (including SST-2, MR, CR, RT, HYP, CB, RTE, AGN, and Yahoo).
  • Hallucination Evaluation: The HaluEval benchmark across dialogue, QA, and summarization tasks.

Key Insights and Ideas

  • Extreme Memory Compression: MLP Memory acts as an incredibly efficient compressor. It condenses massive $k$NN datastores (which can take up to 40TB of storage for 5B tokens) into a compact 4GB parametric module (1B parameters) without sacrificing performance.
  • The 70% Depth Sweet Spot: While traditional $k$NN-LMs perform best when extracting retrieval keys from the very final layer of an LLM, the authors discovered that MLP Memory achieves optimal performance when hooked into representations at roughly 70% of the network's depth.
  • Distribution Sharpness: Standard language models produce smooth, dense probability distributions, whereas $k$NN retrievers produce highly sparse, "spiky" distributions. MLP Memory naturally strikes a perfect middle ground—sharper than a standard LM, yet smooth enough to retain predictive power and generalizability.

Key Results

The experimental results demonstrate substantial improvements in both capability and speed:

  • Inference Speedups: MLP Memory achieved a 2.5× faster Time-to-First-Token (TTFT) compared to standard top-5 RAG, and was 5.6× faster than a dimension-reduced $k$NN-LM.
  • QA Performance: When integrated with Mistral-7B, it delivered a 12.3% relative improvement across five QA benchmarks, notably outperforming both RAG and $k$NN-LM on WebQA (37.45% vs 29.28% baseline).
  • Hallucination Mitigation: On the HaluEval benchmark, MLP Memory reduced hallucinations significantly, yielding accuracy gains of 9.68 points in dialogue and 10.08 points in QA.
Performance and inference efficiency comparisons across benchmarks.

Limitations and Future Work

While highly effective, the authors note some challenges and areas for future exploration:

  • Optimization Difficulty: The retriever imitation task is inherently complex because the module must learn to predict entire distributions rather than single target tokens. As a result, the training process is computationally demanding and requires a substantial training budget to fully optimize.
  • Static Knowledge Base: Because the retrieval patterns are baked into the MLP weights during pretraining, updating the memory with real-time or rapidly changing information without retraining remains an open question. Future work could investigate methods for dynamic weight updating or modular memory swapping.

Summary updated

BibTeX
@inproceedings{wei2026mlp,
  author = {Rubin Wei and Jiaqi Cao and Jiarui Wang and Jushi Kai and Qipeng Guo and Bowen Zhou and Zhouhan Lin},
  title = {{MLP Memory: A Retriever-Pretrained Memory for Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=1SMdxRtLBp},
}
Figure