Stable Hadamard Memory: Revitalizing Memory-Augmented Agents for Reinforcement Learning

Hung Le, Dung Nguyen, Kien Do, Sunil Gupta, Svetha Venkatesh

TL;DR

Stable Hadamard Memory (SHM) is a novel memory architecture designed to help reinforcement learning (RL) agents navigate complex, partially observable environments. By using element-wise Hadamard products and a clever random-parameter calibration mechanism, SHM allows agents to selectively forget or reinforce information with high computational efficiency and mathematically guaranteed gradient stability over long episodes.

What Problem Does This Paper Address?

In many real-world scenarios, RL agents operate in Partially Observable Markov Decision Processes (POMDPs). This means the agent cannot see the whole "map" at once; it must remember past observations (like where it left a key) to make optimal decisions in the present.

While memory models like Transformers and LSTMs have revolutionized supervised learning, they often stumble in RL. The challenges are three-fold:

  1. Stability: Over long sequences, gradients tend to "explode" or "vanish," making it impossible for the agent to learn from events that happened early in an episode.
  2. Flexibility: Agents need to dynamically erase irrelevant information (like a temporary detour) while reinforcing critical information (like a goal location).
  3. Efficiency: Standard matrix-based memories can be computationally expensive, slowing down training.

Existing solutions often trade off one of these traits for another. The authors of this paper sought a "Goldilocks" memory: one that is flexible, fast, and stable.

Methods

The authors introduce the Hadamard Memory Framework (HMF), which treats memory writing as a two-step process:

  • Calibration ($C_t$): An element-wise multiplier that decides which parts of the existing memory to weaken (forget) or strengthen.
  • Update ($U_t$): An additive term that encodes new information into the memory.

The "secret sauce" of Stable Hadamard Memory (SHM) lies in how it handles the calibration matrix. Instead of using a fixed or purely deterministic gate, SHM uses:

  1. Hadamard Products: By operating element-wise rather than through matrix multiplication, the model avoids "mixing" memory cells prematurely and remains computationally efficient ($O(\log t)$ complexity when parallelized).
  2. Random Parameter Selection: To prevent gradient issues, the model samples calibration parameters $\theta_t$ from a pre-defined set at each timestep. This breaks the rigid temporal dependencies that usually lead to vanishing gradients, ensuring the expected value of the memory persistence remains bounded near 1.

Datasets

The researchers evaluated SHM on three rigorous benchmarks:

  • Meta-RL (Wind and Point Robot): Environments where the agent must adapt its strategy to changing dynamics (like wind) or varying goal locations across episodes.
  • Long-horizon Credit Assignment (Visual Match, Key-to-Door): Tasks requiring the agent to remember a stimulus from the very beginning of an episode to receive a reward at the very end.
  • POPGym: A massive benchmark for POMDPs, specifically focusing on the "Hardest" tasks like Battleship, Concentration, and RepeatPrevious.

Key Insights and Ideas

  • The Power of Forgetting: The paper demonstrates that "calibration" (the ability to zero out specific memory cells) is just as important as "writing." In the Visual Match task, visualizations showed SHM explicitly erasing "detour" memories while locking in "color code" memories.
  • Stochastic Stability: One of the most counter-intuitive findings is that randomly sampling calibration parameters actually makes the model more stable. By reducing the linear dependence between timesteps, they minimize the Pearson Correlation Coefficient between updates, which keeps the cumulative product of the memory gates from spiraling out of control.
  • Unified Theory: The authors show that many existing models (like Linear Transformers or Fast Forgetful Memory) are actually restricted versions of their Hadamard framework, providing a theoretical bridge between different memory research branches.

Key Results

Success rates on Long-horizon Credit Assignment tasks (Visual Match and Key-to-Door). SHM achieves 100% success on Visual Match 500.
  • Superior Credit Assignment: In the Visual Match task (500 steps), SHM achieved a 100% success rate, while the next best competitor (FFM) only reached 25%, and others failed completely.
  • POPGym Dominance: On the hardest tasks in the POPGym suite, SHM outperformed established models like GRU and FFM by a relative margin of 10–12% on average.
  • Efficiency: Despite its complexity, SHM’s inference time is nearly as fast as a simple GRU (1.9ms vs 1.6ms per batch), making it practical for real-world RL training.
Success rates on Meta-RL tasks (Wind and Point Robot). SHM learns faster and reaches higher success rates than baselines.
  • Meta-Learning: In Point Robot tasks, SHM reached near-optimal success rates 20–50% faster than other memory-augmented agents.

Limitations and Future Work

  • Parallel Implementation: While the paper provides a theoretical $O(\log t)$ parallel algorithm, some experiments were conducted using a non-parallel recursive form. Fully optimized CUDA kernels for SHM could further widen the speed gap.
  • Hyperparameter Sensitivity: The performance is tied to the memory dimension $H$. While larger $H$ generally helps, it also increases the memory footprint.
  • Scaling to LLMs: The current work focuses on RL agents. A natural next step would be applying the Stable Hadamard mechanism to long-context Large Language Models (LLMs) to see if it can replace standard attention mechanisms in non-RL settings.

Reference: Le, H., Nguyen, D., Do, K., Gupta, S., & Venkatesh, S. (2025). Stable Hadamard Memory: Revitalizing Memory-Augmented Agents for Reinforcement Learning. Published as a conference paper at ICLR 2025. Source Code

Summary updated

BibTeX
@inproceedings{le2025stable,
  author = {Hung Le and Dung Nguyen and Kien Do and Sunil Gupta and Svetha Venkatesh},
  title = {{Stable Hadamard Memory: Revitalizing Memory-Augmented Agents for Reinforcement Learning}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=We5z3UEnUY},
}
Figure