Bruno Corcuera · Carlos Eiras-Franco · Brais Cancela
Universidade da Coruña · CITIC Research Center
Project page
·
NeurIPS 2026 paper
A generative world model that holds scene content in a persistent latent code, encoded from a map or sampled from its prior, and evolves only an explicit agent state, so revisited places stay consistent across long imagined trajectories.
SWM separates what stays fixed during an episode from what moves. The scene code
Scene encoder src/models/dds_vae.py). A two-stage VAE [1] over the 128×128 map, built on dynamic feature selection [2].
- Stage 1 is a deterministic compression backbone. A selection UNet feeds DDS gates (hard-concrete gates with a per-map top-k mask over input units), and learned downscaling produces a bottleneck
$\mathbf{h} \in \mathbb{R}^{16\times16\times16}$ . An upscaling path and a refinement UNet reconstruct$\mathbf{m}$ under MSE + L1. - Stage 2 freezes the backbone and fits a small VAE on
$\mathbf{h}$ , with$\lVert \hat{\mathbf{h}} - \mathbf{h} \rVert^2 + \beta, \mathrm{KL}\big(q_\phi(z \mid \mathbf{m}) ,\Vert, \mathcal{N}(0, I)\big)$ and an annealed$\beta$ .
Held-out maps embed without per-scene optimization, and scene codes can also be sampled from the prior.
Observation model src/models/generator.py). The state passes through Fourier features [3] to overcome the spectral bias of MLPs on low-dimensional inputs [4]. It is projected to the scene-code width and fused additively with
Transition model src/models/transition.py). The state is encoded with its own Fourier features,
Position is integrated additively. Heading is integrated in angle space and mapped back to sine–cosine features, so the renderer input stays continuous:
Training uses teacher forcing on the weighted squared error of the standardized increments, in fp32 with TF32 disabled to limit accumulated rollout error:
Checkpoints are selected by free-running error, rolling
The three models are trained in sequence on precomputed scene codes, using PyTorch and Lightning with pyrallis dataclass configs. Each run logs TensorBoard metrics, its training FLOPs (flops.json), and CodeCarbon energy use (emissions.csv).
src/envs/dm_lab_maze.py wraps the procedural maze level of DeepMind Lab [6] (third_party/deepmind_lab/random_maze_safe.lua, built on the lasertag procedural factory without bots). The maze parameters come from Python:
- 13×13 mazes with up to four rooms of 3–5 cells;
- pickups;
- one maze per seed.
| Quantity | Definition |
|---|---|
| Scene map |
Engine top-down camera, 128×128 RGB, one per episode. All maps span the same world range |
| Observation |
First-person RGB, rendered at 128×128 and stored at 96×96 |
| Raw state |
|
| State |
|
| Increment |
|
| Action |
|
Each step repeats the action for two engine frames at 30 fps. The rollout dataset stores base_seed + episode_id, so every rollout can be regenerated exactly. The viewers load src/envs/dmlab_levels/interactive_maze.lua, which extends the same level with a teleport property for placing the agent on the map.
Rollouts are collected without a pretrained navigator. Random policies cover the maze poorly and get trapped locally, so the data comes from a planner that reads the same top-down map SWM later encodes (src/envs/dmlab_autonomous_exploration/, src/datasets/make_rollouts_dmlab.py).
Occupancy and waypoints. The map is segmented into a walkable grid by color distance to the wall color, with borders cropped and free space eroded away from walls. The agent cycles through the map center and four inset corners, each snapped to the nearest walkable cell by breadth-first search.
Travel-time field. For a waypoint $\mathbf{x}g$, the planner solves the eikonal equation on the 128×128 grid. The speed $F$ drops near walls: $d\text{wall}$ comes from a Euclidean distance transform of the occupancy grid, so routes follow corridor centers instead of hugging corners:
The fast sweeping method [7] solves it with a Godunov upwind discretization. Cell
-
Sweep orderings. The update is applied in place, Gauss–Seidel style, in the four orderings
$(i!\uparrow, j!\uparrow)$ ,$(i!\uparrow, j!\downarrow)$ ,$(i!\downarrow, j!\uparrow)$ ,$(i!\downarrow, j!\downarrow)$ . Each ordering propagates information along the characteristics of one quadrant, so a few rounds of four sweeps cover a maze. -
Cost. Each sweep is a plain
$O(N)$ pass over the grid, with no priority queue as in fast marching [8]. The loops are compiled with Numba, and the field is recomputed only when the waypoint changes.
Control. The agent at position
It turns in place when
Perturbations. Pure gradient descent on balanced policy adds four perturbations:
- a sinusoidal slalom with a random phase, frequency, and amplitude per episode;
- a slowly drifting heading offset;
- short random-action bursts;
- in-place look-around turns.
All four are damped in narrow corridors, which are detected from the local free-space ratio. They widen state and viewpoint coverage without leaving the walkable region. The policy is selected with --policy (balanced, fast_sweeping, slow_fast_sweeping, random).
Create a Python 3.11 environment and install the pinned dependencies (PyTorch 2.6, CUDA 12.4):
conda create -n swm python=3.11 && conda activate swm
pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu124DeepMind Lab is not on PyPI. It is built from source as a Python wheel and installed into the same environment. Install the system packages listed in DeepMind Lab's docs/users/build.md (C++ toolchain, SDL2, OSMesa, Lua 5.1, and others) and Bazelisk. third_party/deepmind_lab/build.patch updates the upstream build for current toolchains:
- pins Bazel 6.5.0 through
.bazelversion(Bazelisk fetches it) and disables Bzlmod; - declares
rules_ccandrules_python, and pinsabseil-cppto a release tag instead ofmaster; - builds the extension for Python 3 only, against the headers of the
python3onPATH; - drops the
pkg_resourcesdependency from the package loader.
Because of the third change, build with the SWM environment activated, so that the extension matches its Python and NumPy. The maze level used by SWM is copied into the source tree before building, so it is packaged with the wheel:
git clone https://github.com/google-deepmind/lab.git && cd lab
git apply <swm>/third_party/deepmind_lab/build.patch
cp <swm>/third_party/deepmind_lab/random_maze_safe.lua game_scripts/levels/contributed/dmlab30/
bazel build -c opt //python/pip_package:build_pip_package
./bazel-bin/python/pip_package/build_pip_package /tmp/dmlab_pkg
pip install /tmp/dmlab_pkg/deepmind_lab-*.whl
python -c "import deepmind_lab"To render scene maps with a build used from bazel-bin without installing the wheel, pass its runtime assets to make_topdown_views_dmlab with --runfiles_path.
Settings are dataclasses in src/configs/, and every field can be set from the command line.
python -m src.datasets.make_topdown_views_dmlab # scene maps
python -m src.datasets.make_rollouts_dmlab # exploration rollouts (HDF5)
python -m src.training.train_dds_vae # scene encoder
python -m src.training.train_generator --scene_encoder <dds_vae> # observation model
python -m src.training.train_transition --scene_encoder <dds_vae> # transition model-
src/configs/holds one dataclass per component, parsed by pyrallis.-
dmlab.pydefines the world range and the transforms between simulator coordinates and$s_t$ ,$a_t$ ,$\Delta s_t$ . -
datasets.pyconfigures scene-map and rollout generation. -
dds_vae.py,generator.py, andtransition.pyhold model and optimization settings.
-
-
src/envs/holds the environment code.- The DMLab maze wrapper resets by seed, caches the top-down map, and resets automatically at episode end.
-
DMLabSimulatorserves episodes to the viewers in the dataset's conventions. - The Lua levels live here.
-
dmlab_autonomous_exploration/holds map segmentation, world–grid mapping, fast-sweeping distance maps, the steering controller, and the waypoint manager.
-
src/datasets/holds data generation and loading.- The map and rollout generation scripts.
-
generation.pyruns parallel, sharded, resumable episode writing and the final merge. -
maps.pyprovides the map dataset and its splits. -
rollouts.pyprovides episode splits, per-episode scene encoding, and frame and sequence-window datasets.
-
src/models/holds the three models.layers.pyholds the Fourier features shared by the observation and transition models. -
src/training/holds the three entry points.-
utils.pycovers versioned run directories, the cosine schedule, the shared Lightningfit, CSV and TensorBoard logging, preview images, and summary plots. -
callbacks.pycounts training FLOPs and tracks energy with CodeCarbon.
-
-
assets/holds the README figures and the scripts that draw them, with shared SVG helpers insvg_utils.py.-
python assets/render_architecture.pyrebuilds the architecture animation from its SVG template and the map and frames inassets/architecture_frames/. Use--durationto set the loop length in seconds. -
python assets/make_rollout_overview.pyrebuilds the animated rollout figure from its SVG template and the scene map and observations inassets/rollout_frames/. Use--durationto set the loop length in seconds.
-
src/tools/ holds pygame viewers and a benchmark that run on trained checkpoints. render_models.py loads compatible checkpoints and encodes scene maps to posterior means. render_utils.py holds the shared window and drawing helpers. Keyboard and mouse controls are listed in each module's docstring.
| Module | What it does |
|---|---|
render_transition |
Drives the simulator and the free-running SWM with the same keyboard actions. Shows the simulator view, renders at the simulator and predicted states, and both trajectories on the map. Resynchronizes on demand. |
render_generator |
Compares the simulator observation with |
render_prior_scenes |
Samples |
render_dds_vae_latent |
Explores the scene-code space: posterior means of dataset maps, PCA plane and sliders, per-dimension edits, map interpolation, and prior samples. |
render_fast_sweeping_dmlab |
Runs the exploration policy live with the observation, the travel-time field replayed sweep by sweep, and the descent route. |
render_rollout_dataset |
Plays recorded HDF5 episodes with the trajectory on the scene map. |
benchmark_swm_speed |
Measures SWM as a simulator: frames per second for one environment and the largest batch of parallel environments that keeps a target rate, on GPU and CPU. Writes JSON, which assets/make_speed_chart.py plots. |
python -m src.tools.render_transition --checkpoint <transition.ckpt> --generator <generator.ckpt>| Notebook | What it shows |
|---|---|
dataset.ipynb |
Scene-map PNG datasets and rollout HDF5 files: sample maps, episodes, and their contents. |
dds_vae.ipynb |
A trained scene encoder on held-out maps. The pipeline from map through DDS selection and bottleneck to the reconstructions; prior samples and interpolations; per-dimension KL, the aggregate posterior against |
transition.ipynb |
A trained transition model on complete held-out episodes. Free-running trajectories on the scene map; rollout against one-step error as it accumulates over steps and beyond the training window; predicted states inside walls and their signed distance to the nearest wall; and a scene-code ablation (own, shuffled, prior, and zero codes). |
fast_sweeping_dmlab.ipynb |
The exploration planner step by step: segmentation and waypoints, wall-aware speed, the local eikonal update, Gauss–Seidel sweeps and their convergence, descent routes, steering, and one field per waypoint. |
MIT, see LICENSE. Files in third_party/deepmind_lab/ derive from DeepMind Lab and are distributed under the GNU GPL v2.0, see third_party/deepmind_lab/LICENSE.
- D. P. Kingma, M. Welling. Auto-Encoding Variational Bayes. ICLR, 2014.
- B. Corcuera, C. Eiras-Franco, B. Cancela. Unsupervised Dynamic Feature Selection for Robust Latent Spaces in Vision Tasks. arXiv:2510.01758, 2025.
- M. Tancik et al. Fourier Features Let Networks Learn High Frequency Functions in Low Dimensional Domains. NeurIPS, 2020.
- N. Rahaman et al. On the Spectral Bias of Neural Networks. ICML, 2019.
- R. Zhang, P. Isola, A. A. Efros, E. Shechtman, O. Wang. The Unreasonable Effectiveness of Deep Features as a Perceptual Metric. CVPR, 2018.
- C. Beattie et al. DeepMind Lab. arXiv:1612.03801, 2016.
- H. Zhao. A Fast Sweeping Method for Eikonal Equations. Mathematics of Computation, 74(250):603–627, 2005.
- J. A. Sethian. Level Set Methods and Fast Marching Methods. Cambridge University Press, 1999.