DOOMFORMER: the marine fights a horde of demons under a hellish sky

A compiler that turns neural networks into DOOM maps where voodoo dolls do the arithmetic.

Conveyor belts carry voodoo dolls across weighted lines that change light levels or floor heights. Staircases turn those values into activations by controlling how many dolls pass. Python reads the results from the running game and fails on any difference from the integer reference.

DOOM reads handwritten MNIST digits with 97% accuracy: all 10,000 test digits ran through four tile maps with Python passing values between them, and every value read from the game matched NumPy exactly, while DrawPad, below, runs the same network in one map.

Walk a digit, DOOM reads it

The marine holds FIRE to ink the floor and then presses READ, which writes the 784 pixels into a network trained on MNIST and scripted strokes, and its 1,355 voodoo dolls compute the network inside the same map until the winning digit's doll lights the display.

All 30 scripted digits were classified correctly with all 248 values matching NumPy on every run, and a READ takes 273 game tics, about 8 s, at the default --opt 3. How it works · drawpad.mp4, 16 s, 1.5 MB

# arrows walk, hold Ctrl to draw, Space: READ
doomformer draw
# headless: the marine walks a 7
doomformer draw --digit 7
# the same map as a WAD that GZDoom plays without Python
doomformer draw --build drawpad

His brain is the level

The marine fights in the map that computes his policy, and the dots on the right are 1,345 voodoo dolls of him. A level script senses the nearest demon, the dolls pick an action and the level turns him or fires, while Python only advances the clock and reads the results, and all 50 decisions match NumPy. The film is time-lapsed, and the demons are frozen while the dolls compute.

Details · brain_is_the_level_raw.mp4, 53 s, 22.6 MB

Commands

pip install git+https://github.com/mottopanikeiku/doomformer   # Python 3.11+, Linux or macOS

Install it in a virtual environment, and because the first run builds ACC, the level-script compiler, install git, cmake, make and a C/C++ compiler first and then run doomformer doctor to check the setup.

CommandWhat DOOM doesTimeSkill level
doomformer helloa small MLP, 5 random inputs2 sI'm too young to die
doomformer draw --digit 7the marine walks a 7, the level reads it15 s
doomformer mnistreads 4 test digits, or your own image1.5 to 3 min per digitHey, not too rough
doomformer demoa transformer writes a level name15 to 60 sHurt me plenty
doomformer demo --nightmarethe 2-layer model, 106 tile maps3.5 to 7 minNightmare!
doomformer ask "what does iddqd do"answers from 189 DOOM factsabout 11 minUltra-Violence

ask answers 94.7% of its training questions correctly and 35.4% of new wordings, and a small MLP runs about 23,000 times slower than NumPy on a 16-core arm64 machine. Every command

How it works

  1. your networkPyTorch / NumPy
  2. integersquantised
  3. a DOOM maplanes, gates, lava lines, doors
  4. ViZDoom runs itvoodoo dolls walk
  5. read backlight levels and plane heights
  6. EXACTevery readback equals the NumPy integer reference

DOOM turns every extra player start into a voodoo doll, a copy of the player that rides conveyors and triggers every line it crosses, so an activation of 5 is five dolls. A staircase lets a doll past each step only if the value clears it, which gives ReLU, rounding and clamping in one shape.

A second floor move in the same sector and tic is lost, a teleport cancels lines crossed earlier that tic, and objects far from a BSP node land in the wrong room, so these constraints shape the compiler (engine details).

counter.wad (2006) counts with voodoo dolls, conway.wad runs Game of Life, and Danny Spencer's calculator adds numbers. Doomformer compiles neural networks into these mechanics and checks their outputs against NumPy.

Bigger experiments

Every value read from these runs matched the NumPy integer reference, and the films show selected runs (demo results).

DOOM dreams of DOOM

A 2-layer name model writes DEMON CANYON and a Python generator builds the level, which a marine whose policy runs in 55 games plays for 120 decisions, with 3 neuron lanes closing at decision 50.

trilogy.mp4, 48 s, 11.5 MB

DOOM plays DOOM

A 1-layer policy navigates the generated level, opens doors, kills two demons and reaches the exit in 102 decisions, with Python supplying the compass and enemy positions.

doom_beats_doom.mp4, 37 s, 10.4 MB

DOOM learns

In this earlier learning run, 156 dolls train a 38-weight perceptron inside one map by raising and lowering ceiling heights, while Python bins the features and supplies the aimbot's labels.

one_game.mp4, 44 s, 19.3 MB

Lobotomy

A 7-pellet blast to his DOOM brain stops him firing, so he gets 0 kills over 74 decisions.

lobotomy.mp4, 29 s, 4.7 MB

A 4-layer transformer

A 4-layer transformer writes UNHOLY STRONGHOLD over 10,166 tile runs, which share a pool of games, and 208,598 voodoo dolls.

full_brain.mp4, 28 s, 2.6 MB

A fruit-fly circuit

A 255-neuron circuit derived from the FlyWire connectome runs for 169 steps as the marine visits four stations: eat, refuse, groom, take off.

FLY.md · fly_alive.mp4, 71 s, 5.8 MB

A whole transformer in one map

A 1-layer, d=8 transformer writes SHIL using 3,548 voodoo dolls, and the map computes embeddings, attention, MLP and logits without Python between layers (time-lapsed).

onemap_shil_raw.mp4, 58 s, 6.5 MB

Generation without Python

The winner's doll writes the next token and the level rewinds itself to generate DAN while Python only advances the clock and reads the results. The overhead view uses ViZDoom's 4,096-object list, so some dolls are absent from the picture.

selfgen.mp4, 56 s, 6.9 MB

The showreel

A one-minute compilation: voodoo dolls on lava, attention gates, level generation, the marine playing and learning, lobotomy, a transformer in one map and his brain inside the level.

showreel.mp4, 56 s, 25.1 MB

Run it yourself

These run from a clone after pip install -e ., and the demo commands, timings and sample output are in the repository.

Build your own

Compile a network into a map and let its outputs open doors, flash lights or shove the marine.

import numpy as np
import doomformer as df

# 2 inputs -> [a AND b, a OR b] -> 2 outputs, all integers
net = df.MLP(
    weights=[np.array([[1, 1], [1, 1]]), np.array([[1, 0], [0, 1]])],
    biases=[np.array([-1, 0]), np.array([0, 0])],
    thresholds=[np.array([1]), np.array([1])],
    signed_input=False,
)
with df.compile(net) as brain:
    for x in ([0, 0], [1, 0], [1, 1]):
        # computed by voodoo dolls; raises df.MismatchError on any difference from net.reference
        print(x, "->", brain(np.array(x)).tolist())
    brain.record([np.array([0, 1]), np.array([1, 1])], "dolls.gif")   # film the dolls doing it

Start with BUILD_YOUR_OWN.md or the 12 runnable examples.