Dreamer: Learning World Models
Dreamer (and its successors DreamerV2, DreamerV3) is a model-based reinforcement learning agent that learns a latent dynamics model—called a world model—entirely from high-dimensional sensory observations, then trains both actor and critic entirely inside imagined rollouts of that model, never touching the real environment during policy optimization. It matters because it achieves data efficiency orders of magnitude beyond leading model-free algorithms on visual control tasks, demonstrating that sufficiently accurate world models can substitute for environment interaction during learning. Remarkably, DreamerV3 is the first algorithm to collect diamonds in Minecraft from scratch without human demonstrations or domain-specific rewards—a benchmark considered intractable for prior methods.
The key insight is the decoupling of world model learning from behavior learning: the agent learns a compact, predictive latent representation of the world from real data, and then treats that learned simulator as a cheap, differentiable environment in which actor-critic gradients can be computed through time via backpropagation through imagined trajectories. This means policy gradients flow through the dynamics model itself rather than being estimated purely from Monte Carlo rollouts, dramatically reducing variance. The "aha moment" is realizing that if your world model is good enough, you can learn an excellent policy while spending almost no additional real-world interaction budget—imagination becomes the primary training signal.
How It Works
Dreamer decomposes learning into three interleaved phases: (1) fitting the Recurrent State Space Model (RSSM) world model to a replay buffer of experience, (2) imagining multi-step trajectories from the learned latent dynamics, and (3) training actor and critic on those imagined trajectories via backpropagation through time (BPTT).
The Recurrent State Space Model (RSSM)
The RSSM maintains a latent state (deterministic GRU hidden state) and a stochastic component , separating deterministic memory from stochastic uncertainty. The joint state forms the full model state.
Explanation: The deterministic recurrent function (a GRU) updates the hidden state by conditioning on the previous latent state and action , creating a temporal memory that carries information across time steps.
Symbols: is the GRU hidden state at step ; is the previous stochastic latent; is the previous action; denotes world model parameters. The stochastic posterior (used during training) and prior (used during imagination) are:
Explanation: During training the posterior refines the latent using the actual observation , while during imagination the prior generates the next stochastic state from the recurrent state alone, enabling rollouts without real data.
Symbols: is the encoder/posterior network; is the transition prior; is the high-dimensional observation (e.g., image). In DreamerV2/V3 the stochastic latent is a vector of categorical distributions (straight-through gradients), not a Gaussian—this empirically reduces posterior collapse.
World Model Training Objective
The world model is trained by maximizing the Evidence Lower Bound (ELBO) over sequence data:
Explanation: The objective simultaneously trains a decoder to reconstruct observations and rewards from latent states and pushes the posterior toward the prior, balancing representation fidelity against the compactness of learned dynamics.
Symbols: is the observation decoder; is the reward predictor; is the KL balance coefficient (DreamerV3 uses free bits and dynamic balancing); is the Kullback–Leibler divergence.
Behavior Learning via Imagined Rollouts
Starting from states in the replay buffer, the actor is unrolled for imagination steps entirely within the world model, producing imagined trajectories . The critic estimates -returns (a TD() target combining bootstrapped and Monte Carlo estimates):
Explanation: The -return interpolates between one-step TD (low variance, high bias) and full Monte Carlo returns (high variance, low bias) within the imagination horizon, giving a balanced advantage estimate for the actor gradient.
Symbols: is the imagined reward; is discount factor; controls bias-variance tradeoff (typically 0.95); is the imagined latent state. The actor is updated by maximizing:
Explanation: Actor gradients are backpropagated through the entire imagined trajectory—including through the differentiable world model dynamics—enabling low-variance, gradient-based policy improvement without returning to the real environment.
Symbols: The expectation is over imagined actions sampled from ; gradients flow through back through via straight-through estimation for the categorical latents.
DreamerV3 Innovations
DreamerV3 (2023, Hafner et al.) introduced several robustness improvements enabling single-hyperparameter training across wildly different domains:
- Symlog encoding: Replaces raw reward/return magnitudes with , allowing a single learning rate to handle rewards spanning many orders of magnitude.
- Two-hot encoding of returns: The critic predicts a categorical distribution over a fixed support, avoiding scale sensitivity entirely.
- KL balancing: Separately scales the representation loss and dynamics loss within the KL term to prevent posterior collapse.
Danijar Hafner completed his PhD at the University of Toronto and Google Brain, working at the intersection of latent variable models and reinforcement learning. He is the lead author of the entire Dreamer series—introducing the RSSM architecture in the original Dreamer paper (2019), scaling it with categorical latents and actor-critic improvements in DreamerV2 (2020), and achieving domain-agnostic general intelligence benchmarks in DreamerV3 (2023). Remarkably, Hafner developed much of the early Dreamer codebase as a solo researcher, and DreamerV3's Minecraft diamond result emerged from a system trained with identical hyperparameters across all 150+ benchmark tasks including Atari, DMControl, and ProcGen simultaneously.
Timothy Lillicrap (DeepMind) is best known as a co-author of DDPG and the biological plausibility of backpropagation, but his earlier work on continuous control and latent-space imagination directly influenced the actor-critic framework Dreamer builds upon. His collaboration with David Silver on value-gradient methods helped establish the theoretical grounding for differentiating through learned dynamics models. Lillicrap trained as a computational neuroscientist before transitioning to deep RL, and his interest in biologically plausible learning algorithms informs an unconventional angle: he views world models as mechanistically analogous to the predictive coding framework hypothesized in the mammalian neocortex.
Intuition
Imagine a chess grandmaster who has played thousands of games and has built a deeply internalized mental model of how the board evolves. To improve, they no longer need to play real games; instead they close their eyes and simulate thousands of positions in their head, running through imagined continuations and learning which strategies succeed. Dreamer is precisely this: the RSSM is the grandmaster's internal chess engine (learned from real games stored in the replay buffer), and the actor-critic is trained entirely by watching the grandmaster's imagination unfold—never touching the real board during policy improvement. The critical subtlety is that this inner world model is learned, not hand-coded: it starts blank and bootstraps its own physics, rewards, and dynamics purely from pixels or sensor data. The categorical latent acts like a compressed "situation code"—a few dozen discrete categories capturing the essential state of the world, analogous to recognizing a chess position as belonging to a "Sicilian defense middle-game" rather than memorizing every piece position individually.