Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/native/autodiff664/CONTRACT.md # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / native / autodiff664 / CONTRACT.md` 140 lines · 8103 bytes Raw Blame History Rendered 1 # Native reverse-mode tape (bounded): `native/autodiff664/tape.om` 2 3 Status: IMPLEMENTED and EXERCISED on the host (aarch64 Linux, DGX Spark). Not 4 QUALIFIED on hardware, not MERGED, not DEPLOYED. Tracks omega-mv #664 (native 5 autograd) and builds on #663 / PR #674 (`native/ecosystem663/metadata.om`). 6 7 ## What it is 8 9 A handwritten seeded `.om` reverse-mode tape for rank-2 IEEE binary32 tensors. 10 Values and gradients use native `f32` words. It contains no FFI, no C fallback 11 and no generated code. Build order: 12 `native/ecosystem663/metadata.om`, `native/autodiff664/tape.om`, then the consumer. 13 14 | word | meaning | 15 |---|---| 16 | `tpreset` | empty tape (node count, backward flag, arena offset to 0) | 17 | `tpleaf r c rg` → id | leaf `[r,c]`; `rg` 1 requires grad | 18 | `tpset n i v` → 0 | write leaf/node value element `i` | 19 | `tpadd a b`, `tpsub a b`, `tpmul a b` → id | elementwise, equal shapes | 20 | `tpmm a b` → id | `[m,k]·[k,n]` | 21 | `tprelu a` → id | `x > 0 ? x : +0` | 22 | `tpbcast a rows` → id | `[1,c]` → `[rows,c]` | 23 | `tpsum a axis` → id | axis 0 → `[1,c]`, axis 1 → `[r,1]` (keepdims) | 24 | `tpback root` → 0 | reverse pass, seed 1.0, once per tape | 25 | `tpval n i`, `tpgrad n i`, `tphasg n` | read value / gradient / whether a gradient exists | 26 27 ## Admission and limits 28 29 Each recorded node has an M20 metadata-v1 descriptor (`TD`) and an allocator 30 snapshot (`TS`). Every operand passes `emcheck` from `metadata.om` before an op 31 runs, so a stale or non-live operand is refused with the metadata error. 32 The `tests/autodiff664` `tstale` check exercises this path. 33 34 | code | condition | 35 |---|---| 36 | −30 | capacity: 33rd node, >64 elements, reduced axis >32, arena full | 37 | −31 | `tpback` already run or failed, or any op after `tpback` | 38 | −32 | bad id, shape mismatch, bad layout, bad axis | 39 | −33 | `tpback` root not `[1,1]` or not requiring grad | 40 | −1..−8 | passed through from `emcheck` | 41 | exit 97 | `tpval`/`tpgrad` out of range or on a node without a gradient | 42 43 A refusal records nothing (the node count is unchanged). 44 45 ## Numeric order (the contract the fixture oracle checks) 46 47 - **Reductions** use one E1 tile: copy the n ≤ 32 inputs, pad lanes n..31 with 48 −0.0, then for d = 16, 8, 4, 2, 1 set `t[i] = t[i] + t[i+d]` for `i < d`. 49 This mirrors `src/omega_numeric_reduce.c` `cpu_sum_like` (line 124; 50 `OMEGA_REDUCE_SUM_PAD_BITS`). 51 - **Matmul** output `(i,j)` takes the products `A[i,q]·B[q,j]` in q order, then the 52 E1 tile. This is the M20 matmul v1 order (FMUL_RNE products, then the E1 tree). 53 Backward: `gA = g·Bᵀ` (products `g[i,j]·B[q,j]` in j order) and 54 `gB = Aᵀ·g` (products `A[i,q]·g[i,j]` in i order), each followed by the E1 tile. 55 - **Backward walk** (`src/autodiff/omega_autodiff.c` `omega_ad_backward`, 56 line 511): nodes in decreasing index order, `in0` before `in1`. The first 57 contribution to a gradient is stored as is; later contributions are added as 58 `grad + contrib` (`accumulate`, line 107). Because there is no zero 59 initialisation, signed zeros match the C tape bit for bit. 60 - **Rules:** SUB `in1` takes `neg g`. MUL takes `g·value(other)`. RELU routes 61 `g` only where `x > 0`, so `−0`, `+0` and NaN give `+0`; this matches 62 `max_routes_to_a` (line 148) against a zeros operand. BROADCAST sums `g` over 63 rows with the E1 tile. SUM spreads `g` along the reduced axis. 64 - **No contraction:** every `a·b + c` is written as `add (mul a b) c`. The 65 pinned compiler emits no fused multiply-add for it. `tape-test.om` `tnofma` 66 proves this: with `c = −round(a·b)` the result is exactly +0 on all 64 67 trials, while an f64 widening of the same expression is nonzero on at least 68 one trial. 69 70 ## Evidence (host) 71 72 The recorded host suite used omega-mv `seed/out/omc`, SHA-256 73 ``be8c51301307555254fc59e351d281aae1aa096d91521777e33a41c8b446448a`` (main `9920aab1`; the suite 74 first passed with ``62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b``). 75 That pin is historical. The x86efi compiler from PR #1015 is 76 ``b4f45121f6c6d5d8a6ed0f5c4f3934b7cc4bec369bfa89523699bd33928f9b55`` 77 (`seed/omc/omc.om` ``16b4ca40a5bd7796ac08b55d1ceadac1260e52298ed123f45418e77b3221c749``). 78 On 2026-11-04 the tape suite passed against it natively (DGX Spark, Linux aarch64): 79 `TAPE_SUITE_PASS NATIVE_TAPE_PASS checks=302`, all three compiled mutants failed with status 1. 80 The compiler of PR #1022 (`efi 14`) is 81 ``3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194`` 82 (`seed/omc/omc.om` ``0effe37afc4ddd0507151c9f2afa34b3e6774eae7006cbecd8c59f11bc386db7``). 83 On 2026-11-04 the tape suite passed against it the same way (DGX Spark, Linux aarch64, core 9): 84 `TAPE_SUITE_PASS NATIVE_TAPE_PASS checks=302`, all three compiled mutants failed with status 1. 85 On 2026-11-07, with the signed-zero padding checks and the fourth mutant added (DRA-14 86 follow-up), the suite passed against the reseeded compiler 87 ``cfd96b48b0460ab5557853d6856f9c741b96ac8d0d624e06198defb4cbfa0d8a`` (main ``6efc4572``, DGX Spark, 88 Linux aarch64, cores 10-11): `TAPE_SUITE_PASS NATIVE_TAPE_PASS checks=351`, all four compiled 89 mutants failed with status 1. `tape.om` is unchanged (sha256 ``1b4ed431`…8bde`). 90 91 ```sh 92 OMC= OUT= sh tests/autodiff664/run-tape.sh 93 # TAPE_SUITE_PASS NATIVE_TAPE_PASS checks=351 94 ``` 95 96 - `tests/autodiff664/tape-test.om` (351 checks). Expected values come from 97 separate code paths in the test: a test-local E1 tile, a sequential sum, 98 IEEE identities (`x·x` grad is `x + x`, SUB grad is `neg s`, a sum of −0 99 values is −0) and the f64 widening control. No expected value is a 100 hand-entered constant. `torder` 101 requires at least one input where the tree sum differs from the sequential 102 sum, and requires the tape to follow the tree on every input. `tnzsum`, 103 `tnzmm` and `tnzbc` (49 checks) feed all −0 inputs to `tpsum` on both axes, 104 to the matmul forward and both matmul backward reductions, and to the 105 broadcast backward reduction, and require the bits `0x80000000`: a +0 pad 106 would turn every one of them into +0. Random inputs cannot see the pad value. 107 Deviation from 108 the plan: these are not Wolfram-computed literal bit patterns. A rounding 109 mistake shared by the tape and the test-local tile would pass here. That case 110 is covered elsewhere: by the C M21 fixture replay below, and by the 111 exact-rational Wolfram oracle on the full training step in aien-train 112 `tests/adtrain/gradient.wl`, which gave 58/58 exact. 113 - `tests/autodiff664/mutate.om`: four compiled source mutants of `tape.om` 114 (SUB sign dropped, MUL operand swapped to `value(in0)`, RELU tie `gt`→`ge`, 115 E1 pad +0 instead of −0 in `e1tree`). 116 Each compiles with rc 0 and makes the test exit 1, at checks 212, 66, 171 and 305. 117 The pad mutant passed the earlier 302-check test (found by the DRA-14 replay, 118 aien-train `tests/adtrain/replay/padprobe.om`). 119 - `tests/test_omega_ad_fixture.c` (`make test-autodiff-fixture FIXTURE=…`) 120 replays one MLP step written by the native trainer (aien-train 121 `tests/adtrain`, mode D) on the C M21 tape over the M20 CPU table. 122 Observed: `exact=75/75 max_ulp=0 verdict=PASS`. The `--mutant-sign` control 123 fails as required. The C tape is a disclosed test oracle only; nothing in the 124 native tape calls C. 125 - The fixture is 187 u32 words, 748 bytes: a 6-word header, 106 inputs and 75 126 expected values. The plan's "179 words" was an arithmetic slip. 127 - The GB10 arm is `tests/run_ad_chip.sh` (`GB10_CHIP_RUN=1`, 128 `/tmp/aien-gb10.lock`, or the lock its `spark-window` already holds when run 129 under `spark-window run`; physics at `physics.lock`). It ran once on 2026-10-29 130 at 17:07Z, in a window Drake authorised. Result: 131 `AD_FIXTURE_CHIP: exact=75/75 max_ulp=0 verdict=PASS`; the sign-flip control 132 exits 1. Receipt: aien-train `evidence/ADTRAIN/gb10/`. This is one fixture on 133 one device. The GB10 executes the C M21 replay; the native tape runs on the 134 host. 135 136 ## Not claimed 137 138 General autograd (rank >2, more than 32 nodes, DIV/SQRT/MEAN/TRANSPOSE), GPU 139 launch from `.om` (#638 / CUDApp #35), performance, atomic checkpoint 140 publication, or any hardware qualification.