Search

Search papers and lessons

Model-Based Reinforcement Learning for Atari

Lukasz Kaiser, Mohammad Babaeizadeh, Piotr Milos et al. · 2019

SimPLe learns Atari games from 100,000 real steps by training a video model and improving its policy inside it, matching or beating a tuned Rainbow on most games.

On this page

  • Colour = topic mix
  • Probability
  • Reinforcement learning
  • Discrete math
  • Calculus
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Kaiser and colleagues (2019) train an agent to play Atari games from raw pixels using only about 100,000 steps of real play, roughly two hours of human-speed gameplay. The method, Simulated Policy Learning (SimPLe), alternates between two loops: it learns a video prediction model of the game from the agent's real experience, then improves the policy by trial and error inside that model. Their model-free comparison, a tuned Rainbow agent, needed more steps on about half of the 26 games tested, and in the best case, Freeway, SimPLe was more than ten times as sample-efficient.

Builds on: Model-Based Reinforcement Learning, World Model, Proximal Policy Optimization (PPO), Long Short-Term Memory · Leads to: Dream to Control: Learning Behaviors by Latent Imagination (Dreamer), Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model (MuZero)

Why it mattered

Before this paper, model-based agents were strong on simple, low-dimensional control tasks, while model-free agents were the methods that played image-based games well, and they needed millions of steps to do it. The authors note that Dyna-style planning with a learned model had not yet produced comparable results in the Atari domain. SimPLe showed competitive results on that benchmark with a small interaction budget, which turned model-based learning from a promise into a measured result on a standard suite.

The paper also showed a practical recipe. A world model is trained on the data the agent collects, the policy is trained inside the model with a standard algorithm, and the new policy goes back out to collect fresh data. The loop, with a discrete latent variable in the video model, is the core of the method, and its code is public in the Tensor2Tensor library.

The result is also a warning. The learned agents were on the whole weaker than the best model-free agents when given millions of steps, and their performance varied a great deal between runs. The paper states both points, which is why it is a useful reading for anyone weighing sample efficiency against final performance.

The problem

A reinforcement learning agent learns by trying actions and seeing rewards. In the Atari Learning Environment (ALE), an agent sees the screen as pixels and chooses one of a small set of joystick actions. A model-free method learns a policy directly from those trials. The best of them, such as the Rainbow baseline in this paper (a combination of several improvements to deep Q-learning), need tens or hundreds of millions of steps, which the paper puts at several weeks of real-time training.

A human learns a game in minutes, and the paper's guess is that part of the reason is an internal model of how the game works, which lets a player predict what an action will do. The question is whether a learned video model can play that role for an agent, so that most of its learning happens in imagination and only a small amount happens in the real game.

There are three obstacles. The first is that a video model drifts: its own predictions are fed back in, and small errors compound over many steps. The second is that Atari is deterministic in principle but not from the agent's view, since a few past frames do not reveal what the game will spawn next. The third is that a policy trained inside an imperfect model may exploit the model's flaws and then fail in the real game.

How it works

The loop in the paper's Figure 1 has three stages, and the whole method is a repetition of them.

flowchart LR
  A[act in the real game with the current policy] --> B[add the frames and rewards to the buffer]
  B --> C[train the world model on the buffer]
  C --> D[train the policy with PPO inside the world model]
  D --> A

Trace one pass through a tiny instance. The paper's real numbers are used throughout.

  1. Collect real experience. The first policy is random. It plays the real game for 6,400 steps and stores every frame and reward in a buffer. Each observation is four consecutive frames, stacked, because one frame does not show a ball's direction. The paper repeats each action four times (frame skip 4).

    Check: 6,400 steps times 16 passes, counting the initial random data, is 102,400 real steps. That is the budget the paper calls 100K.

  2. Train the world model. A neural network takes the four stacked frames and the chosen action, and predicts the next frame and the reward. It is trained on the buffer for 45,000 steps in the first pass and 15,000 steps in each later pass. The network is a convolutional encoder and decoder, with the input frames and action embedded by fully connected layers, and its output is a softmax over 256 colours per pixel.

    Check: in the stochastic variant, a discrete latent code is also sampled at each step and fed to the model, so it can represent several possible futures instead of one blurred average.

  3. Train the policy inside the model. The world model replaces the real game. Rollouts start from states drawn at random from the real buffer and run for 50 simulated steps each. PPO uses these rollouts to improve the policy. Each pass uses about 800,000 simulated steps times a pass factor, which is 1 in most passes, 2 in passes 8 and 12, and 3 in the last. Summed over the 15 passes, the paper reports 15.2 million simulated interactions.

    Check: 15.2 million simulated steps against 102,400 real ones is about 150 simulated steps per real step. That ratio is why the approach is cheap in real play, and why errors in the model matter so much.

  4. Return to the real game. The new policy plays the real game for the next 6,400 steps. Its data goes into the buffer, and the world model is then trained again on the larger buffer.

    Check: after pass 1, the model has seen data from the random policy and from the first trained policy. Its errors are concentrated where that policy goes, which is why the loop has to keep collecting real data.

Three design choices keep the loop from failing. Short rollouts of 50 steps stop errors from compounding. Restarting rollouts from real states, rather than from the start of the game, keeps the policy in the states it will actually meet. Scheduled sampling, which feeds the model's own predictions back during training, teaches it to handle its own mistakes.

The math

An Atari game is a Markov decision process with states ss, actions aa, a transition distribution P(s′∣s,a)P(s' \mid s, a), a reward rr and a discount factor γ\gamma between 0 and 1. The paper works with pixel observations rather than the emulator's internal state, and stacks four frames to recover some of the missing state.

The quality of a policy π\pi is its value,

Vπ(s)=Eπ ⁣[∑t=0∞γtrt+1 | s0=s].V^{\pi}(s) = \mathbb{E}_{\pi}\!\left[\sum_{t=0}^{\infty} \gamma^{t} r_{t+1} \,\middle|\, s_0 = s\right].

The paper uses γ=0.95\gamma = 0.95 for PPO training and compares it with γ=0.99\gamma = 0.99; it reports that 0.950.95 gives the better results.

Step 2 in symbols: the world model

The world model is a learned approximation P^θ\hat{P}_\theta to the real game. Given the stacked frames xt−3:tx_{t-3:t} and the action ata_t, it predicts the next frame and the reward:

x^t+1,r^t+1∼P^θ(⋅∣xt−3:t,at).\hat{x}_{t+1}, \hat{r}_{t+1} \sim \hat{P}_\theta(\cdot \mid x_{t-3:t}, a_t).

The frame loss is clipped at a constant CC, so that max⁡(loss,C)\max(\text{loss}, C) stops the model from spending its effort on areas it already predicts well. With the softmax output, the clip is C=0.03C = 0.03. The paper notes that −ln⁡(0.97)≈0.03-\ln(0.97) \approx 0.03, so the clip removes the gradient from any pixel whose correct value already has 97 percent probability.

Step 3 in symbols: the policy objective

The policy is trained with PPO inside the model. Its rollouts have length N=50N = 50, and at the end of each rollout the paper adds the value estimate to the last reward. Writing the value function of the learned model as V^\hat{V}, the rollout's return is

Gt=∑k=0N−1γkr^t+k+1+γNV^(s^t+N).G_t = \sum_{k=0}^{N-1} \gamma^{k} \hat{r}_{t+k+1} + \gamma^{N} \hat{V}(\hat{s}_{t+N}).

The term with V^\hat{V} is what lets a short rollout say something about the long future.

Step 4 in symbols: the budget

Write nrealn_{\text{real}} for real steps and nsimn_{\text{sim}} for simulated steps. The paper's numbers give

nreal=6400×16=102,400,nsim=800,000×19=15.2×106,n_{\text{real}} = 6400 \times 16 = 102{,}400, \qquad n_{\text{sim}} = 800{,}000 \times 19 = 15.2 \times 10^{6},

where the factor 19 is the sum of the pass factors over the 15 passes: twelve passes of 1, two passes (8 and 12) of 2, and the last of 3, so 12+2⋅2+3=1912 + 2 \cdot 2 + 3 = 19. The ratio nsim/nrealn_{\text{sim}} / n_{\text{real}} is about 148.

Results

Sample efficiency (Figure 3). On 26 games, each averaged over 5 runs, SimPLe reached the score of the tuned Rainbow baseline in fewer steps on almost all games. In the paper's words, on more than half of the games Rainbow needed at least twice as many samples. On Freeway, the gap was more than tenfold. Stronger baseline. The paper also reports results with a stronger comparison, where the two model-free methods are better on 13 games and SimPLe is better on the other 13 out of 26. Read this way, the claim is parity on half the games, not a clean win.

Against both baselines. The paper reports that SimPLe outperforms Rainbow and PPO even when those are given twice as many interactions.

Longer budgets. SimPLe's results keep improving up to about 500K samples, where the paper reports it is on par with model-free PPO.

Sticky actions. The authors also ran the full pipeline with sticky actions, as Machado et al. (2018) recommend, and compared it with Rainbow in the same format as the main results.

Limits. The paper is explicit that the final scores are generally lower than those of the best model-free methods. Runs on the same game varied a lot, and training inside the model costs substantial compute, so the approach trades real samples for simulated ones.

Tradeoffs and when to use it

It is tempting to think a learned model always makes an agent more efficient. In fact, its benefit depends on how cheap real data is compared with compute. When real steps are costly, as with robots or hardware, a fast world model pays off. When the simulator is free, model-free methods with more data often end higher.

A common mistake is to read "sample efficient" as "better". The paper's own asymptotic comparison shows the opposite pattern at larger budgets, so the claim applies only to the low-data regime it studies.

Use this approach when interaction is expensive, the observations are images, and a learned predictor can reach useful accuracy. Do not use it when the environment is hard to predict from a few frames, or when you need the best final score. Alternatives include model-free methods with more samples.

Reading guide

Check yourself

QuestionRecall: what are the two loops in SimPLe, and which one uses real steps?Show answer

The outer loop collects data in the real game with the current policy, then retrains the world model. The inner loop trains the policy with PPO using rollouts in the learned model. Only the outer loop uses real steps. The inner loop uses simulated steps, which are far more numerous in the paper's budget.

QuestionComputation: the paper uses 6,400 real steps per pass over 16 passes. How many real steps is that, and how many frames is it at frame skip 4?Show answer

6,400×16=102,4006{,}400 \times 16 = 102{,}400 real steps. Each step repeats an action four times, so the frame count is 102,400×4=409,600102{,}400 \times 4 = 409{,}600 frames.

QuestionWhy does SimPLe use rollouts of 50 steps and restart them from real states, instead of rolling out the model from the start of the game?Show answer

Model errors compound over many steps, so a long rollout moves the policy into states the model predicts badly. Short rollouts limit that drift. Restarting from real buffered states keeps the policy in regions of the game it has actually seen, which the paper found crucial, since without random starts the results on Seaquest were much worse.

QuestionA team has a real robot with an expensive hour of operation and cheap compute, and the observations are camera images. Is this paper's approach a reasonable starting point, and what would they check first?Show answer

Yes, it is a reasonable starting point: real time is the scarce resource, compute is cheap, and the inputs are images. Before committing, they should check whether a video model can predict the robot's next frames well enough over the horizon they plan to use, for example by measuring prediction error on held-out real episodes, since compounding error is the main risk.

Sources

Read the full paper

Lukasz Kaiser, Mohammad Babaeizadeh, Piotr Milos et al., 2019. arXiv:1903.00374