Search

Search papers and lessons

Transformers are Sample-Efficient World Models (IRIS)

Vincent Micheli, Eloi Alonso, François Fleuret · 2022

IRIS learns Atari policies entirely in imagination, using a discrete autoencoder and a GPT-style Transformer as its world model.

On this page

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

TL;DR

IRIS trains an Atari agent entirely inside a learned world model. A discrete autoencoder turns each frame into 16 tokens, and a GPT-style Transformer predicts the next frame's tokens, reward and episode end from the history of tokens and actions. With the equivalent of about two hours of game time per game, it reached a mean human-normalized score of 1.046 on the 26-game Atari 100k benchmark.

Where you'll see it: sample-efficient reinforcement learning research, and any agent that plans by imagining sequences inside a learned video model.

The problem

Deep reinforcement learning agents need enormous amounts of experience. The paper notes that unconstrained Atari agents are usually trained for 50 million steps, and that DreamerV2 was developed and evaluated with two hundred million frames available. Real robots and real products cannot afford that many interactions, so the paper treats sample efficiency as the bottleneck.

Model-based methods address this by learning a world model and training the policy on imagined trajectories. This works only if the model stays accurate over long horizons. SimPLe showed promise on Atari 100k, but the best imagination agent, DreamerV2, was developed with about two hundred million frames, far from the sample-efficient regime. The authors also point out that Transformers, which model long sequences of discrete tokens well, had not been used as world models for this setting. A pixel-level Transformer is too expensive, because standard attention cost grows with the square of the sequence length, and an image has many thousands of pixels.

So the open question was whether a Transformer world model on compact image tokens could be accurate enough, with little data, to train a competitive policy in imagination.

Key idea

Turn images into a short language of tokens and let a Transformer model that language over time. A discrete autoencoder maps each 64×64×364 \times 64 \times 3 frame to K=16K = 16 tokens chosen from a vocabulary of N=512N = 512 codes. A GPT-like autoregressive Transformer then models the interleaved sequence of frame tokens and actions. Given the history, it predicts the next frame's tokens one by one, plus the reward and whether the episode ends. The policy is trained only on rollouts the world model generates. Real experience is used to train the world model and to keep it current.

flowchart LR
  F["Real frame x_t"] --> E["Encoder E: 16 tokens"]
  E --> G["Transformer G over frame and action tokens"]
  A["Action a_t from policy"] --> G
  G --> N["Predicted next tokens, reward, episode end"]
  N --> D["Decoder D: imagined frame"]
  D --> P["Policy and value learn from imagined frames"]
  P --> A

The design is simple on purpose. The autoencoder is a vector-quantized image coder, the sequence model is a standard Transformer, and the agent learns with an actor-critic objective. The paper argues that these standard pieces, combined carefully, are enough to get strong sample efficiency.

The method

From images to tokens

The encoder runs a convolutional network over the frame, producing a grid of KK vectors of dimension dd. Each vector is replaced by the index of its nearest entry in an embedding table E\mathcal{E} with NN entries:

ztk=argmin⁡i∥ytk−ei∥2.z_t^k = \operatorname*{argmin}_i \lVert y_t^k - e_i \rVert_2.

This is the quantization step from Vector Quantization. The decoder is a convolutional network that turns the KK tokens back into an image.

The autoencoder is trained with an equally weighted sum of four terms. The first is an L1L_1 reconstruction loss. The second and third form the commitment loss, with one term moving the embedding toward the encoder output and the other moving the encoder output toward the embedding, each with a stop-gradient on the other side. The fourth is a perceptual loss. The paper uses a Straight-Through Estimator to pass gradients through the nearest-neighbour choice. The autoencoder starts from the VQGAN code base with the discriminator removed, so it is a plain vector-quantized autoencoder with a perceptual loss. The original VQ-VAE weights its commitment term by a factor β\beta, and IRIS does not use that factor.

The paper's hyperparameters are a 64×6464 \times 64 frame, four layers with two residual blocks each and 64 channels, a vocabulary of 512 entries, 16 tokens per frame and a token embedding dimension of 512.

Modeling dynamics

The Transformer GG takes a sequence of LL time steps. Each step is KK frame tokens followed by one action token, so with L=20L = 20 the input has 20×17=34020 \times 17 = 340 tokens. Frame tokens are embedded with an N×DN \times D table and actions with an A×DA \times D table, where D=256D = 256. The model has M=10M = 10 GPT-2-style blocks with four attention heads each.

At each step, GG models three things. It predicts the next frame's tokens one at a time, with each token conditioned on the earlier ones in the same frame. It predicts the reward and it predicts the episode end. The transition and termination predictors use a cross-entropy loss. The reward predictor uses a mean squared error or a cross-entropy loss, depending on the game's reward scale. The Transformer is trained on segments of past experience, which is standard autoregressive next-token training.

Learning in imagination

The policy never sees the real environment during learning. It starts from a real frame taken from past experience, which the autoencoder reconstructs, and then acts. The world model predicts the reward, the episode end and the next frame, and the process repeats for a fixed horizon H=20H = 20. If an episode end is predicted first, the rollout stops.

Because rollouts are short, the paper bootstraps the return with a learned value function VV, using the λ\lambda-return from the Dreamer line of work. The value network regresses onto this target with a squared error, and the target is treated as a constant. The actor is trained with a REINFORCE-style objective, meaning a Policy Gradient that weights the log-probability of each action by the advantage, the λ\lambda-return minus the value V(x^t)V(\hat{x}_t). An entropy bonus with weight η=0.001\eta = 0.001 keeps the policy exploring. The paper says it chose the objectives and hyperparameters of DreamerV2 for simplicity, and that many other Actor-Critic Methods methods could be used. The discount is γ=0.995\gamma = 0.995 and λ=0.95\lambda = 0.95.

Training loop

The paper runs 600 epochs. In each of the first 500, the current policy collects 200 environment steps, with an epsilon-greedy rate of 0.01. The autoencoder starts training after epoch 5, the Transformer after epoch 25 and the actor-critic after epoch 50. Training uses Adam with learning rate 10−410^{-4}, β1=0.9\beta_1 = 0.9 and β2=0.999\beta_2 = 0.999, and clips gradient norms at 10. Batch sizes are 256 for the autoencoder and 64 for the Transformer and the actor-critic.

Results

The benchmark is Atari 100k. It uses 26 games and allows 100 thousand actions per game, which the paper describes as roughly two hours of human play. Scores are reported as human-normalized, meaning (scoreagent−scorerandom)/(scorehuman−scorerandom)(\text{score}_{\text{agent}} - \text{score}_{\text{random}}) / (\text{score}_{\text{human}} - \text{score}_{\text{random}}). For example, on Breakout the paper reports 83.7 for IRIS, a random score of 1.7 and a human score of 30.5, so the normalized score is (83.7−1.7)/(30.5−1.7)=82.0/28.8≈2.85(83.7 - 1.7) / (30.5 - 1.7) = 82.0 / 28.8 \approx 2.85.

The paper's aggregate table compares IRIS with methods that use no lookahead search and with two search-based methods:

MethodLookahead searchMeanIQMSuperhuman games (of 26)
SimPLeno0.3320.1301
CURLno0.2610.1132
DrQno0.4650.2803
SPRno0.6160.3376
IRISno1.0460.50110
MuZeroyes0.562not reported5
EfficientZeroyes1.943not reported14

Mean, IQM and superhuman counts are the paper's Table 1 values. The median is 0.289 for IRIS and 0.396 for SPR, so IRIS does not lead on the median, and the paper says the median is driven by a few games. Relative to SPR, the paper reports +70% on mean score, +49% on IQM, an optimality gap of 0.512 against 0.577 for SPR (lower is better), and superhuman play on 10 games against 6. The paper's own wording is that IRIS sets a new state of the art for methods without lookahead search on this benchmark. It also reports that IRIS outperforms MuZero, which was not designed for the sample-efficient regime, and it does not claim to beat EfficientZero, whose mean is higher.

The paper's per-game results show the pattern. IRIS scores strongly in games like Pong, Breakout and Boxing, where the world model does not face changing levels. It scores poorly in Frostbite, with 259.1 against a human score of 4334.7. The authors attribute this to a double exploration problem: the agent must first discover a new level, and the world model must learn it, before the policy can exploit it. Krull, which has more frequent level transitions, does better. The paper's qualitative figures show that the world model reproduces Pong pixel-perfectly after 120 games of training and predicts rewards and episode ends in Breakout and Gopher.

Five runs per game are used for IRIS, and the paper reports stratified bootstrap confidence intervals with Agarwal et al.'s recommendations.

Why it mattered

The paper shows that a Transformer over discrete image tokens can serve as a world model with which a policy learns to play Atari games using only about two hours of game time per game. Its claims are limited to the paper's benchmark and to methods without lookahead search. It also gives a concrete recipe: 16 tokens per frame, a 512-entry vocabulary, a 20-step context and an imagination horizon of 20. The code and models are released, as the abstract states. The authors list scaling to harder tasks, learning policies from the world model's internal representations, and combining imagination with Monte Carlo tree search as open directions. The paper does not claim any particular later influence, and this lesson does not either.

Reading guide

Read the paper in this order. For each section, the prerequisites are listed.

  1. Section 1, Introduction. Needs Model-Based Reinforcement Learning for the learning-in-imagination idea, World Model for what a world model is, and Vector Quantization for the discrete autoencoders used by VQGAN and DALL-E.
  2. Section 2, Method, opening. Needs Markov Decision Process and Partially Observable Markov Decision Process for the POMDP notation in the first paragraph.
  3. Section 2.1, From image observations to tokens. Needs Vector Quantization for the nearest-neighbour rule, Convolutional Neural Network for the encoder and decoder, and Straight-Through Estimator for backpropagation through the choice.
  4. Section 2.2, Modeling dynamics. Needs Transformer for the architecture, Autoregressive Model for token-by-token prediction, and Cross-Entropy Loss for the transition and termination losses.
  5. Section 2.3, Learning in imagination. Needs Value Function for the value network, Policy Gradient for the REINFORCE objective, Actor-Critic Methods for how the two networks fit together, Entropy for the entropy bonus and Gradient Descent for training.
  6. Section 3, Experiments. Needs Monte Carlo Tree Search for the lookahead-search methods that appear in the comparison table.
  7. Appendix A, Models and hyperparameters. Needs Adam Optimizer for the optimiser settings.

Check yourself

QuestionRecall: how many tokens represent one frame in IRIS, and how large is the token vocabulary?Show answer
Each frame becomes K=16K = 16 tokens, and each token is an index into an embedding table of N=512N = 512 entries.
QuestionComputation: on Breakout the agent scores 83.7, a random policy scores 1.7 and a human scores 30.5. What is the human-normalized score, to two decimal places?Show answer
(83.7−1.7)/(30.5−1.7)=82.0/28.8≈2.85(83.7 - 1.7) / (30.5 - 1.7) = 82.0 / 28.8 \approx 2.85. The agent is well above human level on this game.
QuestionWhy: why does IRIS model 16 tokens per frame with a Transformer instead of predicting raw pixels?Show answer
A 64×64×364 \times 64 \times 3 frame has 12,288 values, and self-attention cost grows with the square of sequence length. With 16 tokens and one action token per step, a 20-step context is 340 tokens. That keeps the Transformer tractable, and each token is a discrete symbol that can be predicted with a cross-entropy loss.
QuestionApplied: you deploy an IRIS-style agent in a game where a rare event unlocks a new level. What failure does the paper's Frostbite result predict, and what would you change?Show answer
The paper predicts a double exploration problem. The world model will not learn the new level from few samples, so the policy never practises it in imagination. Remedies include collecting real experience that reaches the rare state, such as through a stronger exploration bonus, or seeding the replay data with demonstrations of the rare event. Checking the world model's predictions on that level, rather than only the return, shows whether the model has learned it.

Sources

Read the full paper

Vincent Micheli, Eloi Alonso, François Fleuret, 2022. arXiv:2209.00588