# Improving Transformer World Models for Data-Efficient RL

Warmup and tokenizer changes let transformer world models learn Craftax faster

Antoine Dedieu, Joseph Ortiz, Xinghua Lou, Carter Wendelken, Wolfgang Lehrach, J Swaroop Guntupalli and 2 more · arXiv · 2025-2-3

- **Problem** Model-based RL with transformer world models has lagged behind model-free agents, because early in training the world model is too inaccurate to supply useful imagined data. Mixing imagined data in from the start hurts policy learning.
- **Method** Warmup delays imagined data, and a fixed-code tokenizer gives a stable target.
- **Results** The best agent reaches a reward of 69.66% on Craftax-classic after 1M environment steps. DreamerV3 reaches 53.2% on the same benchmark.

![Figure 5: \| \[Left\] MBRL performance decreases when NNT uses patches of smaller or larger size than the ground truth, but it remains competitive. However, perfo…](https://refivu.com/papers/bf0a569b-7476-4cd0-91b8-a28e0935c805/figures/figure-f207caef00f1d4ed2513ae7671b51438.png?thumb=512)

**Figure 5** \| \[Left\] MBRL performance decreases when NNT uses patches of smaller or larger size than the ground truth, but it remains competitive. However, performance collapses if the patches are not quantized. \[Middle\] Removing any rung of the ladder of improvements leads to a drop in performance. \[Right\] Warming up the world model before using it to train the policy on imaginary rollouts is required for good performance. BP denotes background planning. For each method, training in imagination starts at the color-coded vertical line, and leads to an initial drop in performance.

[Original paper](https://arxiv.org/abs/2502.01591v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Antoine Dedieu, Joseph Ortiz, Xinghua Lou, Carter Wendelken, Wolfgang Lehrach, J Swaroop Guntupalli, Miguel Lazaro-Gredilla, Kevin Patrick Murphy · Improving Transformer World Models for Data-Efficient RL · Original paper figure · Extracted the figure area from page 10 of the original PDF.

## Why sample efficiency is hard on Craftax-classic

Model-free reinforcement learning maps observations straight to actions, and that usually needs a lot of environment data. Model-based RL learns a world model and plans in imagination, which is meant to cut that data need. Each observation is a 63×63 pixel local view split into a grid of 9×9 patches of 7×7 pixels. The agent only sees this local view, plus a visualization of its inventory, so it never observes the full world.

![Figure 1: \| \[Left\] Reward on Craftax-classic. Our best MBRL and MFRL agents outperform all the previously published MFRL and MBRL results, and for the first ti…](https://refivu.com/papers/bf0a569b-7476-4cd0-91b8-a28e0935c805/figures/figure-12a4ed2d4417af267eecbb369e399a7b.png?thumb=512)

**Figure 1** \| \[Left\] Reward on Craftax-classic. Our best MBRL and MFRL agents outperform all the previously published MFRL and MBRL results, and for the first time, surpass the reward achieved by a human expert. We display published methods which report the reward at 1M steps with horizontal line from 900k to 1M steps. \[Middle\] The Craftax-classic observation is a63× 63 pixel image, composed of9× 9 patches of 7× 7 pixels. The observation shows the map around the agent and the agent’s health and inventory. Here we have rendered the image at144× 144 pixels for visibility. \[Right\] 64 different patches.

[Original paper](https://arxiv.org/abs/2502.01591v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)

The environment is procedurally generated, so each episode gives the agent a new map sampled from a common distribution. Its achievement hierarchy gives a sparse reward signal, which forces the agent to explore deeply and broadly before it learns much. Earlier model-based agents such as IRIS and DreamerV3 train their policy only on imagined trajectories.

DreamerV3 held the previous best reward of 53.20% on this benchmark, and the previous best score was 19.4%. So the question is whether a transformer world model can supply enough useful data to beat that level within 1M environment steps.

Those numbers show that a transformer world model alone does not close the gap to the stronger model-free baseline.

## Real data plus delayed imagination

The method keeps the policy learning from real environment experience while it also learns from imagined rollouts. The authors call this scheme Dyna with warmup, because imagined data enters training only after a delay. Each iteration first collects real trajectories and updates the policy on them with PPO. The world model is then updated on replayed trajectories sampled from the data buffer.

Only after the warmup does the policy get updated on rollouts generated inside the world model. Because PPO is on-policy, the real-data update has to happen right after collection, which is why it sits in Step 2. The authors note that an off-policy algorithm could mix real and imaginary data instead, but they leave that as future work.

The warmup exists because an inaccurate world model can harm policy learning when imagined data is mixed in early. The authors set the warmup at T\_BP = 200k environment steps in the main runs. Removing the warmup and starting imagined training at once, with T\_BP = 0, drops the reward from 67.42% to 33.54%. Removing Dyna altogether and training only in imagination drops the reward to 55.02%.

Both parts of the scheme therefore carry weight in the final result.

Dyna is the classic scheme where a learned model generates extra training data for the policy. The authors view the world model here as a form of generative data augmentation. Their version differs from Dyna by adding a delay before the imagined part starts. They also keep the rollout horizon short, with T\_WM much smaller than T\_env, to limit compounding model errors.

When imagined training begins at step 200k, the reward dips temporarily in the authors' runs. The dip happens because the TWM rollouts don't yet match the true environment dynamics, shifting the policy's inputs. The authors later report that annealing the number of imagined policy updates removes this drop.

## How one training iteration runs

Each iteration starts by collecting trajectories from the environment and storing them in a data buffer D. The policy is then updated with PPO on those real trajectories, in Step 2, right after the data is collected. PPO is on-policy, so it needs trajectories that are close to the current policy. Next, the world model is trained for N\_iters^WM updates, each on trajectories sampled from the buffer D.

The authors update the TWM 500 times per iteration, so the world model sees the real data before any imagination starts.

Imagined data enters only in Step 4, and only once the step count t reaches T\_BP. Each imagined update samples starting observations from the buffer D, and the policy rolls out inside the world model. These rollouts have length T\_WM, which is 20 for the Craftax-classic experiments. The authors set T\_WM much smaller than T\_env to limit compounding errors from model imperfections.

They found a T\_WM of 1 no better than MFRL with experience replay, so they use a longer horizon.

The policy is updated on imagined trajectories N\_iters^AC times, with 150 updates in the main runs. The authors left out an off-policy alternative that would mix real and imaginary data in Step 4 and remove Step 2. The loop repeats until the total number of environment steps T\_total is reached, which is 1M in Craftax-classic.

## Patch tokenizer: encoding each patch on its own

Most prior MBRL methods pass the whole image through a CNN and quantize the feature map jointly with a VQ-VAE. The authors instead split each observation into patches and encode every patch independently into its own token. On Craftax-classic each observation has 81 patches, so the tokenizer produces L = 81 tokens per observation. Decoding works in reverse: each token is decoded into a patch on its own, and the patches are rearranged into a full image.

Factorizing the VQ-VAE over these 81 patches lifts the reward from 43.36% to 58.92%.

The nearest-neighbor tokenizer, which the authors call NNT, encodes each patch by finding its closest codebook entry in squared Euclidean distance. If the closest entry is farther than the threshold tau, the patch itself becomes a new code in the codebook. Decoding simply returns the codebook entry at the given index, so no decoder network is needed.

Existing codebook entries are never updated after they are added, so the target the world model learns stays fixed. A VQ-VAE codebook keeps changing during training, so the world model must learn from a non-stationary distribution.

With patch factorization, replacing the VQ-VAE with NNT lifts the reward from 58.92% to 64.96%. For M4 and M5, which use NNT, the authors found a codebook size of 4096 and a threshold of 0.75 critical. Patch size matters for this tokenizer, and the paper's ablation shows performance drops with 5x5 or 9x9 patches.

## Block teacher forcing for next-step tokens

Standard teacher forcing predicts each token from the ground-truth earlier tokens over time and within a timestep, so tokens of one step come out in sequence. Block teacher forcing drops the conditioning on tokens of the current step and predicts all next-step tokens from the previous timesteps alone. A block causal attention pattern lets tokens of the same timestep attend to each other, so the model reasons jointly before it samples them in parallel.

The authors say this property mitigates autoregressive drift, because the tokens of a timestep are sampled with independent readouts.

BTF predicts the next timestep's tokens independently, so the training objective factorizes over the tokens of each timestep. Standard teacher forcing and BTF both maximize a log likelihood, but BTF conditions only on the history and the actions.

The authors report that BTF returns more accurate world models than fully autoregressive training. BTF also ran about twice as fast, even though with key-value caching both schemes have the same theoretical complexity. Both schemes have complexity O(L²T) for one timestep and O(L²T²) for the entire rollout.

## Does the ladder hold up on Craftax-classic

Adding Dyna to the baseline lifts the reward to 43.36%, since the policy trains on both real and imagined trajectories. The patch factorization splits each observation into non-overlapping patches and encodes each patch into its own token, so the tokenizer works per patch.

Replacing the VQ-VAE with the nearest-neighbor tokenizer raises the reward from 58.92% to 64.96%, with patch factorization already in place. The nearest-neighbor tokenizer adds a new code whenever the nearest codebook entry is farther than a threshold, and stored codes are never updated. A static codebook gives the TWM a stationary target, whereas the VQ-VAE codebook keeps changing and makes learning harder.

The authors found that a codebook size of 4096 and a threshold of 0.75 were critical for the nearest-neighbor tokenizer. BTF runs about twice as fast as the autoregressive approach, which cuts the training time of that agent.

That slow run took about 2 days of training, so the authors left it out of their ablations and comparisons.

## Ablations on warmup, tokenizer and BTF

Removing the warmup is the clearest test of when imagined training should start, and it hurts a lot. Setting the background planning starting step to zero drops the reward from 67.42% to 33.54%. The authors trained the policy on imagined rollouts from the start, so the world model was not yet accurate enough. Removing the Dyna method and training only in imagination drops the reward to 55.02%.

The main runs start imagined training at 200k environment steps, and the reward dips briefly when it begins. The rollouts don't initially match the true environment dynamics, so the policy sees a distribution shift. Figure 5 shows that starting background planning too early, at 0k, causes the same kind of collapse.

The tokenizer changes are the other rungs that the authors ablated against the best MBRL agent.

The authors also checked the MFRL changes, since they are part of the ladder. These results suggest that every component of the MBRL agent contributes to its state-of-the-art reward.

## Do the rollouts stay faithful to the true symbols

The authors measure rollout faithfulness by training a CNN to read ground truth symbols from observations. Given a TWM checkpoint at 1M steps, each world model replays the actions of a trajectory from its starting observation. Symbol accuracy is then averaged over rollout timesteps, with each symbol compared against its ground truth value.

Symbol accuracy falls with rollout step for all three world models, because mistakes compound over the rollouts. The NNT-based M5 reaches the highest symbol accuracy at every rollout timestep, as the figure shows for horizons 5 to 20. The authors attribute this to the stationary NNT codebook, which makes the TWM target distribution simpler to learn.

M5 also has the lowest tokenizer and rollout reconstruction errors among the compared models in Appendix D.

Qualitatively, the rollouts show map inconsistencies, feasible hallucinations and infeasible hallucinations. M1 makes simple map errors in successive timesteps, and it incorrectly adds wood to the inventory. M3 and M5 both generate feasible hallucinations, such as spawning mobs and losing health. M3 still shows infeasible hallucinations, such as a monster that suddenly disappears, while M5 rarely shows them.

## Results beyond Craftax-classic

The score values for the previous SOTA agents are unknown, so only reward is compared.

On MinAtar, the authors test the same ideas on four simplified Atari 2600 games with symbolic binary observations. They tune the MFRL agent first, then build the MBRL agent by integrating the three proposed improvements, keeping most Craftax-classic hyperparameters. The authors compare these runs against the Artificial Dopamine agent (AD) of Guan et al., 2024, using results shared by the authors.

For the two-player games, the authors use three OpenSpiel games: Tic-Tac-Toe, Bargaining and Leduc Poker. Tic-Tac-Toe is fully observed with deterministic dynamics, whereas Bargaining and Leduc Poker are partially observed and stochastic. To keep the world model simple, the authors turn stochastic dynamics into deterministic ones with a chance player.

The TWM predicts rewards, terminations, next observations, next player IDs, legal actions and chance probabilities for both players. Policy training in imagination keeps only the agent's predicted observations and discards the opponent's.

![Figure 10: \| By leveraging a multiplayer TWM, our MBRL agents achieve higher rewards than our MFRL agents across three two-player games, illustrating the gener…](https://refivu.com/papers/bf0a569b-7476-4cd0-91b8-a28e0935c805/figures/figure-cf9aecb828937a640418b08d8cbb9fa8.png?thumb=512)

**Figure 10** \| By leveraging a multiplayer TWM, our MBRL agents achieve higher rewards than our MFRL agents across three two-player games, illustrating the generality of our approach.

[Original paper](https://arxiv.org/abs/2502.01591v3) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)

The authors use 100k actions in total for both players, and they start imagination training at 0 steps. The MBRL agents achieve higher rewards than the MFRL agents on all three games, averaged over 10 seeds. The gap is largest early in training, which the authors read as evidence that a TWM can be learned from tens of thousands of interactions.

## Limitations of the transformer world model approach

The authors name two main disadvantages of their patch tokenizer, and both depend on the input structure. NNT may build a large codebook when appearance varies a lot within patches. The authors expect this to stay mild in Craftax-classic because of its grid structure and limited sprite vocabulary. Continuous variations from lighting and texture randomness still exist, so the codebook can still grow.

The codebook size is also a practical constraint for the NNT variants. For M4 and M5, the authors found it critical to use a codebook size of 4096 with a threshold of 0.75. The slow variant trains its world model for 4k steps, which takes about 2 days. Because of that training time, the authors left the slow agent out of the ablation and comparison studies.

Training in imagination also causes a temporary drop in performance at step 200k.

All tested environments are grid worlds, and the authors plan to examine generalization beyond them. They didn't test non-grid environments in this work. Prioritized experience replay is named as a promising way to speed up TWM training, but it isn't tested here. An off-policy RL algorithm that mixes imagined and real data is also named as future work.

Pre-trained tokenizers such as SAM and Dino-V2 are proposed as a longer-term direction, not as a tested method.

## Paper info

- **Authors**: Antoine Dedieu, Joseph Ortiz, Xinghua Lou, Carter Wendelken, Wolfgang Lehrach, J Swaroop Guntupalli, Miguel Lazaro-Gredilla, Kevin Patrick Murphy
- **Venue**: arXiv · Preprint
- **First published**: 2025-2-3
- **Added**: 2026-10-31
- **Updated**: 2025-7-16
- **Version**: v3
- **arXiv**: 2502.01591
- **Category**: cs.LG · cs.AI
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

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

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.

## Abstract

We present three improvements to the standard model-based RL paradigm based on transformers: (a) "Dyna with warmup", which trains the policy on real and imaginary data, but only starts using imaginary data after the world model has been sufficiently trained; (b) "nearest neighbor tokenizer" for image patches, which improves upon previous tokenization schemes, which are needed when using a transformer world model (TWM), by ensuring the code words are static after creation, thus providing a constant target for TWM learning; and (c) "block teacher forcing", which allows the TWM to reason jointly about the future tokens of the next timestep, instead of generating them sequentially. We then show that our method significantly improves upon prior methods in various environments. We mostly focus on the challenging Craftax-classic benchmark, where our method achieves a reward of 69.66% after only 1M environment steps, significantly outperforming DreamerV3, which achieves 53.2%, and exceeding human performance of 65.0% for the first time. We also show preliminary results on Craftax-full, MinAtar, and three different two-player games, to illustrate the generality of the approach.

## Quote from the paper

Antoine Dedieu, Joseph Ortiz, Xinghua Lou, Carter Wendelken, Wolfgang Lehrach, J Swaroop Guntupalli, Miguel Lazaro-Gredilla, Kevin Patrick Murphy (2025). Improving Transformer World Models for Data-Efficient RL. arXiv:2502.01591v3. https://arxiv.org/abs/2502.01591v3

**BibTeX**

```
@misc{dedieu2025improving,
  title = {{Improving Transformer World Models for Data-Efficient RL}},
  author = {Antoine Dedieu and Joseph Ortiz and Xinghua Lou and Carter Wendelken and Wolfgang Lehrach and J Swaroop Guntupalli and Miguel Lazaro-Gredilla and Kevin Patrick Murphy},
  year = {2025},
  eprint = {2502.01591},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.01591v3}
}
```

## Other paper commentary

- [FRUGAL: Memory-Efficient Optimization by Reducing State Overhead for Scalable Training](https://refivu.com/en/papers/c62e87ad-a4e4-49a7-b6e8-0df71fb48f97-frugal-memory-efficient-optimization-by-reducing-state.md)
- [Weight-sparse transformers have interpretable circuits](https://refivu.com/en/papers/57b058ed-824e-41f1-9bf7-37d4673924a5-weight-sparse-transformers-have-interpretable-circuits.md)
- [EvoPress: Accurate Dynamic Model Compression via Evolutionary Search](https://refivu.com/en/papers/9b751a25-3027-4f44-b8fd-a5a56de096fa-evopress-accurate-dynamic-model-compression-via-evolutionary.md)
- [SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization](https://refivu.com/en/papers/5328df78-371a-4c98-b607-4082e43abef7-sageattention2-efficient-attention-with-thorough-outlier.md)
- [SpargeAttention: Accurate and Training-free Sparse Attention Accelerating Any Model Inference](https://refivu.com/en/papers/6a719301-c428-424d-9dc3-3159ff623aea-spargeattention-accurate-and-training-free-sparse-attention.md)
- [STEPQuant: When and Where Errors Matter in Delta-Rule Recurrent State Quantization](https://refivu.com/en/papers/51c79527-1b87-4343-8cdc-defd890a1f93-stepquant-when-and-where-errors-matter-in-delta.md)
- [Geometry-Informed Neural Networks](https://refivu.com/en/papers/da0a16b6-9d7a-4d46-a972-fe3929ea063a-geometry-informed-neural-networks.md)
- [The Surprising Agreement Between Convex Optimization Theory and Learning-Rate Scheduling for Large Model Training](https://refivu.com/en/papers/3a431e7f-c68b-477b-a0ef-073c8d045e7b-the-surprising-agreement-between-convex-optimization-theory.md)
- [History-Guided Video Diffusion](https://refivu.com/en/papers/6108fb68-ef01-4b85-84db-35036f8a36f4-history-guided-video-diffusion.md)
- [Preference learning made easy: Everything should be understood through win rate](https://refivu.com/en/papers/264a94d1-35b3-4713-ad28-4fb53ff57907-preference-learning-made-easy-everything-should-be.md)
- [NestQuant: Nested Lattice Quantization for Matrix Products and LLMs](https://refivu.com/en/papers/fcf33004-4ca4-4b0c-bd9b-474a77e2a35d-nestquant-nested-lattice-quantization-for-matrix-products.md)
- [EQ-VAE: Equivariance Regularized Latent Space for Improved Generative Image Modeling](https://refivu.com/en/papers/fab7b7ee-5523-498a-a636-595696465569-eq-vae-equivariance-regularized-latent-space-for-improved.md)

## Terms in this paper

- [PPO](https://refivu.com/en/terms/21c34991d674-ppo)
- [Teacher Forcing](https://refivu.com/en/terms/5af8c5103329-teacher-forcing)
- [codebook](https://refivu.com/en/terms/fe494568ef8d-codebook)
- [Score](https://refivu.com/en/terms/5aef9aa52556-score)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/bf0a569b-7476-4cd0-91b8-a28e0935c805-improving-transformer-world-models-for-data-efficient-rl)
