PokéDreamer

Dreams the game. Learns to walk in the dream. Plays for real.

v3 Showcase

A complete walkthrough: the 3D map reconstruction, the diffusion world model's imagination, the System 1 / System 2 game harness with its LLM planner, and the Boulder Badge won in the real game.

Full showcase: the diffusion world model, the game agent harness, the System 2 LLM planner with tool calls and RAM-validated decisions, and the System 1 dream-trained agent winning the badge in the real game.

In 30 seconds

  • • A world model of a real game. A diffusion model learned to predict Pokémon Red frame by frame from recorded play: you press a button, it imagines the next screen.
  • • An agent that learned inside the dream. Ten navigation skills were trained purely in that imagination, with zero real-game steps, then dropped into the real game, where the agent wins the Boulder Badge in 30/30 runs.
  • • Measured, not eyeballed. The game's own memory says exactly where the agent and the imagined world really are, so every claim below is a number: where the dream drifts, which shortcuts the agent learned to exploit, and why battles can't be learned this way.
  • • Seen in colour. A neural upscaler and colorizer turn the 72x80 greyscale frames into full-resolution colour for display (99.27% per-pixel accuracy on held-out frames).
Winning the Boulder Badge in the real game: every walk is executed by a System 1 policy trained only in the world model; 30/30 runs.
Left, the real game. Right, the world model imagining the same moments from 4 real frames and the same buttons (re-anchored every 10 steps).

What is PokéDreamer?

PokéDreamer is a research project on world models for game agents - teaching an agent to imagine Pokémon Red, train skills inside that imagination, and measure where the dream matches the emulator's memory.

What PokeDreamer v3 contributes: research value and engineering value, each with a measured number What PokeDreamer v3 contributes: research value and engineering value, each with a measured number
What v3 contributes: research value (the DIAMOND recipe (Alonso et al., 2024) reproduced, Dreamer-style imagination RL (Hafner et al.), RAM-grounded evaluation that caught map hallucinations and a reward hack) and engineering value (System 1/2 harness, emulator + probe measurement stack, display models). Every number is from lab/results/.

The Research Journey

From symbolic state probes to pixel-level imagination - three generations of world models.

v1
Completed ✓

VAE + GRU MPC Planner

The first world model - a Variational Autoencoder compressing frames to 32-dim latents, with a GRU dynamics model predicting the next latent. An MPC planner imagines action sequences and picks the best path using linear probes for map position.

40×36Resolution
R³²Latent Space
97.8%Map Accuracy
1.29 tilesCoord Error
Full v1 Documentation →
v2
Completed ✓

Discrete RSSM World Model

The major leap - native 160×144 resolution, a 4-layer Residual CNN encoder, and a full Recurrent State-Space Model with 32×32 discrete categorical latents trained via Gumbel-Softmax. The RSSM's prior enables pure imagination rollouts without any emulator steps.

160×144Resolution
1024-dimDiscrete Latent
0.1003Best Val Recon
4 epochsTrained
Full v2 Documentation →
v3
Completed ✓

Diffusion World Model + Dream-Trained Agent

A DIAMOND-style diffusion world model of Pokémon Red, and an agent whose navigation was learned entirely inside it. Ten navigation skills trained in imagination carry the agent to the Boulder Badge in the real game in 30 of 30 runs; battles and goal choice are rules, and six local LLMs were tested as the planner (System 2 can call tools: Pokédex and guide search over Bulbapedia via lab/agent/web_search.py). Whether battles can also be trained inside the world model was measured: not with this model. Next: Path B, battles learned inside the world model (estimated ~50 GPU-hours, planned).

30/30Boulder Badges
16.7MModel Params
50 GPU-hTotal Training
72×80Resolution
Full v3 Documentation →

Imagination across versions

Imagined frames across versions, each next to the real emulator: v1 blurs, v2 ghosts, v3 stays sharp (its content can still drift; see v3).
Imagined frames across versions, each next to the real emulator: v1 blurs, v2 ghosts, v3 stays sharp (its content can still drift; see v3).
PokéDreamer v3 EDM diffusion world model architecture PokéDreamer v3 EDM diffusion world model architecture
Architecture of the EDM diffusion world model: 4-frame context denoiser predicting next-frame pixels conditioned on past actions.
v3 diffusion world model: EDM-preconditioned denoiser (lab/dwm/model.py)
    def raw(self, x_noisy, sigma, ctx, actions, aug_bucket):
        """Network output F and EDM scalings; x_noisy (B,1,H,W), sigma (B,), ctx (B,CTX,H,W), actions (B,CTX)."""
        s = sigma[:, None, None, None]
        c_in = 1 / (s ** 2 + SIGMA_DATA ** 2).sqrt()
        c_skip = SIGMA_DATA ** 2 / (s ** 2 + SIGMA_DATA ** 2)
        c_out = s * SIGMA_DATA / (s ** 2 + SIGMA_DATA ** 2).sqrt()
        cond = self.noise_emb(sigma.log() / 4) + self.act_emb(actions).flatten(1) + self.aug_emb(aug_bucket)
        out = self.unet(torch.cat([x_noisy * c_in, ctx], 1), self.cond_mlp(cond))
        return out, c_skip, c_out

Key Experimental Findings

Quantitative results from training and evaluation across all three versions.

🏆 v3 (final): Headline Results (measured)

Empirical findings grounded in Game Boy RAM state across the diffusion world model, imagination-trained navigation policies, start-tile sweeps, battle fidelity, and local LLM planners.

PokéDreamer v3 specs and compute by the numbers PokéDreamer v3 specs and compute by the numbers
By the numbers: 50.0 GPU-hours across 76 runs, quest press efficiency across agent configurations, and display models.
Scope / Task Result Page
Boulder Badge, real game, 10-leg agent 30/30 runs (3 seeds × 10) v3_gym
Runs where every navigation leg is a world-model policy (no fallback anywhere) 14/30 v3_gym
Navigation legs at 100/100 on all 3 seeds 7 of 10; to_pewter_pc 100/0/100, forest 100/69/97 v3_gym
Start-tile robustness after fixing a reward hack (move gate) 2,339/2,340 episodes over 26 start tiles v3_tile_sweep
Can battles be trained inside this world model? No: imagined battles end early in 74.6% of held-out windows (real-frame probe: 1.1%) v3_battle_fidelity
Local LLMs as System 2 5 of 6 reach 10/10 badges v3_system2

The game harness cleanly separates high-level planning from low-level execution. System 2 selects the next sub-goal from verified RAM state and can call tools: Pokédex and guide search over Bulbapedia (lab/agent/web_search.py). Every decision is validated against game memory before execution, and System 1 executes using navigation policies trained entirely in the world model's imagination.

LLM System 2 planner live in the real game: sub-goals chosen from RAM state, every decision validated, System 1 policies executing each leg.
Game harness architecture diagram Game harness architecture diagram
Game harness architecture: System 2 planner, validation against RAM, and System 1 imagination-trained navigation policies.

v1-v2 (earlier world models)

📈 v1: Scheduled Sampling vs. Teacher Forcing - Rollout Drift

Measured over 15,536 held-out trajectories of length 29 steps. Scheduled sampling (SS) is critical: the SS model's compounding drift stays roughly flat (3.71–4.38 tiles) out to 29 imagined steps, while the pure teacher-forcing (TF) ablation reaches 11.63 tiles - a 2.7× degradation.

Rollout Step SS Latent MSE TF Latent MSE SS Tile Error TF Tile Error Improvement
Step 10.101870.136404.38 tiles4.34 tiles0.99×
Step 50.115510.252493.81 tiles5.11 tiles1.34×
Step 100.139150.463853.83 tiles6.98 tiles1.82×
Step 150.155720.690373.92 tiles8.94 tiles2.28×
Step 200.170570.878134.02 tiles10.36 tiles2.58×
Step 250.188850.995884.17 tiles10.81 tiles2.59×
Step 290.201151.065574.25 tiles11.63 tiles2.73×

🌟 v2: RSSM World Model Training Progression

4 epochs on 20 NPZ files (~16,000 native-resolution transitions). Batch size 64, sequence length 15. Reconstruction loss steadily decreases - the best checkpoint (epoch 4, val recon = 0.1003) demonstrates pixel-level world modeling at native Game Boy resolution.

Epoch Train Loss Train Recon Train KL Val Loss Val Recon Val KL
10.14760.13790.00780.12660.12560.0010
20.12070.11440.00630.11720.11100.0062
30.14900.10680.04220.12280.11420.0086
40.10210.10150.00050.16510.1003 ★0.0648

v1 vs v2 Architecture Comparison

How the world model evolved across versions - from continuous latents and teacher forcing to discrete RSSM with KL-balancing.

Component v1 (VAE + GRU) v2 (Discrete RSSM)
Resolution 40×36 pixels (PWhiddy downsampled) 160×144 pixels (native Game Boy)
Encoder Variational Autoencoder (VAE) 4-layer Residual CNN → 512-dim embed
Latent Space Continuous R³² (reparameterization) Discrete 32×32 categorical (1024-dim)
Dynamics Autoregressive GRU (scheduled sampling) RSSM: GRU h_t (512) + Stochastic s_t
Gradient Estimator Reparameterization trick Gumbel-Softmax straight-through
KL Balancing Standard ELBO 80% prior / 20% posterior balancing
Imagination Prior-only rollout Full posterior + prior with KL balancing
Decoders Pixel decoder only Pixel + Reward predictor + Continue predictor
Controller Lookahead MPC planner (coordinate probe) Actor-Critic trained in imagination

Quick Start Guide

Get PokéDreamer running in minutes. You'll need a legally-obtained Pokémon Red ROM.

01

Clone & Install

bash
git clone https://github.com/xoTEMPESTox/PokeDreamer.git
cd PokeDreamer
conda env create -f environment.yml
conda activate pokemon-rl
02

Place ROM & Collect Data

Copy your legally-obtained Pokemon - Red Version (USA, Europe).gb to the project root. Alternatively, download the pre-collected dataset from Hugging Face.

bash
# Collect data (optional - dataset available on HF)
python legacy/v2/scripts/collect_data.py --episodes 20 --out-dir data
03

Train the RSSM World Model

bash
python legacy/v2/scripts/train_rssm.py \
    --data-dir data \
    --epochs 12 \
    --batch-size 64 \
    --out-dir legacy/v2/checkpoints/rssm_v2
04

Generate Imagination Demo

Renders a side-by-side video comparing the real emulator vs. the RSSM's imagined frames.

bash
python legacy/v2/scripts/generate_demo_video_v2.py \
    --checkpoint legacy/v2/checkpoints/rssm_v2/best_world_model.pt \
    --save-state saves/intro_done.state \
    --out-video legacy/v2/checkpoints/rssm_v2/side_by_side_demo_v2.mp4

Models, Datasets & References

📖 References & Credits

  • DreamerV2/V3 Hafner et al. (2021, 2023) - Mastering Atari with Discrete World Models / DreamerV3. Primary RSSM architecture inspiration.
  • PWhiddy PPO PokemonRedExperiments - Used as the data collection policy for gathering gameplay transitions.
  • PyBoy Baekalfen/PyBoy - Game Boy emulator used for environment interaction and screen capture.
  • DIAMOND DIAMOND - Diffusion As a Model Of eNvironment Dreams. Long-term architectural reference point for v3.