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/si19/run-select.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 / si19 / run-select.sh` 267 lines ยท 14881 bytes Raw Blame History 1 #!/bin/sh 2 # SPDX-License-Identifier: AGPL-3.0-only 3 # aien-train#25 ORIG-2 host glue (POSIX sh, disclosed): materialize the pinned sources, 4 # verify SHA-256, concatenate, compile with the pinned seeded compiler, run the .om 5 # tests and the fixture training/control/resume/refusal/evaluation runs through the 6 # process path, inject faults, and record every status. Every judgment about numbers 7 # is made inside the .om units; this file only sequences and compares bytes/exit codes. 8 # Host CPU only. No GPU, network, service or model process is touched. 9 # RECORDS= ALLOW=: run the same train/eval steps over a 10 # given record file (real-record run); the SYNTHETIC fixture and the mutants are skipped. 11 # V2=1 (ORIG1-CONTRACT-v2.md; benchmarks-mv manifests/prereg/orig3_selector_v2.json): after the 12 # tests, only the v2 steps on RECORDS (or the fixture): v2 admission (config flag 8), MLP 13 # candidate and the shuffled/untrained controls at the frozen lr 2^-8, seed 19024, at most 14 # 64 epochs, patience 16 on VALIDATION; then mode E per image on VALIDATION + HELD-OUT. 15 V2=${V2:-0} 16 set -u 17 ROOT=$(cd "$(dirname "$0")/../.." && pwd) 18 OUT=${OUT:-$ROOT/evidence/SI19-ORIG2/fixture-run} 19 OMC=${OMC:-/tmp/omc-`191b776e`} 20 OMC2=${OMC2:-$HOME/workspace/omega-seedqual-`20261025`/seed/out/omc} 21 BRIDGE=${OMEGA_BRIDGE_GIT:-$HOME/workspace/omega-bridge} 22 OMEGA=${OMEGA_MV_GIT:-$HOME/workspace/omega} 23 QUIET=${QUIET:-quiet-build} 24 BUILD=${BUILD:-$(mktemp -d "${TMPDIR:-/tmp}/si19sel.XXXXXX")} 25 RECORDS=${RECORDS:-} 26 ALLOW=${ALLOW:-} 27 SEED=${SEED:-19024} 28 FIXSEED=${FIXSEED:-4242} 29 FIXCOUNT=${FIXCOUNT:-400} 30 LR_AFF=${LR_AFF:-8} 31 LR_MLP=${LR_MLP:-8} 32 OMC_SHA=`191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9` 33 OMC2_SHA=`734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61` 34 mkdir -p "$OUT" "$BUILD/deps" 35 SUM="$OUT/summary.txt" 36 : > "$SUM" 37 note() { echo "$*" | tee -a "$SUM"; } 38 fail() { note "SI19_SELECT_RUN_FAIL $*"; exit 1; } 39 command -v "$QUIET" > /dev/null 2>&1 || QUIET=env 40 TIMEV="" 41 [ -x /usr/bin/time ] && TIMEV="/usr/bin/time -v" 42 43 note "build_dir=$BUILD" 44 note "source_commit=$(git -C "$ROOT" rev-parse HEAD)" 45 note "host=$(uname -srm)" 46 git -C "$BRIDGE" show `7e1d0d61755ec1a0bbf20941a18379861b5b9d0d`:native/ref32/add32.om > "$BUILD/deps/add32.om" || fail materialize add32 47 git -C "$BRIDGE" show `7e1d0d61755ec1a0bbf20941a18379861b5b9d0d`:native/ref32/mul32.om > "$BUILD/deps/mul32.om" || fail materialize mul32 48 git -C "$OMEGA" show `3a995ba8dace538c1532c747d829ca6e4a73582d`:native/ecosystem663/metadata.om > "$BUILD/deps/metadata.om" || fail materialize metadata 49 git -C "$ROOT" show `c9782bfdcf1885082d1fa6c483473f2a514096ad`:native/ecosystem6/affine.om > "$BUILD/deps/affine.om" || fail materialize affine 50 (cd "$BUILD/deps" && sha256sum -c "$ROOT/docs/si19/deps.sha256") > "$OUT/deps-check.txt" 2>&1 || fail dependency hash 51 set -- $(sha256sum "$OMC") 52 [ "$1" = "$OMC_SHA" ] || fail "compiler hash $1" 53 note "compiler_sha256=$1" 54 if [ -x "$OMC2" ]; then 55 set -- $(sha256sum "$OMC2") 56 [ "$1" = "$OMC2_SHA" ] || fail "second compiler hash $1" 57 note "second_compiler_sha256=$1" 58 else 59 OMC2="" 60 note "second_compiler=NOT_RUN (absent)" 61 fi 62 63 N="$ROOT/native/si19" 64 LIB="$BUILD/deps/add32.om $BUILD/deps/mul32.om $BUILD/deps/metadata.om $BUILD/deps/affine.om $N/fixture.om $N/world.om $N/omexp.om $N/omexpfix.om $N/select.om" 65 66 # build NAME CALLER [LIBRARY...]: compile one concatenated unit with the pinned compiler; 67 # the second compiler must also accept it (NAME.r6.elf, compile-only check). 68 build() { 69 name=$1; caller=$2; shift 2 70 [ $# -gt 0 ] || set -- $LIB 71 cat "$@" "$caller" > "$BUILD/$name.om" 72 "$QUIET" "$OMC" < "$BUILD/$name.om" > "$BUILD/$name.elf" 2> "$OUT/$name.compile.stderr" 73 rc=$? 74 echo "$rc" > "$OUT/$name.compile.rc" 75 [ "$rc" -eq 0 ] || return "$rc" 76 head -c 4 "$BUILD/$name.elf" | od -An -c | grep -q 'E L F' || return 70 77 chmod 700 "$BUILD/$name.elf" 78 if [ -n "$OMC2" ]; then 79 "$QUIET" "$OMC2" < "$BUILD/$name.om" > "$BUILD/$name.r6.elf" 2> "$OUT/$name.r6.compile.stderr" 80 rc=$? 81 echo "$rc" > "$OUT/$name.r6.compile.rc" 82 [ "$rc" -eq 0 ] || return "$rc" 83 chmod 700 "$BUILD/$name.r6.elf" 84 fi 85 } 86 87 ms() { date +%s%N; } 88 89 # le64 N: 8 little-endian bytes of N. cfg W...: config words. allow LINE: 4096-byte block. 90 le64() { n=$1; i=0; while [ "$i" -lt 8 ]; do b=$((n % 256)); n=$((n / 256)); printf "\\$(printf '%03o' "$b")"; i=$((i + 1)); done; } 91 cfg() { for v in "$@"; do le64 "$v"; done; } 92 allowblock() { { cat "$1"; head -c 4096 /dev/zero; } | head -c 4096; } 93 94 build select-test "$ROOT/tests/si19/select-test.om" || fail compile select-test 95 build selmain "$N/selmain.om" || fail compile selmain 96 readelf -l -d "$BUILD/selmain.elf" > "$OUT/selmain.readelf.txt" 2>&1 97 note "second_compiler_units=$( [ -n "$OMC2" ] && echo 'select-test selmain compiled' || echo NOT_RUN )" 98 99 t0=$(ms) 100 $TIMEV "$BUILD/select-test.elf" > "$OUT/select-test.stdout" 2> "$OUT/select-test.stderr" 101 rc=$?; t1=$(ms) 102 echo "$rc" > "$OUT/select-test.rc" 103 note "select-test rc=$rc wall_ms=$(( (t1 - t0) / `1000000` )) $(cat "$OUT/select-test.stdout") $(grep 'Maximum resident' "$OUT/select-test.stderr" 2>/dev/null | sed 's/^[[:space:]]*//')" 104 [ "$rc" -eq 0 ] || fail select-test 105 if [ -n "$OMC2" ]; then 106 "$BUILD/select-test.r6.elf" > "$OUT/select-test.r6.stdout" 2> "$OUT/select-test.r6.stderr" 107 rc=$? 108 echo "$rc" > "$OUT/select-test.r6.rc" 109 note "select-test(r6 compiler) rc=$rc $(cat "$OUT/select-test.r6.stdout")" 110 [ "$rc" -eq 0 ] || fail select-test r6 111 fi 112 113 # run NAME MODE "CFG WORDS" [IMAGE]: stdin = mode, config, allow block, image, records; 114 # fd 3 receives an image, fd 4 the per-record lines. Exit code is returned. 115 run() { 116 name=$1; mode=$2; words=$3; img=${4:-} 117 t0=$(ms) 118 { printf '%s' "$mode"; cfg $words; allowblock "$ALLOWFILE"; [ -n "$img" ] && cat "$img"; cat "$RECFILE"; } \ 119 | $TIMEV "$BUILD/selmain.elf" 3> "$BUILD/$name.img" 4> "$OUT/$name.records" > "$OUT/$name.stdout" 2> "$OUT/$name.stderr" 120 rc=$?; t1=$(ms) 121 echo "$rc" > "$OUT/$name.rc" 122 note "$name mode=$mode rc=$rc wall_ms=$(( (t1 - t0) / `1000000` )) epochs=$(sed -n 's/^epochs=//p' "$OUT/$name.stdout") updates=$(sed -n 's/^updates=//p' "$OUT/$name.stdout") dev_loss_dec=$(sed -n 's/^dev_loss_dec=//p' "$OUT/$name.stdout") $(grep 'Maximum resident' "$OUT/$name.stderr" 2>/dev/null | sed 's/^[[:space:]]*//')" 123 return "$rc" 124 } 125 kv() { sed -n "s/^$2=//p" "$OUT/$1.stdout"; } 126 127 if [ -n "$RECORDS" ]; then 128 [ -f "$RECORDS" ] || fail "RECORDS file $RECORDS" 129 [ -f "$ALLOW" ] || fail "ALLOW file $ALLOW" 130 RECFILE=$RECORDS; ALLOWFILE=$ALLOW 131 note "records_source=$RECORDS (real-record run; development-only)" 132 else 133 { printf 'G'; cfg "$FIXSEED" "$FIXCOUNT"; } | "$BUILD/selmain.elf" 3> "$BUILD/fixture.rb" > "$OUT/fixture.stdout" 2> "$OUT/fixture.stderr" 134 rc=$?; echo "$rc" > "$OUT/fixture.rc" 135 [ "$rc" -eq 0 ] || fail fixture generation 136 FNV=$(sed -n 's/^fnv=//p' "$OUT/fixture.stdout") 137 printf '%s SYNTHETIC si19-orig2-fixture-seed%s-n%s\n' "$FNV" "$FIXSEED" "$FIXCOUNT" > "$BUILD/allow.txt" 138 RECFILE="$BUILD/fixture.rb"; ALLOWFILE="$BUILD/allow.txt" 139 note "records_source=SYNTHETIC fixture seed=$FIXSEED count=$FIXCOUNT fnv=$FNV" 140 fi 141 note "records_sha256=$(sha256sum "$RECFILE" | cut -d' ' -f1)" 142 143 if [ "$V2" = 1 ]; then 144 # Config: kind seed lr maxep patience ctrl stop flags; flags 14 = v2 + VALIDATION + HELD-OUT. 145 run v2_train_mlp T "2 $SEED 8 64 16 0 0 14" || fail v2_train_mlp 146 run v2_ctrl_shuffled T "2 $SEED 8 64 16 1 0 14" || fail v2_ctrl_shuffled 147 run v2_ctrl_untrained T "2 $SEED 8 0 16 0 0 14" || fail v2_ctrl_untrained 148 [ "$(kv v2_ctrl_untrained epochs)" = 0 ] || fail untrained control trained 149 [ "$(kv v2_ctrl_untrained final_params_fnv)" = "$(kv v2_train_mlp init_fnv)" ] || fail untrained control init differs 150 run v2_eval_mlp E "2 $SEED 8 64 16 0 0 14" "$BUILD/v2_train_mlp.img" || fail v2_eval_mlp 151 run v2_eval_shuffled E "2 $SEED 8 64 16 1 0 14" "$BUILD/v2_ctrl_shuffled.img" || fail v2_eval_shuffled 152 run v2_eval_untrained E "2 $SEED 8 0 16 0 0 14" "$BUILD/v2_ctrl_untrained.img" || fail v2_eval_untrained 153 # A v1 config over a v2 image is refused: 68 (image flag) or, on a file with records the 154 # v1 reader refuses (family 5 coverage records), 66 before the image is read. 155 run v2_cross_v1 E "2 $SEED 8 64 16 0 0 6" "$BUILD/v2_train_mlp.img" 156 rc=$?; [ "$rc" -eq 68 ] || [ "$rc" -eq 66 ] || fail v1 config accepted a v2 image 157 grep '^v2_admitted=' "$OUT/v2_eval_mlp.stdout" | tee -a "$SUM" 158 grep '^eval part=' "$OUT/v2_eval_mlp.stdout" "$OUT/v2_eval_shuffled.stdout" "$OUT/v2_eval_untrained.stdout" | tee -a "$SUM" 159 for f in v2_train_mlp v2_ctrl_shuffled v2_ctrl_untrained; do 160 note "image $f sha256=$(sha256sum "$BUILD/$f.img" | cut -c1-64) bytes=$(wc -c < "$BUILD/$f.img")" 161 done 162 (cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr *.records deps-check.txt selmain.readelf.txt) > "$OUT/raw.sha256" 163 (cd "$BUILD" && sha256sum -- *.img *.elf *.om 2> /dev/null) > "$OUT/build.sha256" 164 note "SI19_SELECT_V2_RUN_PASS" 165 exit 0 166 fi 167 168 # Learning-rate sweep (contract s.8: 2^-8, 2^-10, 2^-12 judged on DEV loss only; DEV loss 169 # sums are recorded here as evidence, the choice LR_AFF/LR_MLP is the operator's input). 170 for lr in 8 10 12; do 171 run "sweep_affine_lr$lr" T "1 $SEED $lr 64 16 0 0 2" || fail "sweep_affine_lr$lr" 172 run "sweep_mlp_lr$lr" T "2 $SEED $lr 64 16 0 0 2" || fail "sweep_mlp_lr$lr" 173 done 174 note "lr_choice affine=2^-$LR_AFF mlp=2^-$LR_MLP" 175 176 # Training, controls, partial + resume, evaluation. Config: kind seed lr maxep patience ctrl stop flags. 177 run train_affine T "1 $SEED $LR_AFF 64 16 0 0 7" || fail train_affine 178 run train_mlp T "2 $SEED $LR_MLP 64 16 0 0 7" || fail train_mlp 179 run ctrl_shuffled T "2 $SEED $LR_MLP 64 16 1 0 2" || fail ctrl_shuffled 180 run ctrl_noupdate T "2 $SEED 0 64 16 2 0 2" || fail ctrl_noupdate 181 [ "$(kv ctrl_noupdate final_params_fnv)" = "$(kv ctrl_noupdate init_fnv)" ] || fail no-update control changed params 182 [ "$(kv ctrl_noupdate updates)" -gt 0 ] || fail no-update control made no updates 183 note "ctrl_noupdate params_bit_identical=yes updates=$(kv ctrl_noupdate updates)" 184 run ctrl_untrained T "2 $SEED $LR_MLP 0 16 0 0 7" || fail ctrl_untrained 185 [ "$(kv ctrl_untrained epochs)" = 0 ] || fail untrained control trained 186 [ "$(kv ctrl_untrained final_params_fnv)" = "$(kv train_mlp init_fnv)" ] || fail untrained control init differs 187 for cut in 1 3; do 188 run "partial$cut" T "2 $SEED $LR_MLP 64 16 0 $cut 0" || fail "partial$cut" 189 run "resume$cut" R "2 $SEED $LR_MLP 64 16 0 0 7" "$BUILD/partial$cut.img" || fail "resume$cut" 190 { printf 'C'; cat "$BUILD/train_mlp.img" "$BUILD/resume$cut.img"; } | "$BUILD/selmain.elf" > "$OUT/compare$cut.stdout" 2> "$OUT/compare$cut.stderr" 191 rc=$?; echo "$rc" > "$OUT/compare$cut.rc" 192 note "compare$cut rc=$rc $(cat "$OUT/compare$cut.stdout")" 193 [ "$rc" -eq 0 ] || fail "resume$cut image differs" 194 cmp -s "$OUT/train_mlp.stdout" "$OUT/resume$cut.stdout" || fail "resume$cut report differs" 195 cmp -s "$OUT/train_mlp.records" "$OUT/resume$cut.records" || fail "resume$cut records differ" 196 done 197 note "resumed_report_identical=yes" 198 run eval_mlp E "2 $SEED $LR_MLP 64 16 0 0 6" "$BUILD/train_mlp.img" || fail eval_mlp 199 run eval_affine E "1 $SEED $LR_AFF 64 16 0 0 6" "$BUILD/train_affine.img" || fail eval_affine 200 run eval_shuffled E "2 $SEED $LR_MLP 64 16 1 0 6" "$BUILD/ctrl_shuffled.img" || fail eval_shuffled 201 run eval_untrained E "2 $SEED $LR_MLP 0 16 0 0 6" "$BUILD/ctrl_untrained.img" || fail eval_untrained 202 grep '^eval part=' "$OUT/eval_mlp.stdout" "$OUT/eval_affine.stdout" "$OUT/eval_shuffled.stdout" "$OUT/eval_untrained.stdout" | tee -a "$SUM" 203 204 # Negative controls on the process path. 205 { printf 'C'; cat "$BUILD/train_mlp.img" "$BUILD/partial1.img"; } | "$BUILD/selmain.elf" > "$OUT/compare_partial.stdout" 2>&1 206 [ "$?" -eq 1 ] || fail compare of different images did not refuse 207 cp "$BUILD/partial1.img" "$BUILD/damaged.img" 208 printf '\001' | dd of="$BUILD/damaged.img" bs=1 seek=5000 conv=notrunc 2> /dev/null 209 run resume_damaged R "2 $SEED $LR_MLP 64 16 0 0 0" "$BUILD/damaged.img" 210 [ "$?" -eq 65 ] || fail damaged image admitted 211 # An image cut short would shift the record stream (the image has a fixed length), so the 212 # truncated image is zero-padded back to the fixed length: the checksum must refuse it. 213 { head -c 11000 "$BUILD/partial1.img"; head -c 560 /dev/zero; } > "$BUILD/short.img" 214 run resume_short R "2 $SEED $LR_MLP 64 16 0 0 0" "$BUILD/short.img" 215 [ "$?" -eq 65 ] || fail truncated image admitted 216 cat "$OUT/compare_partial.stdout" "$OUT/resume_damaged.stdout" "$OUT/resume_short.stdout" | tee -a "$SUM" 217 run bad_config T "3 $SEED 10 64 16 0 0 0" 218 [ "$?" -eq 68 ] || fail invalid config accepted 219 GOODALLOW=$ALLOWFILE 220 sed 's/ SYNTHETIC / REVOKED /; s/ AUTHORIZED / REVOKED /' "$GOODALLOW" > "$BUILD/revoked.txt" 221 ALLOWFILE="$BUILD/revoked.txt" 222 run revoked T "2 $SEED $LR_MLP 1 16 0 0 0" 223 [ "$?" -eq 67 ] || fail revoked dataset admitted 224 printf '1 SYNTHETIC other\n' > "$BUILD/absent.txt" 225 ALLOWFILE="$BUILD/absent.txt" 226 run unlisted T "2 $SEED $LR_MLP 1 16 0 0 0" 227 [ "$?" -eq 67 ] || fail unlisted dataset admitted 228 ALLOWFILE=$GOODALLOW 229 cat "$OUT/revoked.stdout" "$OUT/unlisted.stdout" | tee -a "$SUM" 230 231 if [ -z "$RECORDS" ]; then 232 # Fault injection: each altered unit must compile and fail the unchanged test. 233 # FILE|ORIGINAL LINE|ALTERED LINE; the original must occur exactly once. 234 i=0 235 while IFS='|' read -r file orig alt; do 236 [ -n "$file" ] || continue 237 i=$((i + 1)) 238 src="$N/$file" 239 n=$(grep -c -x -F -- "$orig" "$src") 240 [ "$n" -eq 1 ] || fail "mutant$i matches $n" 241 mdir="$BUILD/mutant$i"; mkdir -p "$mdir" 242 awk -v o="$orig" -v a="$alt" '$0 == o { print a; next } { print }' "$src" > "$mdir/$file" 243 mlib="" 244 for f in $LIB; do 245 if [ "$(basename "$f")" = "$file" ]; then mlib="$mlib $mdir/$file"; else mlib="$mlib $f"; fi 246 done 247 build "mutant$i" "$ROOT/tests/si19/select-test.om" $mlib || fail "mutant$i compile" 248 "$BUILD/mutant$i.elf" > "$OUT/mutant$i.stdout" 2> "$OUT/mutant$i.stderr" 249 rc=$? 250 echo "$rc" > "$OUT/mutant$i.rc" 251 note "mutant$i $file rc=$rc $(cat "$OUT/mutant$i.stdout") :: $alt" 252 [ "$rc" -eq 1 ] || fail "mutant$i survived" 253 done <<'EOF' 254 select.om|d = add32 get SZ 20 xor y `2147483648`|d = add32 get SZ 20 y 255 select.om|ret and eq and x `2147483648` 0 ne x 0|ret eq and x `2147483648` 0 256 select.om|v = add32 get SP i xor mul32 lr get SG i `2147483648`|v = add32 get SP i mul32 lr get SG i 257 select.om|ret eq siget add base 104 get RC 2|ret true 258 select.om|put SS 5 c|put SS 5 0 259 select.om|put SX p get SX k|put SX p p 260 select.om|if ne oxpart r 0|if gt oxpart r 1 261 select.om|if gt siget add base 176 1|if gt siget add base 176 2 262 EOF 263 fi 264 265 (cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr *.records deps-check.txt selmain.readelf.txt) > "$OUT/raw.sha256" 266 (cd "$BUILD" && sha256sum -- *.img *.elf *.om allow.txt fixture.rb 2> /dev/null) > "$OUT/build.sha256" 267 note "SI19_SELECT_RUN_PASS"