Replay Buffer with Local Forgetting for Adapting to Local Environment Changes in Deep Model-Based Reinforcement Learning

Ali Rahimi-Kalahroudi, Janarthanan Rajendran, Ida Momennejad, Harm van Seijen, Sarath Chandar

Introduction

Deep Model-Based Reinforcement Learning (MBRL) is theoretically designed for rapid adaptation. By learning a world model and planning through it, an agent should, in principle, be able to adjust to environment changes—such as a blocked path or a relocated reward—simply by updating its internal model. However, recent research has exposed a significant gap between theory and practice: modern deep MBRL agents often fail to adapt to even simple local changes. This paper, presented at CoLLAs 2023, identifies the standard replay buffer as the primary culprit and introduces the Local Forgetting (LOFO) mechanism as a solution.

The Adaptation Crisis: FIFO Buffers and Local Changes

The core issue lies in the ubiquitous First-In-First-Out (FIFO) replay buffer. In a dynamic environment, FIFO buffers create a dilemma between stability and plasticity:

  1. Large Buffers (Stale Data): If the buffer is large, it retains outdated samples from before the environment changed. The world model, trained on a mix of old and new data, becomes confused by conflicting transitions, leading to inaccurate planning.
  2. Small Buffers (Catastrophic Forgetting): If the buffer is small to facilitate faster updates, the agent quickly forgets distant but still-valid information. As new local experiences evict old global ones, the agent loses its "world map," focusing only on the immediate vicinity of its recent actions.

The LOFO Replay Buffer

To resolve this, the authors propose the LOFO (Local Forgetting) replay buffer. Instead of a global "oldest out" rule, LOFO implements a "local oldest out" strategy. When a new experience is added, the buffer identifies samples in the local neighborhood of that specific state. If that neighborhood is full, only the oldest sample within that vicinity is removed.

Implementing Locality

To determine state proximity, the authors utilize Contrastive Learning to train a state-locality function. This function maps states into an embedding space where states reachable within a few steps are vectorially close. This locality function is typically trained during an initial exploration phase. For recurrent models like DreamerV2, a dual-buffer system is used: a state-buffer manages which states to retain, while a trajectory-buffer stores sequences, masking rewards for states that have been "forgotten."

Experimental Setup: The LoCA Framework

The authors evaluated LOFO using the Local Change Adaptation (LoCA) setup. This framework specifically tests whether an agent can update its knowledge about a local area without forgetting the rest of the environment.

The Local Change Adaptation (LoCA) setup illustrates how training distributions shift between Phase 1 (global) and Phase 2 (local), testing the agent's ability to maintain a global world model while adapting to local reward changes.

As shown in the figure, Phase 1 involves global exploration. In Phase 2, the environment changes (e.g., a reward value shifts), and the agent's training is restricted to a specific sub-zone (the T1-Zone). A successful agent must adapt to the change in T1 while remembering the terminal states in other regions during the evaluation phase.

Key Results and Insights

  • Restoring Adaptability: Advanced agents like PlaNet and DreamerV2, which previously failed the LoCA test using FIFO buffers, became successfully adaptive when equipped with LOFO. They reached near-optimal performance after environment changes that previously paralyzed them.
  • Spatial vs. Temporal Forgetting: LOFO shifts the forgetting mechanism from a temporal basis (how long ago?) to a spatial basis (where did this happen?). This ensures the replay buffer maintains a near-uniform distribution of samples across the entire state space, regardless of the agent's current trajectory.
  • Efficiency: In discrete grid-world tasks (MiniGrid), LOFO achieved superior adaptation while requiring two orders of magnitude less data than the best-performing FIFO configurations, as it only retains the most relevant representatives of each region.
  • Reward Visualization: Heatmaps of internal reward models confirmed that LOFO agents correctly identified new reward locations while maintaining accurate values for distant, unvisited targets. In contrast, FIFO agents either averaged old and new data or zeroed out distant rewards entirely.

Limitations and Future Work

While LOFO significantly improves adaptation to reward changes, some challenges remain. The current locality function is trained on initial physics; if the transition dynamics of the world change drastically, the embedding may become inaccurate. Future work aims to update the locality function online in a truly lifelong learning scenario and to scale these planning routines to even larger, more complex horizons.

Summary updated

BibTeX
@inproceedings{rahimikalahroudi2023replay,
  author = {Ali Rahimi-Kalahroudi and Janarthanan Rajendran and Ida Momennejad and Harm van Seijen and Sarath Chandar},
  title = {{Replay Buffer with Local Forgetting for Adapting to Local Environment Changes in Deep Model-Based Reinforcement Learning}},
  booktitle = {CoLLAs},
  year = {2023},
}
Figure