Search

Search papers and lessons

Mastering Diverse Domains through World Models (DreamerV3)

Danijar Hafner, Jurgis Pasukonis, Jimmy Ba et al. · 2023

DreamerV3 learns a world model and trains its actor and critic on imagined rollouts, using one fixed set of hyperparameters across more than 150 tasks.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Reinforcement learning
  • Linear algebra
  • Neural network basics
  • World models
  • Sign in to see your progress

TL;DR

DreamerV3 is a reinforcement learning agent. It learns a world model from its own experience, then trains an actor and a critic entirely on imagined trajectories produced by that model. The same algorithm, with the same hyperparameters, works across more than 150 tasks in eight domains, and it was the first algorithm to collect diamonds in Minecraft from scratch without human data or a curriculum.

Where you'll see it: as a general-purpose baseline for model-based reinforcement learning, and as the reference for how to make a learned world model and its policy stable across tasks whose rewards and observations differ by orders of magnitude.

The problem

Reinforcement learning algorithms are fragile in a specific way. An algorithm that wins on Atari usually needs its learning rate, entropy bonus, network size and replay settings retuned for a new benchmark. Tuning costs compute and expert time, and the tuning is often done per benchmark, so published comparisons quietly favour whoever tuned hardest. Model-free methods such as Proximal Policy Optimization (PPO) are robust but need a great deal of environment interaction. Model-based methods can be sample efficient, but they have their own failure modes: a model that is wrong about small details, a reward scale that changes between games, or a value estimate that chases its own moving target.

The paper asks for one algorithm and one configuration that is good enough everywhere: pixels or vectors, dense or sparse rewards, small or large rewards, 2D or 3D worlds, procedurally generated levels or not. Minecraft diamond collection was the hardest test they chose, because it needs long-horizon planning from sparse rewards in a randomly generated open world, and previous approaches resorted to human expert data and domain-specific curricula.

Key idea

DreamerV3 separates learning into three parts that all share one latent state:

  1. A world model compresses each observation into a latent state and learns to predict the next latent state, the reward and whether the episode continues. It is a Recurrent State Space Model, trained by reconstructing the inputs.
  2. An actor chooses actions from the latent state.
  3. A critic estimates the value of a latent state.

The actor and critic never touch the real environment during learning. They are trained on rollouts that the world model imagines, starting from states the agent actually visited. The rest of the paper is a set of normalisation and loss choices that make this three-part loop behave the same way whatever the scale of the rewards, the observations or the environment.

flowchart LR
  E[Environment] -->|observation, reward| R[Replay buffer]
  R -->|sequences| W[World model<br/>encoder, RSSM, predictors]
  W -->|latent start states| I[Imagined rollout<br/>horizon steps in latent space]
  I --> A[Actor]
  I --> C[Critic]
  A -->|action| E
  C -->|values for returns| A

The method

World model

The encoder maps an observation xtx_t to a stochastic representation ztz_t. The sequence model keeps a deterministic recurrent state hth_t that is updated from the previous state, the previous representation and the previous action. The model state is the concatenation of hth_t and ztz_t, and reward, continuation and reconstruction heads read from it.

The paper's notation for the sequence model and the three predictors is:

ht=fϕ(ht−1,zt−1,at−1),zt∼qϕ(zt∣ht,xt),z^t∼pϕ(z^t∣ht)h_t = f_\phi(h_{t-1}, z_{t-1}, a_{t-1}), \qquad z_t \sim q_\phi(z_t \mid h_t, x_t), \qquad \hat{z}_t \sim p_\phi(\hat{z}_t \mid h_t)

The dynamics predictor pϕ(z^t∣ht)p_\phi(\hat{z}_t \mid h_t) is what the agent uses to imagine the future, because it does not see the observation. The encoder qϕq_\phi is what the agent uses on real data. Training pulls the two together.

The world model loss has three parts. The prediction loss Lpred\mathcal{L}_{\mathrm{pred}} is the negative log likelihood of the observation, the reward and the continuation flag. The dynamics loss Ldyn\mathcal{L}_{\mathrm{dyn}} is a Kullback–Leibler Divergence that trains the sequence model to predict the encoder's next representation. The representation loss Lrep\mathcal{L}_{\mathrm{rep}} is a KL term in the other direction, which pulls the encoder toward what the dynamics predictor can predict. The two KL terms differ only in which side has the stop-gradient. The three terms are combined with weights βpred\beta_{\mathrm{pred}}, βdyn\beta_{\mathrm{dyn}} and βrep\beta_{\mathrm{rep}}; the paper pairs free bits with a small representation loss so that one setting works across visual complexities.

Two details make this stable across domains.

Free bits. Each KL term is clipped below at one nat, about 1.44 bits:

Ldyn=max⁡(1,KL⁡[sg⁡(qϕ(zt∣ht,xt)) ∥ pϕ(zt∣ht)])\mathcal{L}_{\mathrm{dyn}} = \max\bigl(1, \operatorname{KL}[\operatorname{sg}(q_\phi(z_t \mid h_t, x_t)) \,\|\, p_\phi(z_t \mid h_t)]\bigr)

Once the KL is already below one nat the gradient is zero, so the model is not pushed to make the representation trivially predictable at the cost of losing information. Per the paper, this disables the term while it is already well minimised so learning focuses on the prediction loss.

Categorical latents with a uniform mix. The representation is a vector of softmax distributions, sampled with a Straight-Through Estimator. The encoder and dynamics distributions are each mixed as 99 percent network output and 1 percent uniform. This keeps every category probability above a floor, so a KL term cannot blow up when a distribution becomes almost deterministic. The paper reports that earlier experiments had occasional KL spikes of exactly this kind.

Observations pass through symlog before they enter the encoder, and vector-valued reconstruction targets are symlog-transformed too. This keeps inputs of different magnitudes on a common scale.

Critic

The critic predicts a distribution over returns, not a single number. The paper parameterises it as a categorical distribution over exponentially spaced bins, and trains it with a symexp twohot loss, described in the robust predictions section below. The predicted value vtv_t is the mean of that distribution.

Targets are λ\lambda-returns computed in imagination:

Rtλ=rt+γct((1−λ)vt+λRt+1λ),RTλ=vTR^\lambda_t = r_t + \gamma c_t\big((1 - \lambda) v_t + \lambda R^\lambda_{t+1}\big), \qquad R^\lambda_T = v_T

This is the same bootstrapped estimator used in Temporal-Difference Learning and in Generalized Advantage Estimation (GAE), with the discount γ\gamma scaled by the continuation flag ctc_t so that episode ends stop the sum. The critic is regularised toward the output of an exponentially moving average of its own parameters, a target network in the sense of earlier deep RL work.

Actor

The actor is trained with a Policy Gradient on the imagined trajectory, with the critic's value as baseline and an Entropy bonus:

L(θ)=−∑t=1Tsg⁡ ⁣(Rtλ−vψ(st)max⁡(1,S))log⁡πθ(at∣st)+η H⁡[πθ(at∣st)]\mathcal{L}(\theta) = -\sum_{t=1}^{T} \operatorname{sg}\!\Big(\frac{R^\lambda_t - v_\psi(s_t)}{\max(1, S)}\Big) \log \pi_\theta(a_t \mid s_t) + \eta \, \operatorname{H}[\pi_\theta(a_t \mid s_t)]

Here η=3×10−4\eta = 3 \times 10^{-4} is a fixed entropy scale across domains, and SS is the return scale. The paper's reason for this form is that the right amount of exploration depends on the scale of the rewards. If the advantage is normalised by its own standard deviation, sparse rewards get amplified noise that drowns out the entropy term. So the paper normalises returns instead, dividing by a robust range SS that is computed as an exponential moving average of the difference between the 95th and 5th percentiles of the returns, with decay 0.99. The division is only applied when SS is larger than one, so small returns are not amplified.

Robust predictions

Rewards, returns and reconstructions can differ in scale by orders of magnitude between domains. A squared loss on raw targets can diverge; absolute or Huber losses stagnate; normalising targets with running statistics makes the optimisation non-stationary. The paper's answer has two parts.

For deterministic targets the network predicts the symlog of the target, and the prediction is read out with symexp:

symlog⁡(x)=sign⁡(x)ln⁡(∣x∣+1),symexp⁡(x)=sign⁡(x)(exp⁡(∣x∣)−1)\operatorname{symlog}(x) = \operatorname{sign}(x) \ln(|x| + 1), \qquad \operatorname{symexp}(x) = \operatorname{sign}(x)\big(\exp(|x|) - 1\big)

For stochastic targets (rewards and returns) the network outputs logits over bins bib_i whose positions are symexp⁡\operatorname{symexp} of evenly spaced values between −20-20 and +20+20. The prediction is the probability-weighted mean of the bin positions. The target is encoded as a twohot vector: the two bins that bracket the target get weights that sum to one and favour the nearer bin. The loss is cross-entropy against that soft target:

L(θ)=−twohot⁡(y)⊤log softmax⁡(f(x,θ))\mathcal{L}(\theta) = -\operatorname{twohot}(y)^\top \operatorname{log\,softmax}(f(x, \theta))

The loss depends only on the probabilities assigned to the bins, not on the bin positions. So the size of the gradient does not grow with the size of the target, which is the property the paper is after.

Results

The benchmark section of the paper covers eight domains with more than 150 tasks, using one configuration throughout. The table below lists what the paper states in its text. The paper's figures carry the per-task numbers, which are not reproduced here. The eighth domain, BSuite (23 environments, 468 configurations), is omitted from the table; the paper reports a new state of the art there, especially in the reward-scale robustness category.

BenchmarkBudget (as stated in the paper)What the paper reports
Atari, 57 games, sticky actions200M framesOutperforms MuZero and the expert algorithms Rainbow and IQN, with fewer computational resources than MuZero
ProcGen, 16 games50M framesMatches the tuned expert PPG and outperforms Rainbow
DMLab, 30 tasks100M framesExceeds IMPALA and R2D2+ at 1B environment steps, a data-efficiency gain the paper puts above 1000 percent
Atari100k, 26 games400K frames (about 2 hours of game time)Outperforms the best remaining methods, but not EfficientZero, which the paper says uses extra tricks
Proprioceptive control, 18 tasks500K environment stepsNew state of the art, ahead of D4PG, DMPO and MPO
Visual control, 20 tasks1M environment stepsNew state of the art, ahead of DrQ-v2 and CURL
Minecraft diamond36000 steps per episode (30 minutes)Discovers diamonds in 100M environment steps; no compared baseline does

Two more results matter for the argument. The PPO baseline, run with fixed hyperparameters chosen to maximise performance across domains, is substantially worse than Dreamer; the paper reports that Dreamer outperforms it across all domains. The ablations find that every robustness technique contributes, most notably the world model's KL objective, followed by return normalisation and symexp twohot regression; and that Dreamer rests predominantly on the world model's unsupervised (reconstruction) objective. Across six model sizes from 12M to 400M parameters (tested on Crafter and a DMLab task), larger models gave higher performance and lower data requirements, and more gradient updates per environment step reduced the interaction needed. Every Dreamer agent was trained on a single Nvidia A100 GPU, which the authors use to argue that the results are reproducible for many labs.

On Minecraft the paper plots the fraction of trained agents that reach each of the late items in the tech tree. Several strong baselines progress up to the iron pickaxe. Dreamer is the only compared algorithm that reaches a diamond, and all the Dreamer agents trained on it discovered diamonds within 100M environment steps.

Why it mattered

The paper made the case that one model-based algorithm can be a default rather than a tuned specialist. Its robustness tricks (symlog inputs, symexp twohot losses, percentile return normalisation) are small, self-contained pieces that can be lifted into other agents, which is how the paper frames them. Its ablations also indicate that the world model's unsupervised objective carries most of the learning signal, which the authors suggest could allow future variants that pretrain on unsupervised data.

Its limits are real. The results rely on imagined rollouts being accurate enough over the chosen horizon. The paper's evidence for the fixed configuration is empirical across the domains the authors tested.

Reading guide

Read the paper in this order, with these prerequisites in hand:

Check yourself

QuestionWhat is the purpose of the free-bits clip, max(1, KL), in the dynamics and representation losses?Show answer

Without it, the representation can be made trivially predictable by discarding information, which lowers the KL but hurts the reconstruction and reward predictions that the agent depends on. Clipping below one nat means the KL term has zero gradient once it is already small. The optimiser then spends its effort on the prediction loss, and the representation keeps the information needed for control.

QuestionSymlog of 9 is ln(10), about 2.3026. Compute symexp of that value, and then symlog of -99.Show answer

symexp(2.3026) = sign(2.3026) times (exp(2.3026) minus 1) = exp(2.3026) minus 1, which is about 10 minus 1, so 9. The inverse holds. symlog(-99) = sign(-99) times ln(|-99| + 1) = minus ln(100), which is about minus 4.6052. The two values differ by about a factor of 20 in magnitude, but the network only has to produce numbers of similar size, which is the point of the transform.

QuestionWhy does dividing the advantage by max(1, S) not amplify returns when rewards are sparse?Show answer

S is the exponential moving average of the 95th minus 5th percentile of returns. When rewards are sparse, the returns are small, so S is below one, and max(1, S) equals one. The division is then a no-op and the advantage is not scaled up. The paper's reason is that scaling up advantages under sparse rewards amplifies noise that outweighs the entropy term. Dividing only when S is large also means very large returns are scaled down, which is the intended behaviour.

QuestionAn illustrative bin layout has bins at positions 0, 1, 2 and 3. A target of y = 1.3 is twohot encoded. Which two bins get weight, what are the weights, and what is the prediction if the network puts probability 0.5 on bin 1 and 0.5 on bin 2?Show answer

The bracketing bins are at positions 1 and 2. The nearer bin, at 1, gets weight 1 minus 0.3, which is 0.7. The bin at 2 gets 0.3. The weights sum to one. The prediction is the probability-weighted mean of bin positions: 0.5 times 1 plus 0.5 times 2, which is 1.5. The prediction is not restricted to the bin positions, which is why the readout can represent any continuous value in range. This example is illustrative and uses made-up bin positions, not the paper's bins.

QuestionApplied to a new task with a reward scale a thousand times larger than in Atari, which parts of the method are responsible for the agent still learning, and which would you expect to be most sensitive to a change in the fixed hyperparameters?Show answer

Symlog inputs, symexp twohot reward and value heads, and percentile return normalisation are scale-free by construction, so the agent should adapt without retuning. The free-bits KL and the uniform mix keep the world model well behaved across visual complexity. The fixed entropy scale is the part that depends most on the reward structure, but the return normalisation makes it scale-free as well. A sensible answer names the mechanisms and admits that the paper's evidence for the fixed configuration is empirical across its eight domains, not a proof for arbitrary tasks.

Sources

  • Hafner, Pasukonis, Ba, Lillicrap (2023). Mastering Diverse Domains through World Models. arXiv:2301.04104
  • Hafner, Lillicrap, Ba, Norouzi (2019). Dream to Control: Learning Behaviors by Latent Imagination. arXiv:1912.01603

Read the full paper

Danijar Hafner, Jurgis Pasukonis, Jimmy Ba et al., 2023. arXiv:2301.04104