Integrated Episodic and Semantic Memory via Modulating Transformer FeedForward Layers

Yiqun Yao, Xiang Li, Xin Jiang, Xuezhi Fang, Naitong Yu, Siwei Dong, Wenjia Ma, Jing Li, Aixin Sun, Yequan WangICML 2026

Introduction

Human intelligence relies on two distinct but deeply integrated memory systems: episodic memory (remembering specific events tied to a time and place) and semantic memory (general knowledge about the world). In the realm of Large Language Models (LLMs), these systems are historically disjointed. Models store semantic knowledge in their static weights during pre-training, while episodic memory is temporarily simulated using a Key-Value (KV) cache that stores recent conversation history.

This paper introduces HyperMem, a novel framework that bridges this gap. By using a hypernetwork to map input contexts into dynamic weight modulations, HyperMem allows LLMs to store both specific events and general knowledge directly within their FeedForward parameters. This achieves state-of-the-art memory retrieval and long-context reasoning without the massive computational overhead of traditional KV caches.

The Challenge: Volatility and Quadratic Scaling

The traditional KV cache approach to episodic memory suffers from two major flaws:

  1. Quadratic Scaling: As the context grows, the KV cache becomes massive and slow to process, scaling with $O(N^2)$ complexity.
  2. Volatility: Once the context window is full, the model "forgets" earlier events unless they are explicitly re-processed.

Existing alternatives, such as knowledge editing or test-time training, are often too slow or computationally expensive for real-time use. The authors address this by baking episodic memory directly into the model's parameters on the fly.

The HyperMem Architecture

HyperMem treats the Transformer’s FeedForward Network (FFN) layers as a dynamic memory bank. The architecture consists of three main components:

  1. Memory Injection: As the model reads text, it maintains a fixed-size Recurrent Memory Pool at each layer. Instead of keeping every token, a LoRA-based encoder incrementally updates these memory slots.
  2. The Hypernetwork: Acting as the "brain" of the system, the hypernetwork takes the state of the memory pool and projects it into parameter updates ($\Delta W$) for the FFN layers—specifically targeting the up, down, and gate projections.
  3. Hyper-LoRA Modulation: These generated updates are added to the frozen base model weights. Unlike standard LoRA, these weights are not learned through backpropagation at test time; they are generated instantly by the hypernetwork based on the input.

Training Strategy

The model undergoes a sophisticated two-stage training process:

  • Post-training: Uses a subset of FineWeb-Edu to train on two objectives: random-access associative memory (reconstructing tokens given a small hint) and continuation (predicting the next chunk of a document based on installed memory).
  • Fine-tuning (SFT): Adapts the model to long-context tasks using datasets like LongAlpaca, Booksum, and SlimPajama-long.

Key Insights and Results

Extensive evaluations on benchmarks like LongBench, MemGPT-MSC, and custom Raw Text Retrieval revealed several critical insights:

  • FFNs as Memory Slots: The research reinforces that FFN layers (MLPs) are the primary site of "knowledge" in Transformers. Modulating FFNs proved significantly more effective for memory retention than modulating Attention layers.
  • Context-Free Retrieval: Because memory is stored directly in the weights, the model can answer questions about a document without having that document in its current context window. This eliminates the $O(N^2)$ attention cost during generation, making HyperMem roughly 3x faster in inference than full-context models for very long sequences.
  • Superior Retrieval Performance: On raw text retrieval, HyperMem achieved an impressive F1 score of 0.876, vastly outperforming the previous state-of-the-art context-free model, Generative Adapter (0.390), while using a similar memory footprint.
  • Long-Range Stability and Zero Interference: HyperMem maintains stable performance even after 20+ "injection steps" (reading 20+ chunks of text), whereas competing methods like MemoryLLM show rapid degradation. Furthermore, modulating the weights to store new memories does not degrade the model's performance on unrelated general tasks, avoiding "catastrophic forgetting."
  • Reconstructive Memory: Unlike a KV cache that stores exact token copies, HyperMem's parameter-based memory is generative. Case studies show the model occasionally makes small errors but can "self-correct" and stay on track, closely mimicking the reconstructive nature of human memory.

Limitations and Future Directions

While HyperMem establishes a new state of the art for hypernetwork-based memory mechanisms, it has limitations. Due to GPU memory constraints, the authors could only backpropagate through 13 injection steps during training, limiting how deeply the model can learn to integrate extremely long sequences. Additionally, the paper uses a fixed memory size ($K=258$ slots); scaling laws for how memory capacity should grow with model size or context length remain an open question.

Ultimately, HyperMem demonstrates that directly bridging data and parameters provides a highly viable direction for exploring next-generation foundation models with flexible, persistent, and efficient memory capabilities.

Summary updated

BibTeX
@inproceedings{yao2026integrated,
  author = {Yiqun Yao and Xiang Li and Xin Jiang and Xuezhi Fang and Naitong Yu and Siwei Dong and Wenjia Ma and Jing Li and Aixin Sun and Yequan Wang},
  title = {{Integrated Episodic and Semantic Memory via Modulating Transformer FeedForward Layers}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=7D5WD70jKj},
}
Figure