← neural6502

Target reached, single networkDownloadable

Can a neural network be a CPU?

Teaching a neural network to be a 1975 MOS 6502, bit for bit.

The numbers below are final for the models listed. The write-up says "we" throughout, as the project's own text does. The goal of 100% on every test is reached twice: by three networks voting, and then by a single network, which also runs the complete Klaus test. The code is on GitHub; the software, the weights and the result files are also on the project page.

Contents

  1. 1. The idea
  2. 2. Step one: a perfect reference
  3. 3. Step two: turning a CPU into a function a network can learn
  4. 4. Step three: teaching it
  5. 5. One big network, or many small experts?
  6. 6. The networks: a family tree and an outsider
  7. 7. Results
  8. 8. Debugging a neural CPU
  9. 9. Why several networks? Error correction by voting
  10. 10. A neural CPU vs. the real silicon
  11. 11. What didn't work, and what we learned
  12. 12. Try it yourself
  13. Glossary

In one paragraph

We trained a 1.7-million-parameter neural network to behave exactly like the MOS 6502, the 8-bit processor inside the Apple II, NES and BBC Micro (and, as the slightly extended 6510, the Commodore 64). The network holds the whole CPU: decoding instructions, computing addresses, doing arithmetic, setting flags and running the stack. Around it sits nothing but a block of memory that answers "read this address" and "write this byte". Fed its own output, cycle after cycle, the network runs real 6502 programs: a sorting routine, a prime sieve, a multiplier, Fibonacci. It runs them bit-exactly, compared against a reference emulator after every instruction. On the 1.43 million single-instruction tests of the standard ProcessorTests suite, plus the 80,000 that use the 6502's decimal (BCD) arithmetic, a single network gets every one of the 1.51 million tests right. It also runs Klaus Dormann's famous functional test from start to finish, all 30.6 million instructions, without a single error (§7, §9). We got there in two steps: first three independently trained networks voting together got every test right, and then those networks were used to find the rare cases a single network still missed.

Along the way we trained several networks, not one. Three of them are successive versions of the same network, each continuing the last one's training. Later ones were deliberately trained from scratch as independent second opinions. For a long time one network still made roughly one mistake per ten thousand instructions. So we also ran three networks side by side and let them vote on every bit, the way three people checking the same sum catch each other's slips. In the end the voters became a searchlight for the inputs a single network still found hard (§6 and §9 explain).

headlineresult
ProcessorTests, closed loop, all 1,510,000 cases incl. decimal mode, single networkall 1,510,000 exact (100%), 0 failures (mlp_single3)
same, vote of 3 independently trained networksall 1,510,000 exact (100%), 0 failures
Opcodes with every ProcessorTests case exact151 of 151, single network and ensemble
Seven test programs (sort, sieve, multiply, Fibonacci, sum, memcpy, BCD)all bit-exact (several single networks and every recent ensemble)
Klaus Dormann functional test, single networkcomplete run, all 30,646,177 instructions, no error (mlp_clear3); mlp_single3, 100% on ProcessorTests, still made 2 errors in it; best network trained only from scratch: 80,818 instructions (mlp_indep4)
Klaus Dormann functional test, 3-network ensembles300,000 instructions, no error (run limit) for every ensemble of independent networks; the newest, all-decimal trio as well, with a member outvoted on only 5 of 1,083,260 micro-steps
Text screen at $0400 and ONNX exportscreen demo identical to the reference; the final network as a 6.8 MB ONNX file runs all programs bit-exactly, and the complete Klaus run ran on that file
Each networkresidual MLP, 3 blocks of 512, 1.69M parameters
Networks trained17 (16 MLPs + 1 mixture-of-experts experiment); an ensemble votes with 3
Hardwarea 4-core laptop CPU (the GPU died early on)

1. The idea

A CPU is, at heart, a function. Given the current state (registers, flags, the program counter, a few internal latches) and the byte that just arrived from memory, it produces the next state and a request to memory: "read address X", or "write byte Y to address X".

         ┌──────────────────────────────┐
state ──►│                              │──► next state ──┐
         │   f  =  "the CPU"            │                 │
byte  ──►│                              │──► bus request  │
 ▲       └──────────────────────────────┘        │        │
 │                                               ▼        │
 └──────────────── memory (64 KiB) ◄─────────────┘        │
          ▲                                               │
          └───────────────── fed back next cycle ◄────────┘

Neural networks approximate functions. So: can one learn this function so precisely that it never makes a mistake, even when its own output is fed back as its input millions of times? A single wrong bit in the program counter sends execution somewhere random. A single wrong carry corrupts every calculation that follows. There is no "mostly right".

The one rule

The obvious way to cheat is to let ordinary code do the hard parts and only ask the network for the easy ones. We forbade that. All CPU logic lives in the network. The harness around it does exactly two things:

  1. If the network says write, store the byte at the address it gives.
  2. If the network says read, hand back the byte at that address on the next cycle.

The harness never decodes an instruction, never adds an index register, never computes a flag. It is a memory chip, nothing more.

Why the 6502?

It is small (151 official instructions, 13 addressing modes, 3,510 transistors), thoroughly documented, and has excellent public test suites. It also has quirks that make it a real test rather than a toy: a famous bug in indirect jumps, binary-coded decimal arithmetic, and an overflow flag that confuses humans, let alone networks.


2. Step one: a perfect reference

You cannot train or judge a network without a ground truth that is itself beyond doubt. So the first deliverable was a plain Python 6502 emulator, written from scratch:

It was validated against the two standard references:

test suitewhat it isresult
ProcessorTests (Tom Harte)10,000 randomised single-instruction tests per opcode, captured from real hardware behaviour: 1.51 million casesall pass
6502 functional test (Klaus Dormann)a 16 KB assembly program that tests every instruction and flag and traps on the first failurereaches the success address $3469

Both suites were downloaded as data and are only ever read, never executed as code on the host.


3. Step two: turning a CPU into a function a network can learn

A real 6502 instruction takes 2–7 clock cycles, and in each cycle the chip does one memory access. We kept that structure, because it is what makes the "harness is only memory" rule possible. One network evaluation is one micro-step, and each micro-step does at most one bus access.

Everything is bits:

INPUT  (100 bits)                                OUTPUT (119 bits)
┌─────────────────────────────┐                 ┌─────────────────────────────┐
│ A  X  Y  S  P     5 × 8     │                 │ next A X Y S P PC           │
│ PC                16        │   ┌────────┐    │ next IR AL AH T MC   92 bits│
│ IR  (opcode)       8        │──►│  MLP   │──► │ bus address        16       │
│ AL AH (address)  2 × 8      │   └────────┘    │ read?  write?      1 + 1    │
│ T  (temp byte)     8        │                 │ byte to write      8        │
│ MC (step counter)  4        │                 │ instruction done?  1        │
│ DIN (byte read)    8        │                 └─────────────────────────────┘
└─────────────────────────────┘

Every output bit is a separate yes/no prediction. After each step the outputs are rounded to 0 or 1 ("snapped") and the 92 state bits go straight back in as the next input.

A few design choices mattered:

The exact behaviour of every step is defined by an executable micro-step oracle, derived from the reference emulator. It was checked to give identical results to the reference on every ProcessorTests case. The full protocol is in the design notes.


4. Step three: teaching it

Endless, perfect training data

There is no dataset to download. Every training example is generated on the fly: a random CPU state, random memory, one instruction run through the oracle, every micro-step recorded. Values are biased towards the interesting edges, such as $00, $7F, $80, $FF and program counters near page boundaries, because that is where carries and overflows live. Over the full project the network saw about 120 million micro-steps.

A curriculum, like a textbook

The network learns instruction families in order, moving on when the current set is 99.5% right:

  1. loads, stores, register transfers, flag instructions
  2. increment, decrement, AND/OR/XOR, BIT
  3. shifts and rotates
  4. compares
  5. ADC/SBC (addition and subtraction with carry and overflow)
  6. branches
  7. JSR, RTS, RTI, BRK, push and pull
  8. everything mixed

Hard-example mining

Accuracy averaged over everything hides the problem: a network can be 99.9% right overall and still get one instruction wrong every time. Two mechanisms counter this.

What "right" means

The bar is strict. A micro-step counts only if all 119 output bits are right. An instruction counts only if every one of its micro-steps is right.


5. One big network, or many small experts?

The obvious alternative to one big network is a mixture of experts: a small "gate" network looks at the opcode and hands the work to one of several specialist networks, one per instruction family. Each specialist has a smaller job, and since only one runs per step, it is twice as fast. We built and trained both, with the same budget of 10,000 training steps.

one residual MLPhard-routed mixture of 8 experts
parameters1.7 M3.1 M
training speed5,300 examples/s11,600 examples/s
micro-steps exactly right99.93 %75.6 %
opcodes 100 % right97 of 1510 of 151

The gate was perfect: it always picked the right expert. The experts were the problem. The prologue expert, which handles the two steps every instruction shares, reached 99.7%. The stack expert (JSR, RTS, BRK…) reached 3.7%.

The reason is that most of a 6502 is shared. Every instruction family computes addresses, increments the program counter, moves the stack pointer and sets the N and Z flags. One network learns those once and reuses them for every instruction. Split into experts, each one has to learn them again, from a fraction of the data. The hard parts of a CPU cut across instruction families, so dividing the work by instruction family cuts straight through what needed to be learned.


6. The networks: a family tree and an outsider

All the networks in this project have the same design: a residual MLP with 1.69 million parameters. They differ only in how they were trained. Their names describe that:

                        from scratch              continue training          continue, better data
   lineage A:   mlp_base ──────────────► mlp_long ──────────────► mlp_polish
                10k steps               +30k steps               +10k steps

   independent: mlp_indep   (from scratch: different random seed, different
                             activation function, better data, 30k steps)

                    │ continue, with decimal-mode data
                    └──────► mlp_decimal   (+15k steps)

   independent: mlp_indep2  (from scratch again: seed 5, ReLU, decimal mode and
                             targeted data from the start, 32k steps)
   independent: mlp_indep3  (seed 9, SiLU, wider targeted data, 36k steps)
   independent: mlp_indep4  (seed 11, GELU, + "sum near 256" data, 36k steps)
                    │ continue on mined hard cases, three rounds
                    └──────► mlp_single ──► mlp_single2 ──► mlp_single3   (100%)
                             +12k steps      +10k steps      +10k steps

   experiment:  routed_cur  (mixture of experts, §5, abandoned)
networkwhat it iswhy it existstraining time
mlp_basefirst network, trained from scratch with the curriculumthe baseline; proves the approach works64 min
routed_curmixture of 8 expertsthe architecture comparison in §529 min
mlp_longmlp_base, trained 30k steps more on all instructionslonger training brings accuracy from 99.93% to 99.99%2 h 45 min
mlp_polishmlp_long, trained 10k steps more on improved datafixes the data gaps found while debugging (§8)1 h 41 min
mlp_indepa new network from scratch, with a different seed, activation function and dataa second opinion that does not share lineage A's habits (§9)3 h 22 min
mlp_decimalmlp_indep, trained 15k steps more on data that includes decimal modeadds BCD arithmetic, which the older networks leave out (§7)2 h 37 min
mlp_indep2a third line: new from scratch, decimal mode and targeted data from the first stepa member that shares no upbringing with the others, aimed at their leftover errors (§9)2 h 48 min
mlp_indep3the same idea again, with another seed and activation (SiLU) and wider targetinga third outsider; with it, three networks share no history at all (§9)5 h 33 min
mlp_indep4once more (GELU), plus data for sums near 256aimed at the last 2 decimal-mode failures (§9); with mlp_indep2 and mlp_indep3 the 100% vote4 h 45 min
mlp_single, mlp_single2, mlp_single3mlp_indep4, trained further in three rounds on hard cases found by the networks themselvesone network that gets everything right on its own (§9)2 h 51 min, 1 h 10 min, 1 h 25 min (+ 1–2 h search per round)

Lineage A is really one network at three moments in time. Each step starts from the previous network's weights and keeps training. That is efficient: no work is thrown away. But it also means the three versions inherit each other's quirks. If mlp_base learned a wrong shortcut, mlp_long probably still carries traces of it.

mlp_indep is the outsider. It starts from different random weights and uses a different activation function. It also learned from the improved data from the very first step. It reached the same accuracy by a different route, so where it goes wrong is largely unrelated to where lineage A goes wrong. Exactly that makes it valuable in an ensemble (§9).

Training on a laptop

The original plan was a GPU. The laptop's small NVIDIA MX150 (2 GB) worked for the first experiments at about 35,000 examples per second. Then it ran out of memory, and Windows reported "GPU is lost. Reboot the system to recover this GPU." Rebooting was not an option mid-project, so every network here was trained on a 4-core laptop CPU at 5,000–7,000 examples per second.

A recurring pattern: with a constant learning rate, the count of perfect opcodes jumps around wildly. In mlp_long it went 19 → 2 → 97 → 58 between checkpoints. It only settles once the learning rate is lowered gradually at the end. Most of the final accuracy is won in that last phase. The chart below shows it.

Opcodes that are 100% right during training, per run Line chart. The count of the 151 opcodes that are fully right on held-out examples, against training steps. It stays near zero for the first 8,000 steps, then climbs in jumps to 97 at 10,000 steps, wobbles between 2 and 98 while the learning rate is constant, and settles at 147 after the final polish run. A second run, the mixture of experts, stays at zero. 0 50 100 151 0k 10k 20k 30k 40k 50k training steps (cumulative) opcodes fully right (of 151) mlp_base mlp_long mlp_polish one network, trained in three stages mixture of experts (10k steps, stays at 0) 147
How many of the 151 opcodes the network gets completely right on held-out examples while it trains. This is a different measure from the ProcessorTests numbers elsewhere on this page, which count test cases from an outside suite. The count jumps around while the learning rate is constant and only settles once it is lowered.

7. Results

Single instructions: 1.43 million ProcessorTests

Which network is which: see §6. Every ProcessorTests case was run closed-loop through the network. The memory-only harness loads the initial RAM, the network runs the instruction on its own, and the final registers and RAM must match exactly. (Decimal-mode ADC/SBC cases are excluded here, because these networks were not trained on decimal mode. That is 80,093 cases. The decimal network at the end of this section is scored on all of them.)

modelexactfailuresopcodes with all cases exact
mlp_long1,429,576 (99.977 %)33182 / 151
mlp_polish1,429,756 (99.989 %)151110 / 151
mlp_indep1,429,872 (99.998 %)35126 / 151
mlp_indep21,429,861 (99.997 %)46124 / 151 (all cases incl. decimal)
ensemble long+polish+indep (vote)1,429,876 (99.998 %)31138 / 151
mlp_indep31,429,885 (99.998 %)22130 / 151 (all cases incl. decimal)
ensemble indep+indep2+decimal (vote)1,429,904 (99.9998 %)3148 / 151
ensemble indep+indep2+indep3 (vote)1,429,907 (100 %)0151 / 151
ensemble indep2+indep3+decimal (vote)1,429,906 (99.9999 %)1150 / 151 (all cases incl. decimal)
mlp_indep41,429,889 (99.999 %)18136 / 151 (all cases incl. decimal)
ensemble indep2+indep3+indep4 (vote)1,429,907 (100 %)0151 / 151 (all 1,510,000 cases incl. decimal)
mlp_single1,429,898 (99.9994 %)9142 / 151 (all cases incl. decimal)
mlp_single21,429,906 (99.9999 %)1150 / 151 (all cases incl. decimal)
mlp_single3, one network1,429,907 (100 %)0151 / 151 (all 1,510,000 cases incl. decimal)

For mlp_indep the 35 failures are spread over 25 opcodes, almost all a single error in 10,000. The ensemble removes most of those scattered errors, but what is left is concentrated: 23 of its 31 failures are the compares CPX and CPY, where mlp_long and mlp_polish make the same mistake and outvote mlp_indep (§9). The grid below shows every opcode and how many of its cases the best network trained from scratch (mlp_indep4) gets wrong; the 100% network fills the whole grid.

Every official opcode, and how many ProcessorTests cases it fails A 16 by 16 grid of opcodes. 136 of the 151 official opcodes are right on every test case; the others show how many of their cases fail, 21 in total. Compares such as CPY and CPX fail most. x0 0x x1 1x x2 2x x3 3x x4 4x x5 5x x6 6x x7 7x x8 8x x9 9x xA Ax xB Bx xC Cx xD Dx xE Ex xF Fx $00 BRK imp: all 10000 cases right $01 ORA izx: all 10000 cases right $05 ORA zp: all 10000 cases right $06 ASL zp: all 10000 cases right $08 PHP imp: all 10000 cases right $09 ORA imm: all 10000 cases right $0A ASL acc: all 10000 cases right $0D ORA abs: all 10000 cases right $0E ASL abs: all 10000 cases right $10 BPL rel: all 10000 cases right $11 ORA izy: all 10000 cases right $15 ORA zpx: all 10000 cases right $16 ASL zpx: all 10000 cases right $18 CLC imp: all 10000 cases right $19 ORA aby: all 10000 cases right $1D ORA abx: all 10000 cases right $1E ASL abx: all 10000 cases right $20 JSR abs: all 10000 cases right $21 AND izx: all 10000 cases right $24 BIT zp: 1 of 10000 cases fail 1 $25 AND zp: all 10000 cases right $26 ROL zp: all 10000 cases right $28 PLP imp: all 10000 cases right $29 AND imm: all 10000 cases right $2A ROL acc: all 10000 cases right $2C BIT abs: all 10000 cases right $2D AND abs: all 10000 cases right $2E ROL abs: all 10000 cases right $30 BMI rel: all 10000 cases right $31 AND izy: all 10000 cases right $35 AND zpx: all 10000 cases right $36 ROL zpx: all 10000 cases right $38 SEC imp: all 10000 cases right $39 AND aby: all 10000 cases right $3D AND abx: all 10000 cases right $3E ROL abx: all 10000 cases right $40 RTI imp: all 10000 cases right $41 EOR izx: all 10000 cases right $45 EOR zp: all 10000 cases right $46 LSR zp: all 10000 cases right $48 PHA imp: all 10000 cases right $49 EOR imm: all 10000 cases right $4A LSR acc: all 10000 cases right $4C JMP abs: all 10000 cases right $4D EOR abs: all 10000 cases right $4E LSR abs: all 10000 cases right $50 BVC rel: all 10000 cases right $51 EOR izy: all 10000 cases right $55 EOR zpx: all 10000 cases right $56 LSR zpx: all 10000 cases right $58 CLI imp: all 10000 cases right $59 EOR aby: all 10000 cases right $5D EOR abx: all 10000 cases right $5E LSR abx: all 10000 cases right $60 RTS imp: all 10000 cases right $61 ADC izx: all 10000 cases right $65 ADC zp: all 10000 cases right $66 ROR zp: all 10000 cases right $68 PLA imp: all 10000 cases right $69 ADC imm: all 10000 cases right $6A ROR acc: all 10000 cases right $6C JMP ind: all 10000 cases right $6D ADC abs: all 10000 cases right $6E ROR abs: all 10000 cases right $70 BVS rel: all 10000 cases right $71 ADC izy: 1 of 10000 cases fail 1 $75 ADC zpx: all 10000 cases right $76 ROR zpx: all 10000 cases right $78 SEI imp: all 10000 cases right $79 ADC aby: all 10000 cases right $7D ADC abx: all 10000 cases right $7E ROR abx: all 10000 cases right $81 STA izx: 1 of 10000 cases fail 1 $84 STY zp: all 10000 cases right $85 STA zp: all 10000 cases right $86 STX zp: all 10000 cases right $88 DEY imp: all 10000 cases right $8A TXA imp: all 10000 cases right $8C STY abs: all 10000 cases right $8D STA abs: all 10000 cases right $8E STX abs: all 10000 cases right $90 BCC rel: all 10000 cases right $91 STA izy: 1 of 10000 cases fail 1 $94 STY zpx: all 10000 cases right $95 STA zpx: all 10000 cases right $96 STX zpy: all 10000 cases right $98 TYA imp: all 10000 cases right $99 STA aby: all 10000 cases right $9A TXS imp: all 10000 cases right $9D STA abx: all 10000 cases right $A0 LDY imm: all 10000 cases right $A1 LDA izx: all 10000 cases right $A2 LDX imm: all 10000 cases right $A4 LDY zp: all 10000 cases right $A5 LDA zp: all 10000 cases right $A6 LDX zp: all 10000 cases right $A8 TAY imp: all 10000 cases right $A9 LDA imm: all 10000 cases right $AA TAX imp: all 10000 cases right $AC LDY abs: all 10000 cases right $AD LDA abs: all 10000 cases right $AE LDX abs: all 10000 cases right $B0 BCS rel: all 10000 cases right $B1 LDA izy: all 10000 cases right $B4 LDY zpx: 1 of 10000 cases fail 1 $B5 LDA zpx: all 10000 cases right $B6 LDX zpy: all 10000 cases right $B8 CLV imp: all 10000 cases right $B9 LDA aby: all 10000 cases right $BA TSX imp: all 10000 cases right $BC LDY abx: all 10000 cases right $BD LDA abx: 1 of 10000 cases fail 1 $BE LDX aby: 1 of 10000 cases fail 1 $C0 CPY imm: all 10000 cases right $C1 CMP izx: all 10000 cases right $C4 CPY zp: 1 of 10000 cases fail 1 $C5 CMP zp: all 10000 cases right $C6 DEC zp: all 10000 cases right $C8 INY imp: all 10000 cases right $C9 CMP imm: all 10000 cases right $CA DEX imp: all 10000 cases right $CC CPY abs: 2 of 10000 cases fail 2 $CD CMP abs: all 10000 cases right $CE DEC abs: all 10000 cases right $D0 BNE rel: all 10000 cases right $D1 CMP izy: all 10000 cases right $D5 CMP zpx: all 10000 cases right $D6 DEC zpx: all 10000 cases right $D8 CLD imp: all 10000 cases right $D9 CMP aby: all 10000 cases right $DD CMP abx: 1 of 10000 cases fail 1 $DE DEC abx: all 10000 cases right $E0 CPX imm: 1 of 10000 cases fail 1 $E1 SBC izx: all 10000 cases right $E4 CPX zp: 1 of 10000 cases fail 1 $E5 SBC zp: all 10000 cases right $E6 INC zp: all 10000 cases right $E8 INX imp: all 10000 cases right $E9 SBC imm: 1 of 10000 cases fail 1 $EA NOP imp: all 10000 cases right $EC CPX abs: all 10000 cases right $ED SBC abs: all 10000 cases right $EE INC abs: all 10000 cases right $F0 BEQ rel: 5 of 10000 cases fail 5 $F1 SBC izy: 2 of 10000 cases fail 2 $F5 SBC zpx: all 10000 cases right $F6 INC zpx: all 10000 cases right $F8 SED imp: all 10000 cases right $F9 SBC aby: all 10000 cases right $FD SBC abx: all 10000 cases right $FE INC abx: all 10000 cases right
Every official opcode, for the best network trained from scratch (the 100% network, mlp_single3, would be all green). A number is how many of that opcode's ProcessorTests cases it gets wrong; a plain green cell fails none; a hollow cell is not an official opcode. Hover a cell for its name.
The second

ensemble, of three networks that share no training history, gets all but 3 cases right (§9): results/ens3_v2/per_opcode.md.

Whole programs, in lockstep

Six programs were written in 6502 assembly and assembled with the project's own assembler. Each one runs simultaneously on the reference and on the network. After every instruction all registers and all 64 KiB of memory are compared, and the first difference stops the run with a full report.

programinstructionsmlp_longmlp_polishmlp_indepensemble base+long+polishensemble long+polish+indep
sum 1..100 (16-bit)905passpasspasspasspass
first 25 Fibonacci numbers262passpasspasspasspass
8×8 multiply, 8 pairs via subroutine569passpasspasspasspass
bubble sort, 24 bytes4,212passpasspasspasspass
sieve of Eratosthenes to 2553,220passfail at 779passpasspass
fill 512 B, copy 300 B via (zp),Y5,370passpasspasspasspass

The final boss: Klaus Dormann's functional test

This is a test program written to break 6502 emulators. It exercises every instruction with every flag combination and jumps into an infinite loop at the first wrong result.

modelinstructions before first errorwhere
mlp_long40,634 (test case 5)CPY #$AA: Z flag wrong
mlp_polish6,734 (test case 1)DEX: one bit of PC wrong
mlp_indep48,774 (test case 32)EOR #$30: carry flag wrong
ensemble base+long+polish (vote)40,634CPY #$AA: two of three nets share the error
ensemble long+polish+indep (vote)300,000, no errorstopped at the run limit, in test case 41
ensemble indep+indep2+decimal (vote)none in 300,000 (run limit)2 h 0 min; a member outvoted on 789 of 1,083,260 micro-steps
mlp_indep355,460SBC abs,Y
ensemble indep+indep2+indep3 (vote)none in 300,000 (run limit)a member outvoted on only 6 of 1,083,260 micro-steps
ensemble indep2+indep3+decimal (vote)none in 300,000 (run limit), decimal referencea member outvoted on 787 of 1,083,260 micro-steps
mlp_indep480,818 (test case 41)SBC abs,Y
ensemble indep2+indep3+indep4 (vote)none in 300,000 (run limit), decimal reference3 h 4 min; a member outvoted on only 5 of 1,083,260 micro-steps
mlp_single2none in 300,000 (run limit), decimal referencethe first single network to get this far
mlp_single3none in 300,000 (run limit), decimal reference59 min, about 85 instructions per second; in the complete run: 11,819,741 (§9)
mlp_clear3none: the complete test, 30,646,177 instructions18.5 h, in 307 parallel segments (§9)

The 300,000-instruction ensemble run took 2 h 20 min (about 35 instructions per second, three networks per step); a complete run at that speed would take about nine days. The complete test is 30.6 million instructions with its decimal part (26.8 million without). It was run in full for single networks, cut into segments (§9). Along the way, in the first ensemble run, one of the three networks was outvoted on 561 of 1,083,260 micro-steps: each of those is an error a single network would have made.

At these error rates, roughly one error per several thousand instructions, how far a particular program gets is partly luck. mlp_polish has half the errors of mlp_long on ProcessorTests, yet fails Klaus much earlier, because one of its rarer errors happens to sit early in that program.

Does rounding the feedback matter?

We also ran the network without snapping, feeding its raw probabilities straight back in, so that small deviations could accumulate. The result: mlp_long ran all six programs correctly this way too. Its outputs sit so close to 0 and 1 that nothing drifts. Its errors are not slow analog creep; they are individual bits it gets wrong outright, and rounding cannot fix those.

Decimal mode: the 6502's other arithmetic

The 6502 has a decimal flag, D. When it is set, ADC and SBC do not add binary numbers but binary-coded decimal: each byte holds two decimal digits, so $19 + $01 = $20, not $1A. Games used it for scores, and calculators and clocks for counting. The NMOS 6502 also has quirks here: with invalid digits (like $1F) it produces specific "wrong" answers, and some flags follow the binary sum instead of the decimal one. ProcessorTests checks all of it.

The networks above treat D as an ordinary flag and always add in binary. That is why the 80,093 decimal ProcessorTests cases were left out of their scores. For the final network, mlp_decimal, we took mlp_indep and trained it 15,000 steps more (2 h 37 min) on data where the reference computes ADC and SBC in decimal whenever D is set. Nothing else changed: same network size, same harness, which still only serves memory.

mlp_indep (binary only)mlp_decimal
ProcessorTests, all 1,510,000 cases incl. decimal–1,509,930 exact (99.995 %)
decimal ADC/SBC cases (D = 1)not trained80,060 / 80,093 (99.96 %)
binary ADC/SBC cases (D = 0)79,904 / 79,90779,897 / 79,907
opcodes with every case exact126 / 151121 / 151
six programs6 / 66 / 6
new BCD program (972 instructions)fail at instruction 102pass bit-exact
Klaus: instructions before first error48,77443,284 (test case 20, EOR #$C3)

The BCD program (programs/bcd.asm) computes the first 30 Fibonacci numbers as six-digit decimal numbers, then counts down from 9999 in steps of 137 with decimal subtraction. The binary-only network derails at the first decimal carry. The decimal network runs it bit-exactly.

The price is small. Decimal arithmetic is now the weakest part (33 errors in 80,093), and the network as a whole has 70 errors instead of 35, spread over 30 opcodes, still about one in 20,000. It fails Klaus at a different place than mlp_indep. Klaus's own decimal test only starts after about 26 million instructions, far beyond what any single network has reached so far.

Phase 5 extras: a screen, and a file you can take anywhere

A text screen at $0400

Many 6502 machines showed text by reserving a block of memory for the screen: write the byte $41 to the right address and an A appears. We gave the neural CPU the same: 40 columns × 25 rows at addresses $0400–$07E7. The harness displays those 1,000 bytes as text. That is all it does. It reads memory, as a video chip would, and computes nothing.

The demo program (programs/screen.asm) prints a title and a table of Fibonacci numbers. The network does all of the work: it adds in decimal mode, splits each byte into its two digits, turns them into the characters '0'…'9', blanks leading zeros and walks a pointer down the screen. After 6,335 instructions the screen of mlp_decimal looks like this, byte-for-byte identical to the reference CPU's:

+----------------------------------------+
|NEURAL 6502  -  FIBONACCI IN DECIMAL    |
|----------------------------------------|
|F( 0) =      0                          |
|F( 1) =      1                          |
|F( 2) =      1                          |
|F( 3) =      2                          |
|F( 4) =      3                          |
|F( 5) =      5                          |
|F( 6) =      8                          |
|F( 7) =     13                          |
|F( 8) =     21                          |
|F( 9) =     34                          |
|F(10) =     55                          |
|F(11) =     89                          |
|F(12) =    144                          |
|F(13) =    233                          |
|F(14) =    377                          |
|F(15) =    610                          |
|F(16) =    987                          |
|F(17) =   1597                          |
|F(18) =   2584                          |
|F(19) =   4181                          |
|F(20) =   6765                          |
|F(21) =  10946                          |
|F(22) =  17711                          |
+----------------------------------------+

Run the same program on mlp_indep, which never learned decimal mode, and you get the screen below. That is not the network failing: a real 6502 with the decimal flag ignored produces exactly this, because a binary add of $08 + $05 gives $0D, and $30 + $0D is the character =. The harness confirms it matches the binary reference.

+----------------------------------------+
|NEURAL 6502  -  FIBONACCI IN DECIMAL    |
|----------------------------------------|
|F( 0) =      0                          |
|F( 1) =      1                          |
|F( 2) =      1                          |
|F( 3) =      2                          |
|F( 4) =      3                          |
|F( 5) =      5                          |
|F( 6) =      8                          |
|F( 7) =      =                          |
|F( 8) =     15                          |
|F( 9) =     22                          |
|F( :) =     37                          |
|F( ;) =     59                          |
|F( <) =     90                          |
…

ONNX: the CPU as one portable file

PyTorch is only needed for training. For running, the network is exported to ONNX, an open file format for neural networks that runtimes in many languages and in web browsers can execute. The file describes exactly one micro-step: 100 input bits in, 119 output bits out. Its metadata says which bit is which and what the memory loop around it must do. The CPU in a file:

filesizechecked against PyTorchprograms via ONNX
mlp_decimal.onnx6.8 MB0 different bits in 255,266 micro-steps7 / 7 bit-exact, screen identical
ens3_vote.onnx (3 networks + vote in one graph)20.3 MB0 different bits6 / 6 bit-exact

Through onnxruntime the network runs about twice as fast as through PyTorch on the same laptop. A browser can load the same file with onnxruntime-web, and then a web page can run the neural 6502 on the visitor's own computer.


8. Debugging a neural CPU

The most interesting part of the project was finding out why the network failed where it did. Each time, the cause was not the network but the data it had been shown.

Bug 1: JSR fails, but only in the test suite. The network was 100% on JSR in its own held-out tests, yet failed 38 of 10,000 ProcessorTests cases. It mis-decremented the stack pointer or wrote the wrong return address. Tracing one case step by step showed the difference: the harness starts every test with its internal latches at zero, while training filled them with random leftovers. A random byte is zero only 1 time in 256, so four zero latches at once essentially never appeared in training. Fix: a quarter of training examples now start with zeroed latches, and half see the harness's exact "nothing was read" value.

Bug 2: comparing equal numbers. Klaus failed on CPY #$AA with Y = $AA. The answer is "equal", so Z = 1, but the network said "not equal". With random memory, the byte being compared equals the register only 1 time in 256. So the network had barely ever seen the most important case of a compare. This also explained why CPX and CPY were the worst opcodes in every run. Fix: fresh memory bytes now copy a register value 15% of the time.

Bug 3: the fix overcorrects. After bug 2's fix, mlp_polish failed the sieve on ADC $10 with A = 2 and memory = 2, setting Z as if the result were zero. Having now seen many "equal operands → Z = 1" compare examples, it had partly carried that rule over to addition, where it is wrong. It is a neat illustration of a network learning a shortcut from its data.


9. Why several networks? Error correction by voting

The problem a single network could not solve (for a long time)

For most of the project our best single networks got roughly one instruction in ten thousand wrong. That sounds excellent, but a program runs tens of thousands of instructions, and the first mistake usually ruins everything after it. Training longer helps, but each further error costs hours to remove. Then a test program shows a new one. (In the end a single network did get there, with the help of the voters; see the last part of this section.)

The idea: let several networks check each other

Ask three people to add up the same long column of numbers, and take the answer at least two of them agree on. A slip by one person is outvoted by the other two. The method fails only if two people make the same slip at the same time, which is much rarer than one person slipping.

We do the same with networks. Three networks get the same input every micro-step, and every output bit is decided separately:

               ┌─► network 1 ─► 0 1 1 0 1 …  ┐
  same input ──┼─► network 2 ─► 0 1 0 0 1 …  ├─► per bit, majority wins ─► 0 1 1 0 1 …
               └─► network 3 ─► 0 1 1 0 1 …  ┘           (bit 3: 2 against 1)

There are two ways to combine them:

The combination never looks at what a bit means. It doesn't know which bit is a flag and which is an address. So the project's rule still holds: all CPU logic is inside the networks, and nothing outside them computes anything a CPU does.

Why it can work: the networks know when they are unsure

A network outputs a probability for every bit, not just 0 or 1. On 193,000 test micro-steps, mlp_long got 8 bits wrong. For 7 of those 8 it was unsure: its probability lay between 0.1 and 0.9, instead of near 0 or 1. Only 1 in 10,000 correct steps was that uncertain. A network that is wrong is usually also hesitant, and a hesitant network is easily outvoted.

Why it can fail: networks with the same upbringing make the same mistakes

Voting only helps if the networks make different mistakes. Our first ensemble showed this the hard way.

ensemblesix programsKlauswhat happened
mlp_long + mlp_polish (mean)5 / 6–at the sieve's critical bit they said 0.31 and 0.72; the average (0.516) landed on the wrong side
mlp_base + mlp_long + mlp_polish (vote)6 / 640,634at CPY #$AA, mlp_polish was right (0.995), but mlp_long (0.08) and mlp_base (0.12) were both wrong and outvoted it

mlp_long is mlp_base trained longer (§6), so they share blind spots. Two votes from the same family are worth little more than one.

The fix: a network with a different upbringing

That is why mlp_indep was trained: a new network from scratch, with different random weights, a different activation function and the improved data. On its own it is already the strongest network:

mlp_longmlp_polishmlp_indep
six programs6 / 65 / 66 / 6
Klaus: instructions before first error40,634 (test case 5)6,734 (test case 1)48,774 (test case 32)
its Klaus errorCPY #$AA, Z flagDEX, PC bitEOR #$30, carry flag

The three networks fail Klaus at three different places with three different errors. That is what an ensemble needs: whenever one of them goes wrong, the other two are likely to be right.

The result

best single network (mlp_indep)ensemble mlp_long + mlp_polish + mlp_indepensemble mlp_indep + mlp_indep2 + mlp_decimal
ProcessorTests failures (of 1,429,907)35313
opcodes with every case exact126 / 151138 / 151148 / 151
six programs6 / 66 / 66 / 6 (and bcd + screen in decimal mode)
Klaus48,774 instructions, then an error300,000 instructions, no error (run limit)300,000 instructions, no error (run limit)
micro-steps where one network was outvoted, during Klaus–561 of 1,083,260789 of 1,083,260

On a long program the ensemble is clearly better: it got more than six times further through Klaus than any single network, and is still going. Every one of those 561 outvoted micro-steps was a mistake that would have derailed a single network.

On ProcessorTests the gain is smaller than you might hope: 31 failures against 35. The reason is the same lesson as before. Two of the three members are from the same lineage. On the compares CPX and CPY they share a blind spot, and together they outvote mlp_indep, which had those cases right. 23 of the ensemble's 31 failures are such compares. The next step would be a third member that is also independent, so that no two members share an upbringing.

The second ensemble: three outsiders

So we trained that member. First we looked at exactly which cases were still wrong. The pattern was clear. Almost every branch error was a jump across a page boundary where the carry ripples through many bits of the address ($BF → $C0, $7F → $80). Compares went wrong on the sign bit when the result was close to $80. Uniform random data almost never produces such values, so we added targeted data: bytes with long runs of ones or zeros at the end, and memory values just next to a register value.

The new network, mlp_indep2, starts from scratch with a different seed and activation function and gets decimal mode from the first step. On its own it is not better: 46 failures against 35. The long-carry branch errors are gone, but it makes new mistakes elsewhere (compares whose result is $68–$7F). But that is exactly what voting needs. Its mistakes are in different places from those of mlp_indep and mlp_decimal, and when three networks rarely make the same mistake, the majority is almost always right:

ProcessorTests failures (binary-scored)
mlp_indep35
mlp_indep246
mlp_decimal37
vote of the three3

Three failures in 1,429,907 cases: one wrong zero flag on an ADC, one wrong sign flag on a CPY, one wrong address bit on a branch across a page. Counting the decimal cases as well, the ensemble gets 1,509,982 of 1,510,000 right.

The third ensemble: no shared history at all, and 100%

That ensemble still contained mlp_decimal, which is mlp_indep trained a bit further, so two of its three members were relatives. We trained one more outsider, mlp_indep3: again from scratch, again a different seed and activation function, and with the targeted data widened so that compare results anywhere from $70 to $90 are common. It became the best single network so far (22 failures), and, as before, its remaining mistakes were mostly new ones: indexed loads across a page boundary that came back as zero, and scattered compare flags.

Now three networks shared no training history at all, and the vote did the rest:

ProcessorTests (binary-scored, 1,429,907 cases)failuresopcodes with every case exact
mlp_indep35126 / 151
mlp_indep246124 / 151
mlp_indep322130 / 151
vote of the three0151 / 151

Every single case right. This is the Phase 3 target: 100% on every opcode and every ProcessorTests case. It is reached by the ensemble, not by one network, and the vote is still bit-blind, so all CPU logic stays inside the three networks. On Klaus's test the same three ran 300,000 instructions without an error, and in all of those 1,083,260 micro-steps a member had to be outvoted only 6 times.

With decimal mode counted too, the best team is the three networks that know it: mlp_indep2 + mlp_indep3 + mlp_decimal get 1,509,998 of all 1,510,000 cases right. The 2 that remain are one and the same sum, $20 + $E0, which is exactly 256: the result byte is $00, so the zero flag must be set. In decimal mode the 6502 still takes that flag from the binary sum, while A receives the decimal result $60. Two of the three networks miss it. Our targeted data made subtractions land near zero but never made additions land near 256, so we trained a fourth outsider, mlp_indep4, with exactly those sums.

The fourth outsider: decimal mode too, and every case right

mlp_indep4 is trained like mlp_indep3, with another seed and the GELU activation, plus one change to the data: a third of the "near" operands are now close to minus the accumulator, so that A + M lands near 256. It gets both $20 + $E0 cases right, and it is the best single network of the project: 18 binary-scored failures, 21 on all 1,510,000 cases (3 of them decimal), 136 opcodes perfect, all seven programs bit-exact, and 80,818 instructions of Klaus's test before its first mistake.

The vote of the three newest outsiders, all trained from scratch with decimal mode:

ProcessorTests, all 1,510,000 cases incl. decimalfailuresopcodes with every case exact
mlp_indep251124 / 151
mlp_indep330130 / 151
mlp_indep421136 / 151
vote of the three0151 / 151

Every case right, decimal mode included, and also every one of the 1.29 million held-out micro-steps. Over the whole test suite (7.7 million micro-steps) a member had to be outvoted on only 141 of them. The trio also runs all seven programs and the screen demo bit-exactly. On Klaus's test it ran 300,000 instructions without an error, and a member had to be outvoted on only 5 of the 1,083,260 micro-steps.

Back to one network: the voters as a searchlight

A vote of three is a fine way to reach 100%, but it is three times the work per cycle, and the question remained whether one network can do it. mlp_indep4 was already almost perfect on its own training data: at the end of its training it got 150 of 151 instructions right on every held-out example. Its 21 remaining ProcessorTests failures were not something it was unable to learn; they were inputs it had hardly ever seen.

Those inputs are rare, about one instruction in 60,000, so simply hunting for mistakes yields too few to learn from. Two signals help. First, a network that is right can still be close to wrong: if one of its 119 output bits comes out at 0.45 or 0.55 instead of near 0 or 1, that input sits near an edge, and the mistake is just around the corner. Second, the other networks make mistakes in other places; where they slip, the inputs are unusual too.

So a search program generated millions of instructions with our own random generator, started each one exactly like the real harness, and kept every micro-step where the network was wrong, close to wrong, or where one of the other networks was wrong. The right answers always come from the reference. ProcessorTests is not used for this at all. The network was then trained a little further, with these hard examples mixed into every batch. Then the search ran again on the improved network, and so on:

roundsearchedreal mistakes found"close calls" keptafter training on themProcessorTests failures
13 million instructions, mlp_indep448107,352mlp_single21 → 11
23 million, mlp_single1923,743mlp_single211 → 1
34 million, mlp_single215,016mlp_single31 → 0

mlp_single3 gets every one of the 1,510,000 cases right on its own, decimal mode included: 151 / 151 instructions, every held-out micro-step, all seven programs and the screen demo. It is the same size as all the others, 1.69 million parameters. On Klaus's test it ran 300,000 instructions without an error, without any vote to fall back on, three times as fast as the trio.

One honest caveat. The search never looked at ProcessorTests, but we did score each round's network on it once, to decide whether another round was needed. So the test suite decided when we stopped, not what the network was trained on. The single failure left after round 2, a branch that lost one bit of its target address, was not turned into training data. The search of round 3 found a mistake of exactly that kind by itself.

The complete Klaus run: 100% on ProcessorTests is not the end

With a single network right on all 1.51 million ProcessorTests, the last open target was the complete Klaus test. One process would need four to five days for it. So the test was cut into 307 pieces of 100,000 instructions. The reference emulator runs the test once and saves a snapshot of the whole machine at the start of every piece: registers, internal state and all 64 KB of memory. Then each piece is given to the network separately, several at a time. The network has to run its piece without help, match the reference after every single instruction, and end exactly on the next snapshot. Because each snapshot is exactly where an error-free network would have been, 307 passed pieces add up to one uninterrupted run.

mlp_single3 passed 305 of the 307 pieces. Both failures were in Klaus's long loops that add and subtract every pair of numbers: an SBC $0105,Y at instruction 11,819,741 that gave A = $00 instead of $40, and a decimal-mode SBC #$07 at instruction 27,071,345 with a wrong Z flag. A network that never misses a ProcessorTests case still missed these, for two reasons.

Leftovers. Besides A, X, Y, P and the stack pointer, the network keeps four internal scratch bytes (the latches: the current opcode, an address being built and one temporary byte). At the end of an instruction they still hold whatever that instruction left in them. Every ProcessorTests case, and every training example that copies how a test starts, begins with them at zero. In a running program they almost never are. The SBC $0105,Y went wrong only because the temporary byte still held $FE; with zero there the same step was right. Training on random leftovers fixed that one case (mlp_single4), but the next network showed the weakness elsewhere. The real fix was a small change of protocol: at the end of every instruction the network itself now clears its four scratch bytes. A program cannot see them, so to a program nothing changes; a test checks that every program and Klaus behave identically. The memory around the network still only reads and writes. Every instruction now starts the way a ProcessorTests case starts.

Pockets. The remaining errors sat at one combination of register value and operand in one situation: about one in 100,000 pairs. ProcessorTests tries 10,000 random cases per instruction, so it almost never lands in such a pocket; Klaus tries all 65,536 pairs, so it does. We built the same kind of test ourselves: for each of the 56 arithmetic and compare instructions, take a few random situations and try every register value × every operand × every carry/decimal setting, 262,144 cases each, all checked against the reference. The cases the network got wrong or almost wrong became training data. The same sweep with a different random seed, so in situations never trained on, served as the exam: 29.4 million cases.

The search for hard cases also got smarter. Around every close call it now tries small variations of the start of that instruction (other register values, another address, other bytes in memory) and lets the reference run the whole instruction again. An early version varied a single step in the middle of an instruction instead; that produced tens of thousands of "errors" in situations no real program can ever reach, and was thrown away.

roundsearched withinstructionsnet afterProcessorTests failuresexam sweep wrong (of 29.4M)
4mlp_single3, leftover latches, local search1.5 millionmlp_single40 → 0–
5mlp_single4, same1.5 millionmlp_clear (clears its latches)0 → 387
6mlp_clear, local search + sweep of 58.7M cases1 millionmlp_clear23 → 10
7mlp_clear2, same (the sweep now found 2 wrong cases)1 millionmlp_clear31 → 00

mlp_clear3 passed all 307 pieces: the complete Klaus test, 30,646,177 instructions, including the decimal part, without a single error. It took 18.5 hours on the laptop, six pieces at a time, through the 6.8 MB ONNX file. The same network gets all 1,510,000 ProcessorTests right, makes no error in the 29.4-million-case exam sweep and runs all seven programs bit-exactly. It is still the same size: 1.69 million parameters.

Honest caveats. Neither ProcessorTests nor Klaus was ever used as training data; every answer the network learned comes from the reference. But Klaus was used to diagnose: the two failing pieces were studied, which is how the leftovers and the pockets were found, and one kind of generated operand (a register with one or two bits flipped) was inspired by the SBC failure. Each candidate was tried on those two pieces before a complete run, and ProcessorTests was scored once per round to decide whether to go on. The last ProcessorTests failure before the final network (a branch, BNE) was not turned into data. The two pieces that once failed are 2 of 307; the other 305 were never looked at before the final run.


10. A neural CPU vs. the real silicon

How would this network compare as hardware? Order-of-magnitude estimates:

MOS 6502 (1975)this network
logic~3,510 transistors1.69 M weights, ~1.7 M multiply-adds per micro-step
as a dedicated chipalready isstoring the weights alone: ~80–325 M transistors; fully parallel multipliers: billions
size ratio1×~10⁵ – 10⁶× larger
delay per cyclea few dozen gate delays5 layers of multiply-and-sum: ~150–300 gate delays
exact?by constructionon every test run (1.51M ProcessorTests, the complete Klaus test); not proven for every input
speed today1–2 MHz in 1975a few thousand micro-steps/s on a laptop CPU

The 6502 is a minimal circuit. Its instruction decoder is a 130-line logic table, one 8-bit ALU is reused for everything, and every transistor was placed by hand. The network is a generic dense function. Every input bit connects to every neuron, it effectively computes all 151 instructions at once every cycle and keeps one answer, and it stores 1-bit facts as 32-bit numbers.

What the network shows is not efficiency but learnability. Nobody told it what an addressing mode, a carry or a stack is. It found all of that from examples. Push the network far enough (prune it, binarise it, turn it into gates) and it would shrink towards a logic circuit. In the limit that circuit would look like the one the 6502's designers drew by hand in 1975.


11. What didn't work, and what we learned

Reached: 100% on every opcode and every ProcessorTests case, first by a vote of three independently trained networks, and then by a single network, mlp_single3, on all 1,510,000 cases including decimal mode. Also reached: a complete, error-free run of Klaus's functional test, all 30,646,177 instructions including the decimal part, by the single network mlp_clear3.

Deliberately not done: the 6510. The Commodore 64 uses the 6510, a 6502 with a small built-in I/O port at addresses $0000 and $0001 that switches parts of memory between RAM, ROM and I/O chips. Its instructions are the same as the 6502's, so the network can already run 6510 code. The port itself is about how memory is wired, not about what the CPU computes, and this project keeps the memory around the network as simple as possible on purpose. So we do not plan to emulate the 6510.


12. Try it yourself

Everything is on GitHub (MIT licence) and in the downloads on the project page: the reference emulator, the oracle, the training code, the assembler, all configs and all result files.

python -m neural6502.ref.download            # fetches the test suites (not included in the download)
python -m neural6502.eval.lockstep --ckpt runs/mlp_long/final.pt --program sieve
python -m neural6502.eval.lockstep --ckpt runs/mlp_decimal/final.pt --program bcd   # decimal mode
python -m neural6502.eval.screen --ckpt runs/mlp_decimal/final.pt --live         # watch the screen
python -m neural6502.neural.onnx_export --ckpt runs/mlp_decimal/final.pt --out export/mlp_decimal.onnx
python -m neural6502.eval.lockstep --ckpt runs/mlp_long/final.pt --klaus
python -m neural6502.eval.lockstep --ckpt runs/mlp_long/final.pt --ckpt runs/mlp_polish/final.pt \
    --ckpt runs/mlp_indep/final.pt --klaus --max-instr 300000   # the voting ensemble
python -m neural6502.eval.accuracy --ckpt runs/mlp_clear3/final.pt --out results/mine    # the final single network
python -m neural6502.eval.klaus_full run --ckpt export/mlp_clear3.onnx \
    --boundaries data_cache/klaus_boundaries_clear --out results/klaus_mine --workers 6   # the complete Klaus run

The README in the software package has the full list of commands.


Glossary

termmeaning
micro-stepone network evaluation, roughly one 6502 clock cycle, with at most one memory access
closed loopthe network's output is fed back as its next input; no help from the reference
lockstepreference and network run the same program side by side, compared after every instruction
snappingrounding every output to exactly 0 or 1 before feeding it back
exact matchevery one of the 119 output bits right
opcodeone of the 151 official instruction encodings, e.g. $A9 = LDA #imm
held-out setrandomly generated test examples the network never trained on
ProcessorTestsTom Harte's 1.5 M single-instruction 6502 test cases
Klaus Dormann's testthe standard 6502 functional test program
BCD / decimal modethe 6502's second way of adding: with the D flag set, each byte holds two decimal digits ($19 + $01 = $20)
ONNXan open file format for trained networks; runtimes exist for many languages and for web browsers
memory-mapped screena block of ordinary memory whose bytes a display shows as characters
ensembleseveral networks run together on the same input; every output bit is decided by majority vote (or averaged probability)
lineagea chain of networks where each continues the previous one's training (mlp_base → mlp_long → mlp_polish)
independent networka network trained from scratch with different random weights, so its mistakes are unrelated to another's
warm startcontinuing training from an earlier network's weights

← back to the project summary