Dreaming to Dodge

An agent learns to survive first-person VizDoom entirely inside a from-scratch Transformer world model โ€” it never touches the real game during training.

Rajat Dandekar

Vizuara AI Labs

The trained agent dodging fireballs in VizDoom take_cover

The imagination-trained agent playing the real game. It learned to strafe away from incoming fireballs having practised only in a dream โ€” a learned neural simulator, never the real engine.

96.8
steps survived
(40 held-out seeds)
99%
of oracle survival
(97.7 reactive oracle)
0
real-env gradient
steps in training
~1.8k
policy parameters
(evolved in the dream)
The whole idea

Practise in a dream,
then play for real

A world model is a neural network that learns to imagine the game. Once it can dream convincingly, the agent rehearses thousands of lives inside the dream โ€” cheap, fast, and safe โ€” and only ever plays the real game.

why it's surprising

The agent we ship never touched the real game while learning to act. It learned to dodge entirely from imagined experience.

Practise in a dream, then play for real
Sleep, dream the corridor, rehearse the dodge โ€” then wake up and play.
Abstract

Abstract

World models promise sample-efficient reinforcement learning: rather than learn from expensive real interaction, an agent practises inside a learned neural simulator. We reproduce, from scratch, the landmark World Models (2018) result โ€” training a policy entirely inside its own dream on VizDoom take_cover โ€” using the stronger discrete, Transformer-based IRIS (2023) recipe: a VQ-VAE tokenizer, a GPT world model over frame tokens, and a policy optimised purely on imagined rollouts. Our final agent โ€” which never touches the real game during learning โ€” survives 96.8 steps on 40 held-out episodes, beating a random policy by +30%, beating a model-free Double-DQN trained on the same real-frame budget, and matching a hand-coded reactive oracle (97.7, i.e. 99% of oracle survival). Beyond the number, we document the failures that make model-based RL brittle โ€” codebook collapse dropping the lethal object, a termination head that never predicts death, and world-model exploitation โ€” and the fixes that overcome them. We release the code and a playable neural simulator in which anyone can drive the world model directly.

Method

How it works โ€” three from-scratch parts

Method pipeline: tokenizer, world model, controller
A VQ-VAE tokenizer maps each 64ร—64 frame to a small grid of discrete tokens; a GPT world model predicts the next frame's tokens, the reward, and termination; a tiny controller (~1.8k params) is evolved by CMA-ES to maximise survival inside the dream. The policy is only ever evaluated in the real game.
Tokenizer intuition
Tokenizer. Compress a frame to symbols, then rebuild it โ€” keeping the tiny bright fireball.
World model predicts the next frame
World model. Given the past and an action, predict the next frame โ€” like a language model over pixels.
Imagination rollout
Imagination. Feed predictions back in to roll the dream forward, with no game engine.

The lethal object โ€” a fireball โ€” is only a few bright pixels, so a naive tokenizer smooths it away and the dream has no threat. A warmth-weighted reconstruction loss keeps it (fireball-recall 0.53 โ†’ 0.95). Because death is ~1% of steps, an unweighted termination head collapses to "always alive"; a class-weighted loss restores it. And a KV cache makes the autoregressive dream 9.6ร— faster โ€” the difference between feasible and infeasible policy search.

Results

Trained in the dream, oracle-level survival

On 40 held-out seeds the imagination-trained agent nearly matches a hand-coded oracle and clearly beats random play โ€” despite never training in the real game.

Survival distributions
Survival distributions on held-out seeds: our agent (blue) tracks the oracle (green); random (grey) trails.
Mean survival with 95% CI
Mean steps survived with 95% confidence intervals โ€” small gap to the oracle, large gap over random.
AgentSurvival (steps)Note
Random74.4lower reference
Model-free Double-DQN (same real-frame budget)90sample-efficiency bar
IRIS agent โ€” trained 100% in imagination96.8held-out, 40 seeds
Heuristic oracle (reactive; sees the game)97.7upper reference

Verified consistent across three independent seed sets. The agent's action distribution is [0.00, 0.54, 0.46] over {no-op, left, right} โ€” genuinely reactive, choosing its strafe from the fireball rather than collapsing to one direction.

Analysis ยท what it learned

A genuine dodging reflex

Across ~3,900 real moments we logged where the fireball was and which way the agent stepped. The avoidance pattern is unmistakable:

  โ€ข fireball on the left โ†’ agent moves right
  โ€ข fireball on the right โ†’ agent moves left

not a memorised script

It learned to react to the threat position โ€” a real policy, learned only from dreaming.

Action tendency vs fireball position
Action tendency vs fireball position โ€” a clean avoidance curve.
Analysis ยท trusting the dream

Sharp up close,
blurry far out

Imagined rollouts drift: errors compound the further ahead the model dreams. We measure it directly and train the policy on the short, faithful window.

design choice

Short imagined rollouts stay close to reality โ€” so that is where policy search happens.

Dream fidelity vs rollout horizon
Pixel error vs how far ahead the model dreams (25 real seeds).
The hard part

The agent tries to cheat the dream

Train a policy against a model and it will find the model's blind spots โ€” an imagined "safe corner" where the dream forgets to spawn fireballs. It scores perfectly in imagination and dies instantly in reality. Early controllers collapsed to a single fixed action.

The fix โ€” three disciplines. A tiny controller too small to memorise exploits; acting on the reconstructed image so the policy can't latch onto token quirks; and held-out selection with best-of-N โ€” keep the brain that survives dream seeds it never trained on.

Model exploitation
Model exploitation: winning the dream by exploiting its flaws.
Held-out selection
Choose the controller that generalises to unseen dream seeds โ€” the exploiters get filtered out.
The wow moment

Play inside the dream ๐Ÿ•น๏ธ

There is no game engine below โ€” every frame is predicted by the Transformer world model in response to your keypresses. Hold โ†/โ†’ to strafe, or switch to watch the AI to see the trained controller play inside its own dream. (First load cold-starts a GPU, ~30โ€“60 s.)

Trouble loading here? Open the simulator in a new tab โ†’

Inside vs. outside the dream

The same agent, two worlds

Agent acting inside the dream
The agent acting inside the world model's dream โ€” no engine; the Transformer generates each frame.
Agent dodging in the real game
The same agent in the real game across one episode, strafing clear of fireballs.
Tokenizer reconstructions
Tokenizer keeps the fireball through quantization (left: real, right: decoded).
Fireball recall
Warmth-weighting lifts fireball recall 0.53 โ†’ 0.95.
A real game frame
A real take_cover frame: the rare bright fireball is the whole challenge.
Zoom out

One recipe, bigger worlds

The bouncing ball, the spreading outbreak, the incoming fireball โ€” all are the same move: predict the next state, then plan inside the prediction. Master the small world and the method scales up.

One idea at three scales
One idea at three scales: the ball, the outbreak, the fireball.
Citation

Citation

@misc{dandekar2026dreamingtododge,
  title  = {Dreaming to Dodge: An Agent that Learns to Survive VizDoom
          Entirely Inside a From-Scratch Transformer World Model},
  author = {Dandekar, Rajat},
  year   = {2026},
  note   = {Vizuara AI Labs}
}