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/aien-train/blob/main/tests/adtrain/run-adtrain.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-train / tests / adtrain / run-adtrain.sh` 159 lines ยท 7908 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: AGPL-3.0-only 3 # adtrain suite: native tape training example, gates 1-4 and the host arm of 5, 4 # plus the golden receipts of PR #42 (docs/adtrain/golden.json: T trajectory, 5 # step-120 checkpoint, G rows), so a self-consistent but different trainer fails. 6 # OMC= OMEGA= OUT= sh tests/adtrain/run-adtrain.sh 7 # OMEGA must contain the commits pinned in docs/adtrain/dependencies.json; the 8 # fixture host arm runs `make test-autodiff-fixture` in OMEGA as checked out. 9 # Host glue only (concatenation, file copies, byte flips, comparisons); every 10 # computation is in .om. Writes each rc/stdout/stderr under $OUT/run. 11 # Last line ADTRAIN_SUITE_PASS (exit 0) or ADTRAIN_SUITE_FAIL (exit 1). 12 set -u 13 ROOT=$(cd "$(dirname "$0")/../.." && pwd) 14 : "${OMC:?set OMC to the pinned seed/out/omc}" 15 : "${OMEGA:?set OMEGA to an omega-mv checkout}" 16 : "${OUT:?set OUT to a scratch directory}" 17 DEPS=$ROOT/docs/adtrain/dependencies.json 18 mkdir -p "$OUT/deps" "$OUT/run" "$OUT/work" "$OUT/mutants" 19 OUT=$(cd "$OUT" && pwd) 20 fail() { echo "ADTRAIN_SUITE_FAIL $1"; exit 1; } 21 22 # 1. Pinned compiler and dependency files from their exact Git objects. 23 want=$(jq -r .compiler.binary_sha256 "$DEPS") 24 have=$(sha256sum "$OMC" | cut -d' ' -f1) 25 echo "$have omc" > "$OUT/deps/omc.sha256" 26 [ "$have" = "$want" ] || fail "compiler-sha256 ($have)" 27 : > "$OUT/deps/files" 28 n=$(jq '.dependencies | length' "$DEPS") 29 i=0 30 while [ "$i" -lt "$n" ]; do 31 commit=$(jq -r ".dependencies[$i].commit" "$DEPS") 32 path=$(jq -r ".dependencies[$i].path" "$DEPS") 33 sha=$(jq -r ".dependencies[$i].sha256" "$DEPS") 34 dst=$OUT/deps/$i-$(basename "$path") 35 git -C "$OMEGA" show "$commit:$path" > "$dst" 2> "$OUT/deps/$i.stderr" || fail "dependency-missing $commit:$path" 36 echo "$sha $dst" | sha256sum -c --status || fail "dependency-sha256 $path" 37 echo "$dst" >> "$OUT/deps/files" 38 i=$((i + 1)) 39 done 40 DEPFILES=$(cat "$OUT/deps/files") 41 42 build() { # $1 unit.om $2 out.elf $3 tag 43 "$OMC" < "$1" > "$2" 2> "$OUT/run/$3.compile.stderr" 44 echo $? > "$OUT/run/$3.compile.rc" 45 [ "$(cat "$OUT/run/$3.compile.rc")" = 0 ] || return 1 46 [ "$(od -An -tx1 -N4 "$2" | tr -d ' ')" = `7f454c46` ] || return 1 47 chmod 700 "$2" 48 } 49 # run TAG ELF MODE: run one driver mode inside $OUT/work. 50 run() { 51 (cd "$OUT/work" && printf '%s' "$3" | "$2" > "$OUT/run/$1.stdout" 2> "$OUT/run/$1.stderr") 52 echo $? > "$OUT/run/$1.rc" 53 cat "$OUT/run/$1.rc" 54 } 55 # golden GATE FILE: FILE must hash to the sha256 recorded for GATE in 56 # docs/adtrain/golden.json (PR #42's receipts); a missing entry also fails. 57 GOLD=$ROOT/docs/adtrain/golden.json 58 golden() { 59 g=$(jq -r --arg g "$1" '[.receipts[] | select(.gate == $g)] | if length == 1 then .[0].sha256 else "" end' "$GOLD") 60 [ -n "$g" ] || fail "$1 (no single golden.json entry)" 61 h=$(sha256sum "$2" | cut -d' ' -f1) 62 echo "$1 want=$g have=$h" >> "$OUT/run/golden.txt" 63 [ "$h" = "$g" ] || fail "$1 ($h)" 64 } 65 : > "$OUT/run/golden.txt" 66 flip() { # flip FILE OFFSET: xor one byte with 1 67 b=$(od -An -tu1 -j"$2" -N1 "$1" | tr -d ' ') 68 printf "\\$(printf %o $((b ^ 1)))" | dd of="$1" bs=1 seek="$2" conv=notrunc 2> /dev/null 69 } 70 71 # shellcheck disable=SC2086 72 cat $DEPFILES "$ROOT/native/adtrain/mlp.om" "$ROOT/tests/adtrain/main.om" > "$OUT/unit.om" 73 build "$OUT/unit.om" "$OUT/unit.elf" unit || fail compile 74 E=$OUT/unit.elf 75 CK=$OUT/work/adtrain.ck 76 77 # 2. Gates 1 and 3: forward, loss, updates that reduce loss (T). 78 [ "$(run T "$E" T)" = 0 ] || fail train 79 grep -qx ADTRAIN_T_PASS "$OUT/run/T.stdout" || fail train-output 80 [ "$(grep -c '^L ' "$OUT/run/T.stdout")" = 201 ] || fail train-L-rows 81 [ "$(grep -c '^P ' "$OUT/run/T.stdout")" = 58 ] || fail train-P-rows 82 l0=$(awk '$1=="L"&&$2==0{print $3}' "$OUT/run/T.stdout") 83 l100=$(awk '$1=="L"&&$2==100{print $3}' "$OUT/run/T.stdout") 84 l200=$(awk '$1=="L"&&$2==200{print $3}' "$OUT/run/T.stdout") 85 # loss >= 0, so binary32 bit patterns order like the values 86 [ "$l200" -lt "$l0" ] && [ "$l200" -lt "$l100" ] || fail loss-gate 87 echo "L0=$l0 L100=$l100 L200=$l200" > "$OUT/run/loss-gate.txt" 88 # Golden trajectory: every L and P row bit for bit as recorded by PR #42. 89 golden golden-T-stdout "$OUT/run/T.stdout" 90 91 # 3. Gate 2: tape gradients against central differences (G). 92 [ "$(run G "$E" G)" = 0 ] || fail gradcheck 93 ok=$(grep -c '^GC [0-9]* [0-9]* 1$' "$OUT/run/G.stdout") 94 bad=$(grep -c '^GC [0-9]* [0-9]* 0$' "$OUT/run/G.stdout") 95 [ "$ok" -ge 50 ] && [ "$bad" = 0 ] || fail "gradcheck-rows ok=$ok bad=$bad" 96 golden golden-G-stdout "$OUT/run/G.stdout" 97 98 # 4. Fixture for the C oracle (D). 99 [ "$(run D "$E" D)" = 0 ] || fail fixture 100 [ "$(wc -c < "$OUT/work/adtrain.fix")" = 748 ] || fail fixture-size 101 cp "$OUT/work/adtrain.fix" "$OUT/adtrain.fix" 102 103 # 5. Gate 4: interrupted at 120, resumed to 200, identical to uninterrupted. 104 [ "$(run S "$E" S)" = 0 ] || fail save 105 [ "$(wc -c < "$CK")" = 536 ] || fail checkpoint-size 106 cp "$CK" "$OUT/adtrain.ck.good" 107 # Golden checkpoint: the step-120 image byte for byte as recorded by PR #42. 108 golden golden-ck120 "$OUT/adtrain.ck.good" 109 [ "$(run R "$E" R)" = 0 ] || fail resume 110 grep -qx ADTRAIN_R_PASS "$OUT/run/R.stdout" || fail resume-output 111 awk '($1=="L"&&$2>=120)||$1=="P"' "$OUT/run/T.stdout" > "$OUT/run/T.tail" 112 awk '$1=="L"||$1=="P"' "$OUT/run/R.stdout" > "$OUT/run/R.tail" 113 [ "$(grep -c '^L ' "$OUT/run/R.tail")" = 81 ] || fail resume-L-rows 114 cmp -s "$OUT/run/T.tail" "$OUT/run/R.tail" || fail resume-identity 115 116 # 6. Checkpoint refusals: other data (66), truncated (65), flipped bytes (65). 117 [ "$(run Z "$E" Z)" = 0 ] || fail save-other-data 118 cp "$CK" "$OUT/adtrain.ck.seed29" 119 [ "$(run R-binding "$E" R)" = 66 ] || fail binding-refusal 120 head -c 535 "$OUT/adtrain.ck.good" > "$CK" 121 [ "$(run R-truncated "$E" R)" = 65 ] || fail truncation-refusal 122 cp "$OUT/adtrain.ck.good" "$OUT/adtrain.ck.flip96" 123 flip "$OUT/adtrain.ck.flip96" 96 124 cp "$OUT/adtrain.ck.flip96" "$CK" 125 [ "$(run R-flip96 "$E" R)" = 65 ] || fail checksum-refusal 126 cp "$OUT/adtrain.ck.good" "$CK" 127 flip "$CK" 100 128 [ "$(run R-flip100 "$E" R)" = 65 ] || fail padding-refusal 129 130 # 7. Compiled mutants of mlp.om; each must be caught. 131 build "$ROOT/tests/adtrain/mutate.om" "$OUT/mutate.elf" mutate || fail mutate-compile 132 for mode in 0 1 2; do 133 { printf '%s' "$mode"; cat "$ROOT/native/adtrain/mlp.om"; } | "$OUT/mutate.elf" > "$OUT/mutants/mlp$mode.om" 134 echo $? > "$OUT/mutants/mlp$mode.mutate.rc" 135 [ "$(cat "$OUT/mutants/mlp$mode.mutate.rc")" = 0 ] || fail "mutant$mode-inject" 136 # shellcheck disable=SC2086 137 cat $DEPFILES "$OUT/mutants/mlp$mode.om" "$ROOT/tests/adtrain/main.om" > "$OUT/mutants/unit$mode.om" 138 build "$OUT/mutants/unit$mode.om" "$OUT/mutants/unit$mode.elf" "mutant$mode" || fail "mutant$mode-compile" 139 done 140 rc=$(run mutant0-T "$OUT/mutants/unit0.elf" T) 141 [ "$rc" = 86 ] || [ "$rc" = 88 ] || fail "mutant0-survived rc=$rc" 142 cp "$OUT/adtrain.ck.seed29" "$CK" 143 [ "$(run mutant1-R-binding "$OUT/mutants/unit1.elf" R)" = 0 ] || fail mutant1-not-load-bearing 144 cp "$OUT/adtrain.ck.flip96" "$CK" 145 [ "$(run mutant2-R-flip96 "$OUT/mutants/unit2.elf" R)" = 0 ] || fail mutant2-not-load-bearing 146 147 # 8. Gate 5 host arm: the fixture replayed on the C M21 tape (CPU table). 148 git -C "$OMEGA" rev-parse HEAD > "$OUT/run/fixture-host.omega-head" 149 make -s -C "$OMEGA" test-autodiff-fixture FIXTURE="$OUT/adtrain.fix" \ 150 > "$OUT/run/fixture-host.stdout" 2> "$OUT/run/fixture-host.stderr" 151 echo $? > "$OUT/run/fixture-host.rc" 152 [ "$(cat "$OUT/run/fixture-host.rc")" = 0 ] || fail fixture-host 153 grep -Eq '^AD_FIXTURE_HOST: exact=[0-9]+/75 max_ulp=[0-9]+ verdict=(PASS|PASS_TOL)$' \ 154 "$OUT/run/fixture-host.stdout" || fail fixture-host-verdict 155 grep -q '^AD_FIXTURE_HOST: .* verdict=FAIL (mutant-sign)$' "$OUT/run/fixture-host.stdout" \ 156 || fail fixture-host-control 157 158 (cd "$OUT" && sha256sum unit.om unit.elf adtrain.fix adtrain.ck.good run/*.stdout) > "$OUT/artifacts.sha256" 159 echo ADTRAIN_SUITE_PASS