Mastering Atari with Discrete World Models: DreamerV2

Discrete World model DreamerV2

In alliance with Deep Mind and the University of Toronto, Google has released DreamerV2, the very first Reinforcement Learning agent that achieves human-level Atari performance. The paper was released under this name: Mastering Atari with Discrete World Models by Danijar Hafner, Timothy Lillicrap, Mohammad Norouzi, Jimmy Ba. Reinforcement Learning methods have made quite a progress in a short time. These approaches have successfully beaten their respective world champions by using model-free learning methods to model-based methods. 

DreamerV2, a model-based method in which the agent predicts the output of the potential actions performed to make informed decisions for a new scenario. The proposed method uses the Dreamer agent from DreamerV1 with a bit of adjustification. Using a single GPU and a single environment instance, DreamerV2 outperforms top model-free single-GPU agents within the same computational budget and training time. 

The Model Architecture of DreamerV2

AIM Daily XO

Join our editors every weekday evening as they steer you through the most significant news of the day, introduce you to fresh perspectives, and provide unexpected moments of joy
Your newsletter subscriptions are subject to AIM Privacy Policy and Terms and Conditions.

DreamerV2 consists of 3 components mainly:

  1. Learn a world model from the dataset of past experience.

DreamerV2 is built upon the Recurrent State-Space Model(RSSM), the backbone of this step. The training data is encoded using CNN, where each image is changed into a stochastic representation(z1 – z3) and is further stored in a recurrent state(h1 – h3). With recurrent state and stochastic representations, the model tries to reconstruct the model’s same image to learn general representations. And predict reward based on the actions(a1-a2) performed.

Download our Mobile App

Unlike DreamerV1 agent, DreamerV2 agent represents each image with categorical variables(for multimodal distribution) instead of using normal(continuous) variables and that’s why this model is named as Discrete World Model. The above encoder converts each image into 32 distributions over 32 classes, and the world model itself learns these distributions and classes. The one-hot vectors are then sampled from the distribution generated and are added to a sparse representation, which the model passes to a recurrent state. To backpropagate through the samples, we use straight-through gradients that are easy to implement using automatic differentiation. The second difference that DreamerV2 has is its loss function. It uses KL balancing, which trains the prior(prediction) and regularizes how much information the posterior(stochastic representations) incorporates from the image. The regularization increases robustness to novel inputs. It also encourages reusing existing information from past steps to predict rewards and reconstruct images, thus learning long-term dependencies.

  1. Learn an actor and critic from imagined sequences of compact model states. To learn the predictions from an observation, DreamerV2 uses actor-critic learning for imagination.
  1. and execute the actor in the environment to grow the experience dataset.

More details about its architecture can be found here.

Performance of DreamerV2

The picture shown below is the predictions of a model world, DreamerV2. The top row represents the episode of a game, and the bottom row contains the predictions from the DreamerV2 model.

Requirements & Installation

Install all the dependencies of the proposed method via pip.

 pip install --user tensorflow==2.3.1
 pip install --user tensorflow_probability==0.11.1
 pip install --user pandas
 pip install --user matplotlib
 pip install --user ruamel.yaml
 pip install --user 'gym[atari]' 

Clone the repository through git.

 !git clone
 %cd dreamerv2 

Train your Dreamer

Train the dreamerV2 model on a single GPU on Colab Notebook. The code is given below:

 !python --logdir ~/logdir/atari_pong/dreamerv2/1 \
     --configs defaults atari --task atari_pong 

You can further monitor the results by using tensorboard.

%tensorboard --logdir ~/logdir

Generate plots by :

!python --indir ~/logdir --outdir ~/plots --xaxis step --yaxis eval_return --bins 1e6


In this article, we have given a short introduction of DreamerV2 model, the very first model-based reinforcement learning algorithm that achieves human-level performance on Atari benchmark and outperforms many model-free methods.

Reference material are as follows:

Sign up for The Deep Learning Podcast

by Vijayalakshmi Anandan

The Deep Learning Curve is a technology-based podcast hosted by Vijayalakshmi Anandan - Video Presenter and Podcaster at Analytics India Magazine. This podcast is the narrator's journey of curiosity and discovery in the world of technology.

Aishwarya Verma
A data science enthusiast and a post-graduate in Big Data Analytics. Creative and organized with an analytical bent of mind.

Our Upcoming Events

24th Mar, 2023 | Webinar
Women-in-Tech: Are you ready for the Techade

27-28th Apr, 2023 I Bangalore
Data Engineering Summit (DES) 2023

23 Jun, 2023 | Bangalore
MachineCon India 2023 [AI100 Awards]

21 Jul, 2023 | New York
MachineCon USA 2023 [AI100 Awards]

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox

Council Post: Evolution of Data Science: Skillset, Toolset, and Mindset

In my opinion, there will be considerable disorder and disarray in the near future concerning the emerging fields of data and analytics. The proliferation of platforms such as ChatGPT or Bard has generated a lot of buzz. While some users are enthusiastic about the potential benefits of generative AI and its extensive use in business and daily life, others have raised concerns regarding the accuracy, ethics, and related issues.