# Dream to Control: Learning Behaviors by Latent Imagination

Dreamer learns behaviors by imagining rollouts in a learned latent space

Danijar Hafner, Timothy Lillicrap, Jimmy Ba, Mohammad Norouzi · arXiv · 2019-12-3

- **Problem** Model-based agents that look only a fixed horizon ahead behave shortsightedly, and many earlier methods skip the analytic gradients that learned dynamics provide.
- **Method** Dreamer trains an action model and a value model only on imagined latent trajectories. It backpropagates value gradients through the learned dynamics, instead of using derivative-free optimization.
- **Results** Dreamer reaches an average score of 823 across visual control tasks, above D4PG's 786 with far fewer steps.

## Why short look-ahead limits model-based control

Once a world model exists, behaviour can be derived from it in several ways, most often by maximizing imagined rewards with a parametric policy or by planning online at decision time. When the imagined reward sum stops at a fixed horizon, the resulting behaviour favours near-term payoff and misses consequences that appear later. Many earlier latent-dynamics methods also rely on derivative-free optimization to stay robust to model errors, which leaves unused the analytic gradients that neural network dynamics can supply.

Actor critic methods that learn online or from replayed experience can be trained on real returns, but they do not use a model to interpolate between past transitions or to differentiate through multi-step returns. The authors argue that a world model closes this gap, because it offers gradients of multi-step returns that can be used for efficient policy optimization.

The setting is visual control, which the authors formalize as a partially observable Markov decision process in which the agent sees images and scalar rewards, and must maximize the expected sum of rewards.

## Latent dynamics as the imagination engine

The latent dynamics model has three parts: a representation model that encodes observations and actions into model states, a transition model that predicts the next model state without seeing the image, and a reward model that predicts rewards from model states. The representation model is written as \\(p(s\_t \\mid s\_{t-1}, a\_{t-1}, o\_t)\\), the transition model as \\(q(s\_t \\mid s\_{t-1}, a\_{t-1})\\), and the reward model as \\(q(r\_t \\mid s\_t)\\), where \\(p\\) denotes distributions over the real environment and \\(q\\) their approximations.

Because the transition model moves forward in the compact latent space, the agent never has to render or observe the corresponding images to imagine a rollout. This keeps the memory footprint small, so thousands of imagined trajectories can be simulated in parallel.

Imagined trajectories begin at model states computed from sequences of past experience, then follow the transition model, the reward model and a policy. The imagined objective is the expected discounted sum of imagined rewards, taken with respect to the policy. The overall loop alternates learning the dynamics from the dataset, learning behaviour in imagination, and acting in the environment to grow the dataset.

## Action and value models trained through imagined returns

The action model is a dense network that defines the policy in latent space, and the value model is a dense network that estimates the expected imagined reward from each model state. The action model outputs a tanh-transformed Gaussian, which follows the approach used for soft actor critic.

Actions are drawn by reparameterized sampling, so each action is a deterministic function of the network outputs and a noise term, with \\(a\_\\tau = \\tanh(\\mu\_\\phi(s\_\\tau) + \\sigma\_\\phi(s\_\\tau)\\epsilon)\\) and \\(\\epsilon \\sim \\mathrm{Normal}(0, I)\\). This lets analytic gradients flow backward through the sampling step into the action model parameters \\(\\phi\\).

Three value estimates are compared: a plain sum of imagined rewards up to the horizon, a k-step estimate that bootstraps from the learned value model, and \\(V\_\\lambda(s\_\\tau)\\), which is an exponentially weighted average of the k-step estimates over different k. The plain sum ignores rewards beyond the horizon and allows learning an action model without any value model, which the experiments use as an ablation.

Dreamer uses \\(V\_\\lambda\\), which trades bias against variance by mixing short and long returns.

The action model is trained to maximize the sum of \\(V\_\\lambda(s\_\\tau)\\) along imagined trajectories, and the value model is trained to regress those same targets, with the gradient stopped through the targets. The action model receives analytic gradients through the learned dynamics, because the value estimates depend on predicted rewards and values, which depend on the imagined states and actions.

The world model is kept fixed during this step, and when a task terminates early, the model also predicts a discount factor that down-weights later imagined steps.

Actor critic methods that use REINFORCE gradients, such as A3C and PPO, rely on value baselines to reduce variance, whereas Dreamer backpropagates through the value model. Deterministic and reparameterized actor critics such as DDPG and SAC use gradients of immediate action values but do not pass gradients through transitions, which the authors list as the difference from their approach.

## Benchmark results on 20 visual control tasks

The evaluation uses 20 visual tasks from the DeepMind Control Suite, with 64×64×3 image observations, action dimensions from 1 to 12, rewards between 0 and 1, and 1000-step episodes with randomized initial states. A fixed action repeat of 2 is used for every task, and the same hyper parameters are applied across all continuous tasks.

The top model-free baseline, D4PG, reaches an average of 786 after 10^8 steps, so Dreamer exceeds it with a much smaller step budget. Results are averages over 5 seeds, and PlaNet was re-run with an action repeat of 2 for a unified setup.

Dreamer keeps the data efficiency of PlaNet, which the authors read as evidence that the learned world model generalizes from small amounts of experience. The D4PG scores use pixel inputs and the A3C scores use state inputs, both taken from Tassa et al., so these baselines are reported scores rather than runs under the same conditions as Dreamer.

## Imagination horizon and the value model

The horizon sweep runs from 10 to 40 on four tasks: Cartpole Swingup, Cheetah Run, Quadruped Walk and Walker Walk. It compares Dreamer with a variant that learns an action model without value prediction, and with online planning using PlaNet, all with pixel reconstruction and action repeat 2.

Across these horizons, the variant with a learned value model stays more robust to the horizon length than the variant without value prediction. The authors attribute this to the value model estimating rewards beyond the imagination horizon, which lets short horizons still capture long-term payoff.

In the appendix comparison at horizon 20, Dreamer outperforms the alternatives on 16 of 20 tasks, with 4 ties. The same text describes these curves as covering 19 tasks in one sentence, so the task count for that appendix comparison is stated inconsistently.

## Choice of representation learning objective

Three objectives are compared: image reconstruction, which uses the observation model and a KL regularizer under the variational lower bound; contrastive estimation, which predicts states from images and keeps them diverse across a batch with noise contrastive estimation; and reward prediction alone. Reconstruction is the default objective in the experiments that do not state otherwise, because it is the one the world model was built on.

Pixel reconstruction performs best on most tasks, and the contrastive objective solves about half of the tasks. Predicting rewards alone was not sufficient in these experiments.

The authors read these differences as a sign that progress in representation learning will carry over into better Dreamer performance.

## Discrete actions and early termination

The authors evaluate Dreamer on a subset of Atari games and on DeepMind Lab levels, which use discrete actions and can terminate early. Dreamer learns successful behaviors on this subset and on the object collection level of DeepMind Lab.

For these tasks the action model predicts a categorical distribution, so straight-through gradients are used for the sampling step. The paper's evaluation details and training curves for these tasks are in its appendix, and the body presents them only as evidence that the method applies to discrete actions.

## Limitations and open questions

The world model is fixed while the behaviour is learned, so improvements to the policy cannot change the model itself during that step. The authors suggest that scaling latent imagination to environments of higher visual complexity will depend on future progress in representation learning.

The horizon sweep covers only four tasks, while the appendix comparison at horizon 20 covers the wider task set. The discrete control results are reported on a subset of Atari games and DeepMind Lab levels.

## Paper info

- **Authors**: Danijar Hafner, Timothy Lillicrap, Jimmy Ba, Mohammad Norouzi
- **Venue**: arXiv · Preprint
- **First published**: 2019-12-3
- **Added**: 2026-11-6
- **Updated**: 2020-3-17
- **Version**: v3
- **arXiv**: 1912.01603
- **Category**: cs.LG · cs.AI · cs.RO
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1912.01603v3) · [PDF ↗](https://arxiv.org/pdf/1912.01603v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Danijar Hafner, Timothy Lillicrap, Jimmy Ba, Mohammad Norouzi (2019). Dream to Control: Learning Behaviors by Latent Imagination. arXiv:1912.01603v3. https://arxiv.org/abs/1912.01603v3

**BibTeX**

```
@misc{hafner2019dream,
  title = {{Dream to Control: Learning Behaviors by Latent Imagination}},
  author = {Danijar Hafner and Timothy Lillicrap and Jimmy Ba and Mohammad Norouzi},
  year = {2019},
  eprint = {1912.01603},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1912.01603v3}
}
```

## Other paper commentary

- [High-Dimensional Continuous Control Using Generalized Advantage Estimation](https://refivu.com/en/papers/95183c94-f386-4a6d-8fda-f7e55021273b-high-dimensional-continuous-control-using-generalized.md)
- [Hindsight Experience Replay](https://refivu.com/en/papers/582040c2-0070-4d83-904a-97d112d29239-hindsight-experience-replay.md)
- [QT-Opt: Scalable Deep Reinforcement Learning for Vision-Based Robotic Manipulation](https://refivu.com/en/papers/7cb7d7d4-7a03-4f1d-bbc0-2ddaf1103d5a-qt-opt-scalable-deep-reinforcement-learning-for-vision.md)
- [Learning Agile Soccer Skills for a Bipedal Robot with Deep Reinforcement Learning](https://refivu.com/en/papers/3ef41329-5e9b-477a-9ece-c7d4b12b603d-learning-agile-soccer-skills-for-a-bipedal-robot.md)
- [Real-World Humanoid Locomotion with Reinforcement Learning](https://refivu.com/en/papers/8e42e14f-83b7-4879-ab8c-1bd8a7bcea8a-real-world-humanoid-locomotion-with-reinforcement-learning.md)
- [Precise and Dexterous Robotic Manipulation via Human-in-the-Loop Reinforcement Learning](https://refivu.com/en/papers/f8ac2bf8-18ae-41b1-9229-515501c8d0d8-precise-and-dexterous-robotic-manipulation-via-human-in.md)
- [Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions](https://refivu.com/en/papers/596b5353-6c04-4ada-a92e-25d0fee13147-natural-tts-synthesis-by-conditioning-wavenet-on-mel.md)
- [SSD: Single Shot MultiBox Detector](https://refivu.com/en/papers/1889995f-3f80-4a7d-b734-c549e845a707-ssd-single-shot-multibox-detector.md)
- [Two-Stream Convolutional Networks for Action Recognition in Videos](https://refivu.com/en/papers/d621dee0-0b2a-45a8-b152-6260b98f0db4-two-stream-convolutional-networks-for-action-recognition-in.md)
- [Prompting Is Programming: A Query Language for Large Language Models](https://refivu.com/en/papers/688fcde1-89d3-44fe-b9ec-673455f09c78-prompting-is-programming-a-query-language-for-large.md)
- [Multimodal Machine Learning-based Knee Osteoarthritis Progression Prediction from Plain Radiographs and Clinical Data](https://refivu.com/en/papers/2b4e96e0-64f3-4752-8b7e-3e4c0c68dc86-multimodal-machine-learning-based-knee-osteoarthritis.md)
- [Collaborative Federated Learning For Healthcare: Multi-Modal COVID-19 Diagnosis at the Edge](https://refivu.com/en/papers/716b1271-0a25-4e75-a046-8918241dcd06-collaborative-federated-learning-for-healthcare-multi-modal.md)

## Terms in this paper

- [Reward model](https://refivu.com/en/terms/76346da527c5-reward-model)
- [variational lower bound](https://refivu.com/en/terms/49024a039d18-variational-lower-bound)
- [A3C](https://refivu.com/en/terms/1c4cb426dcf9-a3c)
- [partially observable Markov decision process](https://refivu.com/en/terms/4e32d4575cd4-partially-observable-markov-decision-process)
- [world model](https://refivu.com/en/terms/512003c04953-world-model)
- [DeepMind Lab](https://refivu.com/en/terms/1d226c83e6ae-deepmind-lab)
- [Noise Contrastive Estimation](https://refivu.com/en/terms/2bfec15cdb82-noise-contrastive-estimation)
- [stochastic backpropagation](https://refivu.com/en/terms/9a4a737a668b-stochastic-backpropagation)
- [image reconstruction](https://refivu.com/en/terms/5e7ec373d1ec-image-reconstruction)
- [PlaNet](https://refivu.com/en/terms/aec227e71098-planet)
- [variational information bottleneck](https://refivu.com/en/terms/2d2e38b839fa-variational-information-bottleneck)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/20a4d063-3ef9-48fc-88cb-307287206e29-dream-to-control-learning-behaviors-by-latent-imagination)
