Now Reading
Mastering Atari with Discrete World Models: DreamerV2

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. 

Register for our upcoming Masterclass>>

The Model Architecture of DreamerV2

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.

Looking for a job change? Let us help you.

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

See Also

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:

What Do You Think?

Join Our Discord Server. Be part of an engaging online community. Join Here.

Subscribe to our Newsletter

Get the latest updates and relevant offers by sharing your email.

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top