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
aien-train / tests / omegese45 / core / run-core.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: AGPL-3.0-only |
| 3 | # omegese45 pipeline suite (aien-train #45): generator, model, checkpoint and decode CLI. |
| 4 | # OMC=<omc bf54b19f> OMEGA=<omega-mv checkout with bf54b19f> OUT=<scratch dir> sh tests/omegese45/core/run-core.sh |
| 5 | # Host glue only (build via build.sh, file copies, byte flips, comparisons); every |
| 6 | # computation is in .om except tests/omegese45/core/oracle.py, the stdlib referee. |
| 7 | # Writes each rc/stdout under $OUT/run. Last line OE45_CORE_PASS (exit 0) or |
| 8 | # OE45_CORE_FAIL <check> (exit 1). Heavy steps run under taskset/nice/ionice. |
| 9 | set -u |
| 10 | ROOT=$(cd "$(dirname "$0")/../../.." && pwd) |
| 11 | : "${OMC:?set OMC to the pinned seed/out/omc}" |
| 12 | : "${OMEGA:?set OMEGA to an omega-mv checkout}" |
| 13 | : "${OUT:?set OUT to a scratch directory}" |
| 14 | mkdir -p "$OUT/bin" "$OUT/run" "$OUT/w" "$OUT/mut" |
| 15 | OUT=$(cd "$OUT" && pwd) |
| 16 | P="taskset -c ${AIEN_TEST_CPUS:-0-9,15-19} nice -n 19 ionice -c3" |
| 17 | ORA="python3 $ROOT/tests/omegese45/core/oracle.py" |
| 18 | VOCAB=$ROOT/docs/omegese45/vocab.tsv |
| 19 | B=$OUT/bin |
| 20 | W=$OUT/w |
| 21 | fail() { echo "OE45_CORE_FAIL $1"; exit 1; } |
| 22 | ok() { echo "ok $1"; } |
| 23 | # run TAG CMD...: run in $W, keep stdout/stderr/rc, print the rc. |
| 24 | run() { |
| 25 | tag=$1; shift |
| 26 | (cd "$W" && $P "$@" > "$OUT/run/$tag.stdout" 2> "$OUT/run/$tag.stderr") |
| 27 | echo $? > "$OUT/run/$tag.rc" |
| 28 | cat "$OUT/run/$tag.rc" |
| 29 | } |
| 30 | flip() { # flip FILE OFFSET: xor one byte with 1 |
| 31 | b=$(od -An -tu1 -j"$2" -N1 "$1" | tr -d ' ') |
| 32 | printf "\\$(printf %o $((b ^ 1)))" | dd of="$1" bs=1 seek="$2" conv=notrunc 2> /dev/null |
| 33 | } |
| 34 | field() { # field TAG N: Nth space-separated word of the first stdout line |
| 35 | sed -n 1p "$OUT/run/$1.stdout" | cut -d' ' -f"$2" |
| 36 | } |
| 37 | |
| 38 | # 1. Build (pinned compiler and SHA unit checked by build.sh). |
| 39 | OMC=$OMC OMEGA=$OMEGA OUT=$B sh "$ROOT/tests/omegese45/core/build.sh" > "$OUT/run/build.out" || fail "build $(cat "$OUT/run/build.out")" |
| 40 | ok build |
| 41 | |
| 42 | # 2. Generator: determinism, seed sensitivity, contract validity, reference policy. |
| 43 | [ "$(run gen1 "$B/oe45gen" 4501 300 train.oe45 train.ids)" = 0 ] || fail gen |
| 44 | [ "$(run gen2 "$B/oe45gen" 4501 300 again.oe45 again.ids)" = 0 ] || fail gen-rerun |
| 45 | cmp -s "$W/train.oe45" "$W/again.oe45" && cmp -s "$W/train.ids" "$W/again.ids" || fail gen-determinism |
| 46 | cmp -s "$OUT/run/gen1.stdout" "$OUT/run/gen2.stdout" || fail gen-stats-determinism |
| 47 | [ "$(run gen3 "$B/oe45gen" 4502 60 dev.oe45 dev.ids)" = 0 ] || fail gen-dev |
| 48 | cmp -s "$W/train.ids" "$W/dev.ids" && fail gen-seed-insensitive |
| 49 | [ "$(run vgen "$B/oe45test" vgen train.oe45 train.ids)" = 0 ] || fail gen-contract-validity |
| 50 | [ "$(field vgen 2)" = 300 ] || fail gen-episode-count |
| 51 | [ "$(run vgendev "$B/oe45test" vgen dev.oe45 dev.ids)" = 0 ] || fail gen-contract-validity-dev |
| 52 | cp "$W/train.ids" "$W/bad.ids" |
| 53 | flip "$W/bad.ids" 40 |
| 54 | [ "$(run vgenbad "$B/oe45test" vgen train.oe45 bad.ids)" = 40 ] || fail vgen-negative-control |
| 55 | $ORA policy "$W/train.oe45" > "$OUT/run/policy.stdout" || fail reference-policy |
| 56 | $ORA policy "$W/dev.oe45" > "$OUT/run/policydev.stdout" || fail reference-policy-dev |
| 57 | ok generator |
| 58 | |
| 59 | # 3. Step-0 checkpoint: deterministic init, vocab pin equals vocab.tsv. |
| 60 | mkdir -p "$W/ck0" "$W/ck0b" |
| 61 | [ "$(run init "$B/oe45core" init ck0 train.ids 45 300 1200 7 7)" = 0 ] || fail init |
| 62 | [ "$(run initb "$B/oe45core" init ck0b train.ids 45 300 1200 7 7)" = 0 ] || fail init-rerun |
| 63 | cmp -s "$W/ck0/ck.a" "$W/ck0b/ck.a" || fail init-determinism |
| 64 | [ -e "$W/ck0/ck.b" ] && fail init-one-slot |
| 65 | [ "$(run info0 "$B/oe45core" info ck0)" = 0 ] || fail info |
| 66 | [ "$(field info0 12)" = "$(sha256sum "$VOCAB" | cut -d' ' -f1)" ] || fail vocab-pin |
| 67 | sha256sum "$W/ck0/ck.a" > "$OUT/run/ck0.sha256" |
| 68 | ok step0 |
| 69 | |
| 70 | # 4. Gradient check, loss decrease, target/mask oracle, causal no-leak. |
| 71 | [ "$(run grad "$B/oe45test" grad ck0 train.ids)" = 0 ] || fail gradient-check |
| 72 | [ "$(run ldec "$B/oe45test" ldec ck0 train.ids 50)" = 0 ] || fail loss-decrease |
| 73 | [ "$(run mask "$B/oe45test" mask train.ids 300)" = 0 ] || fail mask-dump |
| 74 | $ORA mask "$VOCAB" "$W/train.oe45" 300 > "$OUT/run/mask.expect" || fail mask-oracle |
| 75 | cmp -s "$OUT/run/mask.stdout" "$OUT/run/mask.expect" || fail mask-target |
| 76 | [ "$(run leak "$B/oe45test" leak ck0 train.ids)" = 0 ] || fail causal-no-leak |
| 77 | ok model |
| 78 | |
| 79 | # 5. Training, kill -9 mid-run, resume: byte-identical to the uninterrupted run. |
| 80 | cp -r "$W/ck0" "$W/cku" |
| 81 | cp -r "$W/ck0" "$W/ckk" |
| 82 | [ "$(run train "$B/oe45core" train cku train.ids 1200 100)" = 0 ] || fail train |
| 83 | krc=$(run kill timeout -s KILL 2 "$B/oe45core" train ckk train.ids 1200 100) |
| 84 | [ "$krc" = 137 ] || fail "kill-not-mid-run rc=$krc" |
| 85 | [ "$(run resume "$B/oe45core" train ckk train.ids 1200 100)" = 0 ] || fail resume |
| 86 | cmp -s "$W/cku/ck.a" "$W/ckk/ck.a" && cmp -s "$W/cku/ck.b" "$W/ckk/ck.b" || fail resume-not-identical |
| 87 | [ "$(run bind "$B/oe45core" train cku dev.ids 1300 100)" = 54 ] || fail data-binding |
| 88 | ok resume |
| 89 | |
| 90 | # 6. Round trip: load then save reproduces the payload exactly. |
| 91 | mkdir -p "$W/ckr" |
| 92 | [ "$(run infou "$B/oe45core" info cku)" = 0 ] || fail info-trained |
| 93 | slot=$(field infou 2) |
| 94 | [ "$(run rt "$B/oe45test" rt cku ckr)" = 0 ] || fail round-trip |
| 95 | r=$(ls "$W/ckr") |
| 96 | tail -c +241 "$W/cku/ck.$slot" > "$OUT/run/rt.src" |
| 97 | tail -c +241 "$W/ckr/$r" > "$OUT/run/rt.dst" |
| 98 | cmp -s "$OUT/run/rt.src" "$OUT/run/rt.dst" || fail round-trip-payload |
| 99 | [ "$(run infor "$B/oe45core" info ckr)" = 0 ] || fail info-round-trip |
| 100 | [ "$(field infor 4)" = "$(field infou 4)" ] || fail round-trip-step |
| 101 | ok round-trip |
| 102 | |
| 103 | # 7. Corrupt slots: newest corrupt -> older slot; both corrupt -> 51; wrong vocab -> 52. |
| 104 | gen=$(field infou 5) |
| 105 | other=a |
| 106 | [ "$slot" = a ] && other=b |
| 107 | cp -r "$W/cku" "$W/ckc" |
| 108 | flip "$W/ckc/ck.$slot" 5000 |
| 109 | [ "$(run infoc "$B/oe45core" info ckc)" = 0 ] || fail fallback |
| 110 | [ "$(field infoc 2)" = "$other" ] && [ "$(field infoc 5)" = $((gen - 1)) ] || fail fallback-slot |
| 111 | cp -r "$W/cku" "$W/ckh" |
| 112 | flip "$W/ckh/ck.$slot" 100 |
| 113 | [ "$(run infoh "$B/oe45core" info ckh)" = 0 ] && [ "$(field infoh 2)" = "$other" ] || fail fallback-header |
| 114 | cp -r "$W/cku" "$W/ckt" |
| 115 | head -c 1000 "$W/cku/ck.$slot" > "$W/ckt/ck.$slot" |
| 116 | [ "$(run infot "$B/oe45core" info ckt)" = 0 ] && [ "$(field infot 2)" = "$other" ] || fail fallback-truncated |
| 117 | flip "$W/ckc/ck.$other" 3000000 |
| 118 | [ "$(run info51 "$B/oe45core" info ckc)" = 51 ] || fail both-corrupt-51 |
| 119 | mkdir -p "$W/ckn" |
| 120 | [ "$(run info51e "$B/oe45core" info ckn)" = 51 ] || fail empty-51 |
| 121 | mkdir -p "$W/ckv" |
| 122 | [ "$(run forcev "$B/oe45test" force cku ckv 3)" = 0 ] || fail force-vocab |
| 123 | [ "$(run info52 "$B/oe45core" info ckv)" = 52 ] || fail wrong-vocab-52 |
| 124 | ok checkpoint |
| 125 | |
| 126 | # 8. Decode: U and G, guided decode never emits an illegal id, budget 53, invalid 50, prefix 40. |
| 127 | $ORA prefixes "$W/dev.oe45" 60 "$W/pre.oe45" "$OUT/run/pre.expect" || fail prefixes |
| 128 | { echo "oe45 v1"; sed -n 2p "$W/dev.oe45"; } > "$W/one.oe45" |
| 129 | for c in ck0 cku; do |
| 130 | for m in U G; do |
| 131 | [ "$(run "b$c$m" "$B/oe45core" batch $c $m pre.oe45 "b$c$m.out")" = 0 ] || fail "batch-$c-$m" |
| 132 | [ "$(run "v$c$m" "$B/oe45test" vok "b$c$m.out")" = 0 ] || fail "vok-$c-$m" |
| 133 | done |
| 134 | [ "$(field "v${c}G" 3)" = 0 ] && [ "$(field "v${c}G" 4)" = 0 ] && [ "$(field "v${c}G" 5)" = 0 ] && [ "$(field "v${c}G" 6)" = 0 ] && [ "$(field "v${c}G" 7)" = 0 ] || fail "guided-illegal-$c" |
| 135 | [ "$(field "v${c}U" 3)" = 0 ] || fail "unguided-invalid-ok-$c" |
| 136 | done |
| 137 | [ "$(wc -l < "$W/bckuG.out")" = "$(wc -l < "$OUT/run/pre.expect")" ] || fail batch-line-count |
| 138 | [ "$(run decg "$B/oe45core" decode cku G one.oe45)" = 0 ] || fail decode-G |
| 139 | [ "ok $(cat "$OUT/run/decg.stdout")" = "$(sed -n 1p "$W/bckuG.out")" ] || fail decode-batch-agree |
| 140 | urc=$(run decu "$B/oe45core" decode cku U one.oe45) |
| 141 | [ "$urc" = 0 ] || fail "decode-U fixture expected rc 0, got $urc" |
| 142 | [ "ok $(cat "$OUT/run/decu.stdout")" = "$(sed -n 1p "$W/bckuU.out")" ] || fail decode-U-batch-agree |
| 143 | mkdir -p "$W/ckm" "$W/cke" |
| 144 | [ "$(run forcem "$B/oe45test" force cku ckm 1)" = 0 ] || fail force-mm |
| 145 | [ "$(run dec53 "$B/oe45core" decode ckm U one.oe45)" = 53 ] || fail budget-53 |
| 146 | [ -s "$OUT/run/dec53.stdout" ] && fail budget-53-stdout |
| 147 | [ "$(run dec53g "$B/oe45core" decode ckm G one.oe45)" = 0 ] || fail guided-under-mm-bias |
| 148 | [ "$(run forcee "$B/oe45test" force cku cke 2)" = 0 ] || fail force-end |
| 149 | [ "$(run dec50 "$B/oe45core" decode cke U one.oe45)" = 50 ] || fail invalid-50 |
| 150 | { echo "oe45 v1"; sed -n 2,3p "$W/dev.oe45"; } > "$W/badp.oe45" |
| 151 | [ "$(run dec40 "$B/oe45core" decode cku G badp.oe45)" = 40 ] || fail prefix-40 |
| 152 | { echo "oe45 v2"; sed -n 2p "$W/dev.oe45"; } > "$W/badh.oe45" |
| 153 | [ "$(run dec40h "$B/oe45core" decode cku G badh.oe45)" = 40 ] || fail header-40 |
| 154 | [ "$(run dec52 "$B/oe45core" decode ckv G one.oe45)" = 52 ] || fail decode-52 |
| 155 | # Refuse prefix (interface ยง3): G then `act refuse C end` is a decode point for P (rc 0, |
| 156 | # decode and batch); a refuse after an R, or any message after the refuse, is 40. |
| 157 | G12C="goal mm ushort 0x12c ushort 0x008 ushort 0x008 ulong 0x0005 end" |
| 158 | G008="goal mm ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0005 end" |
| 159 | A008="act job mm ushort 0x008 ushort 0x008 ushort 0x008 ulong 0x0005 end" |
| 160 | printf 'oe45 v1\n%s\nact refuse bound end\n' "$G12C" > "$W/refp.oe45" |
| 161 | [ "$(run decref "$B/oe45core" decode cku G refp.oe45)" = 0 ] || fail refuse-prefix-decode |
| 162 | [ "$(run batref "$B/oe45core" batch cku G refp.oe45 refb.out)" = 0 ] || fail refuse-prefix-batch |
| 163 | [ "ok $(cat "$OUT/run/decref.stdout")" = "$(cat "$W/refb.out")" ] || fail refuse-prefix-batch-agree |
| 164 | printf 'oe45 v1\n%s\n%s\nres ok end\nact refuse bound end\n' "$G008" "$A008" > "$W/refr.oe45" |
| 165 | [ "$(run decrefr "$B/oe45core" decode cku G refr.oe45)" = 40 ] || fail refuse-after-R-40 |
| 166 | printf 'oe45 v1\n%s\nact refuse bound end\nact refuse bound end\n' "$G12C" > "$W/refa.oe45" |
| 167 | [ "$(run decrefa "$B/oe45core" decode cku G refa.oe45)" = 40 ] || fail second-A-after-refuse-40 |
| 168 | printf 'oe45 v1\n%s\nact refuse bound end\nres fail transport end\n' "$G12C" > "$W/refx.oe45" |
| 169 | [ "$(run decrefx "$B/oe45core" decode cku G refx.oe45)" = 40 ] || fail R-after-refuse-40 |
| 170 | cat "$W/refr.oe45" "$W/refp.oe45" "$W/refa.oe45" > "$W/refm.oe45" |
| 171 | [ "$(run batrefm "$B/oe45core" batch cku G refm.oe45 refm.out)" = 0 ] || fail refuse-batch-mixed |
| 172 | [ "$(sed -n 1p "$W/refm.out")" = 40 ] && [ "$(sed -n 2p "$W/refm.out" | cut -c1-3)" = "ok " ] && [ "$(sed -n 3p "$W/refm.out")" = 40 ] || fail refuse-batch-mixed-lines |
| 173 | ok decode |
| 174 | |
| 175 | # 9. Mutants: each must be KILLED by the named check. |
| 176 | [ "$(run m0 sh -c "printf 0 | cat - '$ROOT/native/omegese45/core/model.om' | '$B/oe45mut' > '$OUT/mut/model0.om'")" = 0 ] || fail mutant0-inject |
| 177 | [ "$(run m1 sh -c "printf 1 | cat - '$ROOT/native/omegese45/core/model.om' | '$B/oe45mut' > '$OUT/mut/model1.om'")" = 0 ] || fail mutant1-inject |
| 178 | OMC=$OMC OMEGA=$OMEGA OUT=$OUT/mut/b0 sh "$ROOT/tests/omegese45/core/build.sh" "$OUT/mut/model0.om" > "$OUT/run/mb0.out" || fail mutant0-build |
| 179 | OMC=$OMC OMEGA=$OMEGA OUT=$OUT/mut/b1 sh "$ROOT/tests/omegese45/core/build.sh" "$OUT/mut/model1.om" > "$OUT/run/mb1.out" || fail mutant1-build |
| 180 | g0=$(run mgrad0 "$OUT/mut/b0/oe45test" grad ck0 train.ids) |
| 181 | [ "$g0" = 86 ] || fail "mutant0-sign-flip-survived rc=$g0" |
| 182 | echo "mutant0 sign-flip KILLED by gradient check (rc 86)" |
| 183 | [ "$(run mmask1 "$OUT/mut/b1/oe45test" mask train.ids 300)" = 0 ] || fail mutant1-mask-run |
| 184 | cmp -s "$OUT/run/mmask1.stdout" "$OUT/run/mask.expect" && fail mutant1-wrong-target-survived |
| 185 | echo "mutant1 wrong-target KILLED by mask/target oracle" |
| 186 | echo OE45_CORE_PASS |