neural-doom / WRITEUP.md
Quazim0t0's picture
Update WRITEUP.md
bacd258 verified
|
Raw
History Blame Contribute Delete
6.58 kB
# Some people get DOOM to play on a fridge. I got it to play on a neural net.
Not "an AI that imagines DOOM frames." Not a video model hallucinating
something DOOM-ish. The actual 1993 DOOM β€” id Software's real, unmodified
code, compiled to real x86 machine instructions β€” executed by a computer whose
arithmetic and logic are **neural networks**, producing output **bit-identical**
to a normal CPU. Every pixel. Every byte of memory. Exact.
## The problem with neural networks (and why this should be possible)
Neural networks are approximators. They're brilliant at "close enough" β€”
recognizing a cat, finishing your sentence. But a CPU lives or dies on
*perfection*. If one addition out of a million comes back wrong by one bit,
the program doesn't get slightly worse β€” it crashes, or corrupts a save, or
draws garbage. 99.99% accurate arithmetic is 0% playable DOOM. So "run a real
program on neural networks" sounds like a category error.
The trick that makes it possible is stolen from how chips are actually built:
1. **Break the machine into tiny pieces** β€” the way silicon engineers do. An
8-bit adder. A 1-bit shifter. An instruction decoder. Each piece is so
small that you can list *every single input it could ever see* (an 8-bit
adder with carry has exactly 131,072 possible inputs β€” a big number to a
human, a tiny one to a computer).
2. **Train a small neural network on the complete list.** Not a sample β€” all
of it.
3. **Test it on the complete list.** It passes only if it gets every single
case right. 131,071 out of 131,072 is a fail. I retrain until N-of-N.
4. **Wire the verified pieces together** exactly like the chip wires its
circuits: a 32-bit addition is four 8-bit neural adders passing a carry
down the line; multiplication is shifted adds; division is repeated
subtraction. Exact pieces, wired exactly, make an exact whole β€” *forever*,
not just usually.
And when a piece is too big to enumerate? You never train it bigger β€” you
**decompose it further**. Multiplication wouldn't train as one network, so it
became a trivial "multiply a byte by one bit" network (512 cases) feeding an
adder tree, which is literally how hardware multiplies. Every time I hit a
wall in this project, the answer was more decomposition, never a bigger model.
## How I got here
**It started with a Game Boy.** First one neural 8-bit adder, verified exact.
Then a whole Game Boy CPU (512 instructions), a pixel pipeline, a memory
system β€” every functional unit a verified network. The proof bar kept rising:
the core passed the same test suites real emulator developers use
(SingleStepTests: 512,000 randomized cases; Blargg's hardware-validated
cpu_instrs: 11/11), and then a real cartridge game ran on it, with one full
frame replayed entirely through the neural units β€” bit-identical to a
conventional emulator, framebuffer and complete machine state.
- **13 neural units** for the x86: 8-bit add/subtract slices carrying all five
x86 arithmetic flags, the logic ops, 1-bit shift slices, the multiplier
slice, and the instruction-decode tables. Each verified over its complete
domain.
- **An i386 core** wiring them together, validated by differential fuzzing
against QEMU β€” 194 instruction templates, 2,560 randomized full-machine
states, total agreement.
- **A tiny Linux** (an ELF loader and ~30 system calls) so the machine could
run real programs, with every clock deterministic so any run can be replayed
bit-for-bit.
- **DOOM itself**, cross-compiled to i386, booting through its full init
chain to the title screen in 20 million instructions.
**The headline proof:** I froze the machine at the title frame and ran the
next frame β€” **5,952,699 instructions** β€” twice. Once with conventional math.
Once with every decode, add, shift, multiply, and divide computed by the
neural networks. 102 minutes of neural inference later: the framebuffer was
**bit-identical**, and so were all 128 MB of memory, every register, every
flag. Not similar. Identical.
**Then I made it playable.** Neural inference is slow, so the same wiring
diagram was ported to C β€” just the wiring; the neural units remain the
machine's ground truth β€” running at 77 million instructions/second. That's
the DOOM you can play above. And while you play, the original neural machine
doesn't go away: sampled instructions are continuously re-executed by the
neural units and compared against the live CPU. In a two-minute session,
**57,110 out of 57,110 audits came back exact**.
## What this is actually for
- **It's a proof about composition.** "Neural networks are unreliable" is a
statement about monoliths. Exhaustively verified small networks, composed
the way hardware composes circuits, are *components* β€” and you can build
arbitrarily large exact systems out of them. A Game Boy. An x86. DOOM.
- **It's a proof about verification.** Every claim on this page is checkable,
and most of them you can re-run yourself, right here: the GPU button above
re-verifies all 525,000+ unit cases from the shipped weights in seconds;
the segment button re-executes real DOOM code neurally and hashes the
result against the golden reference; the microscope shows you individual
neural nets computing individual instructions.
- **And the bug report says it all:** across the entire project β€” two CPU
architectures, thousands of composed units β€” the test suites found exactly
**one bug, and it was in hand-written glue code** (two entries swapped in a
lookup table a human typed). No verified neural unit was ever wrong. The
discipline of "enumerate, train, verify everything, compose" did exactly
what it promised.
## Honest limits
The fully neural machine runs at ~1,000 instructions/second β€” the playable
DOOM above uses the C wiring with the neural units as its continuously-audited
specification, and the complete-frame neural proof is the offline 102-minute
run. The audits *sample* the instruction stream rather than checking all 60
million per minute. There's no sound, and the machine implements the subset
of a PC that DOOM needs (no floating point β€” DOOM never uses it). None of
these caveats touch the central claim: every comparison ever made between
this machine's neural units and ground truth β€” exhaustive, fuzzed, replayed,
or sampled live β€” has come back **exact**.
---
*Built brick by brick: one adder β†’ a Game Boy β†’ a real cartridge game β†’
an x86 β†’ DOOM. The weights, the DOOM binary, the snapshot, and every proof
log ship with this Space.*