interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / docs / adtrain / CONTRACT.md

163 lines · 8322 bytes Raw Blame History Rendered
1# adtrain — native autodiff training example
2
3Status: IMPLEMENTED and EXERCISED on the host (aarch64 Linux, DGX Spark) for
4gates 1–4 and the host arm of gate 5, plus the exact-rational gradient oracle
5(Wolfram). The GB10 arm of gate 5 is EXERCISED once on the GB10 (one fixture,
675/75 exact). Nothing here is QUALIFIED, MERGED or DEPLOYED. Tracks aien-train
7#6 (trainer, optimizer, checkpoint) on top of
8omega-mv #664 (native tape).
9
10## What it is
11
12`native/adtrain/mlp.om` is handwritten seeded `.om` with native `f32` words. It
13trains a relu MLP by full-batch gradient descent. Gradients come from the
14native reverse-mode tape `native/autodiff664/tape.om` (omega-mv); this
15repository contains no hand-derived derivative. Build order: omega-mv
16`native/ecosystem663/metadata.om`, omega-mv `native/autodiff664/tape.om`,
17`native/adtrain/mlp.om`, then the caller (`tests/adtrain/main.om`). Pins:
18`dependencies.json`.
19
20- Data and model: `X[8,4]`, `T[8,2]`, `W1[4,8]`, `b1[1,8]`, `W2[8,2]`, `b2[1,2]`.
21- Graph (tape nodes 0–16, checked at every build):
22 `X W1 b1 W2 b2 T MM1 BC1 ADD1 RELU MM2 BC2 ADD2 SUB MUL SUM1 SUM0`, that is
23 `H = relu(X·W1 + b1)`, `Y = H·W2 + b2`, `loss = Σ (Y − T)²`.
24- Initialisation: one xorshift64 stream (seed 17; mode Z uses 29) gives
25 `k = (next mod 17) − 8`. `X` and `T` are `k/8`, then `W1` and `W2` are `k/16`.
26 Biases are 0. Every value is a dyadic rational, exact in binary32.
27- Training: `lr = 1/64` (computed as `div 1.0f32 64.0f32`), 200 steps,
28 `p = p − round(lr·g)`. The loss and all 58 parameters must stay finite
29 (`affinite` bit test, ecosystem6), else exit 86.
30
31## Gates and how each is proven
32
33`OMC=<pinned omc> OMEGA=<omega-mv checkout> OUT=<scratch> sh tests/adtrain/run-adtrain.sh`
34ends `ADTRAIN_SUITE_PASS`. The suite materialises the dependencies from their
35pinned Git objects and checks every SHA-256 first.
36
37| gate | mode | check |
38|---|---|---|
39| 1 forward + loss | T | 201 `L <step> <loss bits>` rows from the tape forward |
40| 2 gradients vs independent reference | G | tape gradient against a central difference per parameter, ε = 1/64 (rule below); ≥ 50 checked, none failing |
41| 2 (second reference) | D + host arm | C M21 tape on the same inputs, value-exact |
42| 3 updates reduce loss | T | `loss[200] < loss[0]` and `loss[200] < loss[100]`, in the program (exit 88) and again on the printed bits by the runner |
43| 4 checkpoint/resume | S, R | train to 120, save, fresh process loads and continues to 200; `L 120..200` and all `P` rows `cmp`-identical to the uninterrupted T run |
44| 5 CPU/GPU agreement | D | fixture replayed by omega-mv `tests/test_omega_ad_fixture.c`: host arm (M20 CPU table) PASS; GB10 arm `tests/run_ad_chip.sh` PASS 75/75 `max_ulp=0` on the GB10, sign-flip control FAIL (`evidence/ADTRAIN/gb10/`) |
45| golden receipts | T, S, G | SHA-256 of `run/T.stdout`, the step-120 checkpoint and `run/G.stdout` equal `docs/adtrain/golden.json` (PR #42's `evidence/ADTRAIN` receipts); fails as `golden-T-stdout`, `golden-ck120` or `golden-G-stdout` |
46
47Gates 1–4 are self-consistency checks: a trainer that is wrong but consistent
48with itself (a parameter never updated, another learning rate in the update
49only, a different data hash) passes them. The golden gates bind the run to
50the recorded trajectory, checkpoint and gradient rows of the pinned build, so
51such a trainer fails. Any intended change to the trainer, data or compiler pin
52needs new receipts and a new `golden.json` in the same change. The negative
53controls of these gates (one hex digit changed, entry missing or duplicated,
54another gradient-check step) are `tests/adtrain/replay/mutants-golden.txt`, run by
55`tests/adtrain/replay/run-replay.sh` (`evidence/ADTRAIN-GOLDEN-20261107/`).
56
57Central-difference rule (si19 `qfdone`, extended for small gradients):
58`d = (f(p+ε) − f(p−ε))·32`, with ε = 1/64 from `dgeps` in `tests/adtrain/main.om`,
59its own constant: it equals the learning rate but does not follow it, so a change
60of `mllr` is caught by the golden gates and not through the finite-difference step.
61The check passes iff `|g| ≥ 1/64` and
62`16·|d − g| ≤ |g|`, or `|g| < 1/64` and `|d − g| ≤ 1/64`. A parameter is
63skipped when either perturbation changes the relu pattern. Observed: 58
64checked, 0 skipped, 0 failed.
65
66Declared tolerances for gate 5: PASS is 0 ULP on all 75 values (Y, loss,
67dW1, db1, dW2, db2). PASS_TOL allows at most 2 ULP. Anything else is FAIL.
68Observed on the host: `exact=75/75 max_ulp=0 verdict=PASS`. The
69`--mutant-sign` control (expected dW1 negated) FAILs as required.
70
71## Checkpoint `adtrain.ck`
72
73The image is 536 bytes of u64 little-endian words:
74
75| word | content |
76|---|---|
77| 0 | magic: the bytes of the text `ADCKPT01` |
78| 1 | version 1 |
79| 2 | step |
80| 3 | 58 |
81| 4 | lr bits |
82| 5 | loss bits |
83| 6 | data hash (FNV-1a 64 over the X and T bit patterns) |
84| 7 | 0 |
85| 8–65 | the 58 parameters (f32 bits, zero-extended) |
86| 66 | FNV-1a 64 over bytes 0..527 |
87
88Saving uses `fopen` (create/truncate, 0600), a full `write`, `fsync` and
89`fclose`. The load (mode R) refuses, leaving every parameter unchanged, in
90these cases:
91
92- exit 65: size ≠ 536, checksum, magic, version, count, step > 200, lr,
93 non-zero padding, or a non-finite parameter.
94- exit 66: the image was trained on other data (data hash ≠ current X, T).
95
96There is no `rename` host word, so atomic publication is not claimed; the
97checksum rejects a torn image. The suite exercises each refusal path:
98
99| image | exit |
100|---|---|
101| seed-29 image | 66 |
102| truncated to 535 bytes | 65 |
103| byte 96 flipped (parameter mantissa, checksum only) | 65 |
104| byte 100 flipped (zero-extension padding) | 65 |
105
106A plain byte flip only ever reaches the checksum, so the two flip cases above both
107exercise the checksum check. `tests/adtrain/replay/run-replay.sh` (DRA-14 replay,
108`evidence/ADTRAIN-REPLAY-20261107/`) forges re-checksummed images (`replay/ckforge.om`)
109that reach each structural check on its own, and removes one check at a time to show
110that each carries its refusal.
111
112## Exit codes
113
114| code | meaning |
115|---|---|
116| 1 | gradient check failed |
117| 65 | corrupt checkpoint |
118| 66 | data binding mismatch |
119| 74 | file I/O |
120| 86 | non-finite loss or parameter |
121| 87 | tape refusal or unexpected node id |
122| 88 | loss not reduced |
123| 90 | bad mode byte |
124
125## Compiled mutants (`tests/adtrain/mutate.om`)
126
127| mode | fault | observed |
128|---|---|---|
129| 0 | update direction reversed | T exits 86 |
130| 1 | data-hash check removed | the seed-29 image then loads (exit 0) |
131| 2 | checksum check removed | the byte-96 image then loads (exit 0) |
132
133Each mutant compiles with rc 0. Modes 1 and 2 show that the two checks carry
134the refusals; without them the load is wrongly accepted.
135
136## Exact-rational gradient oracle (gate 2, third reference)
137
138`tests/adtrain/gradient.wl` regenerates the seed-17 data with the same
139xorshift64, binds to the `K <i> <k>` rows of mode D, fixes the relu pattern
140(`x > 0`) from the exact forward, differentiates the exact loss symbolically
141and compares every `G` row against `|g − g_exact| ≤ 2^-16·max(1, |g_exact|)`.
142It ran on the hosted Wolfram service (`WolframLanguageEvaluator`). Observed:
143the K rows match, 58/58 gradients equal the exact values, and the step-0 loss
144equals `4155649/524288` exactly. A copy with one gradient's sign bit flipped
145reports `allWithin False`. The exactness comes from the small dyadic data:
146every binary32 operation of this step is exact. No pre-activation is exactly 0,
147so this oracle does not exercise the relu rule at 0; `tests/autodiff664`
148does. Evidence: `evidence/ADTRAIN/oracle.json`, `evidence/ADTRAIN/oracle/`.
149
150## GB10 arm (gate 5)
151
152Ran once on 2026-10-29 at 17:07Z, in a window Drake authorised. The slot came
153from CodexStackCompare on `~/handoffs/BOARD.md`. Run conditions:
154`GB10_CHIP_RUN=1` and `/tmp/aien-gb10.lock`, omega-mv `965fb762`, physics
155`6d7cf0d4`. Result: `AD_FIXTURE_CHIP: exact=75/75 max_ulp=0 verdict=PASS`; the
156sign-flip control fails. The native tape runs on the host; the GB10 replays the
157same step through the C M21 tape over the M20 GB10 realization. Receipt and
158limits: `evidence/ADTRAIN/gb10/README.md`.
159
160## Not claimed
161
162General training, GPU launch from `.om` (omega-mv #638 / CUDApp #35),
163performance, atomic checkpoint publication, or hardware qualification.