Dreaming of Many Worlds: Learning Contextual World Models Aids Zero-Shot Generalization

Sai Prasanna, Karim Farid, Raghu Rajan, André Biedenkapp · DOI

Model-Based Reinforcement Learning (MBRL) is often praised for its sample efficiency, as agents learn a "world model" to simulate and plan within their environment. However, these models are notoriously brittle: an agent trained to walk on Earth will likely fail on the Moon because the underlying physics have changed. Achieving Zero-Shot Generalization (ZSG)—the ability to perform in novel scenarios without further training—remains a significant hurdle.

Researchers from the University of Freiburg address this by introducing the Contextual Recurrent State-Space Model (cRSSM). By explicitly conditioning the world model on environmental context, they enable agents to "dream" of many worlds and generalize to unseen physical conditions.

The Contextual Recurrent State-Space Model (cRSSM)

The authors build upon DreamerV3, a state-of-the-art MBRL agent that utilizes a latent world model consisting of a deterministic state ($h$) and a stochastic state ($z$). In standard implementations, environmental changes are often treated as noise. In contrast, the cRSSM explicitly incorporates a context vector ($c$)—representing privileged information like gravity or object mass—into every major component of the architecture.

Comparison between a standard generative model for a cMDP (a) and the proposed cRSSM architecture (b).

As shown in the architecture above, the context $c$ influences:

  • The Transition Model: Predicting the next state now depends on the current state, action, and context.
  • Observation and Reward Models: Reconstructing visual inputs and predicting rewards are made context-aware.
  • The Actor-Critic: The policy and value functions are conditioned on $c$, allowing the agent to tailor its strategy to the specific "rules" of the current environment.

This design enables Counterfactual Dreaming. An agent can take a single observation from one environment and "imagine" what would happen under different physical constants by simply swapping the context vector during its internal simulations.

Experimental Setup and Results

The researchers evaluated cRSSM using the CARL (Contextual and Adaptive Reinforcement Learning) benchmark, focusing on tasks like CartPole and DMC Walker. They specifically tested the agent's ability to extrapolate to physical parameters (e.g., pole length, gravity) far outside the range seen during training.

The results demonstrate that explicit context conditioning is superior to common "hacks" like simply concatenating context to the input. In the CartPole pixel-based task, where the agent must infer state from raw images, cRSSM maintained expert-level performance even when the pole length was significantly increased beyond the training distribution.

Zero-shot generalization performance on the Cartpole pixel task. The green shaded area represents the training range; cRSSM (red) maintains high returns in the extrapolation regime compared to baselines.

Key insights from the experiments include:

  1. Disentanglement: By providing context explicitly, the model learns to separate "what is happening" (the latent state) from "how the world works" (the context).
  2. Visual Understanding: Qualitatively, cRSSM demonstrates a better grasp of physics. When asked to reconstruct images of a pole longer than any seen in training, it successfully renders the correct length, whereas baselines default to the maximum training value.

Limitations and Future Directions

A primary limitation of this work is the requirement for observable context. In many real-world applications, physical constants like friction coefficients are not directly provided; they must be inferred.

Future research will focus on Context Inference, where the model estimates $c$ from a short sequence of interactions. Additionally, Counterfactual Training—using the model's ability to dream of many worlds to expose the agent to a wider variety of imagined scenarios during training—could further enhance robustness before an agent ever encounters a new environment.

By moving from learning a single world to learning how worlds vary, cRSSM represents a significant step toward RL agents that can truly generalize across the diverse physical realities of the real world.

Summary updated

BibTeX
@inproceedings{prasanna2024dreaming,
  author = {Sai Prasanna and Karim Farid and Raghu Rajan and André Biedenkapp},
  title = {{Dreaming of Many Worlds: Learning Contextual World Models Aids Zero-Shot Generalization}},
  booktitle = {RLC},
  year = {2024},
  url = {https://openreview.net/forum?id=o8DrRuBsQb},
}
Figure