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/omegallm/v1-oracle.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 / omegallm / v1-oracle.sh` 336 lines · 16173 bytes Raw Blame History 1 #!/bin/sh 2 # Omega LLM v1 referee checks (CONTRACT-V1 §9.2-§9.5): the `ollm` binary against oracle.py. 3 # 4 # BIN=path/to/ollm sh tests/omegallm/v1-oracle.sh 5 # 6 # Environment: 7 # BIN aarch64 v1 ollm binary; unset = referee outputs only, binary cases NOT_RUN 8 # DATA directory holding TinyStoriesV2-GPT4-valid.txt (default: ../../data from here) 9 # WORK scratch directory (default: scratch-v1-oracle beside the clone); ref/ and bin/ are rebuilt 10 # CORE core for taskset (default 8); every process runs at nice 19 11 # MUTANT planted referee defect (oracle.py MUTANTS); the run must then report FAIL lines 12 # V0BIN optional v0 ollm binary for the V = 256 CK01 identity case (§9.4) 13 # EXT_MERGES EXT_V EXT_TEXT EXT_TOK optional: referee-encode EXT_TEXT with EXT_MERGES at EXT_V 14 # and compare with the product's token file EXT_TOK byte for byte 15 # 16 # One PASS/FAIL/NOT_RUN line per case, then `SUMMARY pass=N fail=M not_run=K`; exit 0 iff fail=0. 17 # Tokenizer outputs and init are compared byte for byte; grad and one train step per entry within 18 # the v0 tolerance (ORACLE.md "Tolerance"); printed micro integers exactly. 19 set -u 20 here=$(cd "$(dirname "$0")" && pwd) 21 ORACLE="$here/oracle.py" 22 DATA=${DATA:-$here/../../data} 23 WORK=${WORK:-$here/../../../scratch-v1-oracle} 24 CORE=${CORE:-8} 25 MUTANT=${MUTANT:-} 26 BIN=${BIN:-} 27 V0BIN=${V0BIN:-} 28 VALID="$DATA/TinyStoriesV2-GPT4-valid.txt" 29 RUN="taskset -c $CORE nice -n 19" 30 # every helper (cmp, python3 -c, sha256sum) runs on the same core too 31 if [ -z "${V1_ORACLE_PINNED:-}" ]; then 32 V1_ORACLE_PINNED=1 exec taskset -c "$CORE" nice -n 19 sh "$0" "$@" 33 fi 34 export PYTHONDONTWRITEBYTECODE=1 35 export OLLM_ORACLE_MUTANT="$MUTANT" 36 37 [ -r "$VALID" ] || { echo "v1-oracle: cannot read $VALID (set DATA)" >&2; exit 2; } 38 mkdir -p "$WORK" 39 WORK=$(cd "$WORK" && pwd) 40 REF="$WORK/ref" 41 GOT="$WORK/bin" 42 rm -rf "$REF" "$GOT" "$WORK/tmp" 43 mkdir -p "$REF" "$GOT" "$WORK/tmp" 44 export OLLM_TMP="$WORK/tmp" 45 if [ -n "$BIN" ]; then 46 BIN=$(cd "$(dirname "$BIN")" && pwd)/$(basename "$BIN") 47 [ -x "$BIN" ] || { echo "v1-oracle: BIN $BIN is not executable" >&2; exit 2; } 48 fi 49 if [ -n "$V0BIN" ]; then 50 V0BIN=$(cd "$(dirname "$V0BIN")" && pwd)/$(basename "$V0BIN") 51 [ -x "$V0BIN" ] || { echo "v1-oracle: V0BIN $V0BIN is not executable" >&2; exit 2; } 52 fi 53 echo "v1-oracle: bin=${BIN:-none} mutant=${MUTANT:-none} core=$CORE" 54 55 pass=0 fail=0 notrun=0 56 ok() { echo "PASS $1${2:+ ($2)}"; pass=$((pass + 1)); } 57 ko() { echo "FAIL $1${2:+ ($2)}" | sed "s|$WORK/||g"; fail=$((fail + 1)); } 58 nr() { echo "NOT_RUN $1${2:+ ($2)}"; notrun=$((notrun + 1)); } 59 60 # r DIR TAG CMD...: run CMD in DIR; stdout -> TAG.out, stderr -> TAG.err, exit code -> TAG.rc 61 r() { 62 _d=$1 _t=$2 63 shift 2 64 (cd "$_d" && $RUN "$@" >"$_t.out" 2>"$_t.err"; echo $? >"$_t.rc") 65 } 66 ref() { _t=$1; shift; r "$REF" "$_t" python3 "$ORACLE" ollm "$@"; } 67 got() { _t=$1; shift; [ -n "$BIN" ] && r "$GOT" "$_t" "$BIN" "$@"; return 0; } 68 both() { ref "$@"; got "$@"; } 69 py() { $RUN python3 "$ORACLE" "$@"; } 70 71 # chk NAME TAG RC [FILE|!FILE]...: the referee must exit RC; the binary must match its exit code, 72 # stdout bytes and each FILE byte for byte (!FILE: must not exist on either side). 73 chk() { 74 _n=$1 _t=$2 _rc=$3 75 shift 3 76 _rr=$(cat "$REF/$_t.rc") 77 [ "$_rr" = "$_rc" ] || { ko "$_n" "referee exit $_rr, want $_rc: $(cat "$REF/$_t.err" | tail -n 1)"; return; } 78 for _f; do 79 case $_f in !*) [ ! -e "$REF/${_f#!}" ] || { ko "$_n" "referee left ${_f#!}"; return; } ;; esac 80 done 81 [ -n "$BIN" ] || { nr "$_n" "no BIN"; return; } 82 _gr=$(cat "$GOT/$_t.rc") 83 [ "$_gr" = "$_rr" ] || { ko "$_n" "exit $_gr, want $_rr"; return; } 84 _d=$(cmp "$GOT/$_t.out" "$REF/$_t.out" 2>&1) || { ko "$_n" "stdout: $_d; got '$(head -c 80 "$GOT/$_t.out")' want '$(head -c 80 "$REF/$_t.out")'"; return; } 85 for _f; do 86 case $_f in 87 !*) [ ! -e "$GOT/${_f#!}" ] || { ko "$_n" "binary left ${_f#!}"; return; } ;; 88 *) _d=$(cmp "$GOT/$_f" "$REF/$_f" 2>&1) || { ko "$_n" "$_f: $_d"; return; } ;; 89 esac 90 done 91 ok "$_n" "exit $_rr${1:+, files checked}" 92 } 93 94 # tol NAME KIND GOTFILE REFFILE: oracle.py cmp (header exact, payload within rtol) 95 tol() { 96 _o=$(py cmp "$2" "$3" "$4" 2>&1) 97 _l=$(printf '%s\n' "$_o" | tail -n 1) 98 case $_l in PASS*) ok "$1" "max relerr $(printf '%s\n' "$_o" | grep 'max relerr' | awk '{printf "%s=%s ", $2, $5}')" ;; 99 *) ko "$1" "$(printf '%s\n' "$_o" | tr '\n' ' ')" ;; esac 100 } 101 102 wr() { python3 -c "import sys,struct; open(sys.argv[1],'wb').write($2)" "$1"; } 103 104 # ---------------------------------------------------------------- referee self-test 105 o=$(py selftest-v1 2>&1) 106 case $(printf '%s\n' "$o" | tail -n 1) in 107 *PASS*) ok referee-selftest-v1 ;; 108 *) ko referee-selftest-v1 "$(printf '%s\n' "$o" | grep FAIL | tr '\n' ';')" ;; 109 esac 110 111 # ---------------------------------------------------------------- tokenizer (§2, §9.2) 112 both prep prep "$VALID" train.bin held.bin 113 chk prep prep 0 train.bin held.bin 114 both fit512 bpefit train.bin merges512.bin 512 115 chk fit512 fit512 0 merges512.bin 116 both fit300mb bpefit train.bin m300mb.bin 300 `1000000` 117 chk fit300-maxbytes fit300mb 0 m300mb.bin 118 for d in "$REF" "$GOT"; do 119 wr "$d/tie.txt" "b'ab cd ef\\0ab cd ef\\0'" 120 wr "$d/no0.txt" "b'abc def ghi'" 121 wr "$d/edge.txt" "b' x'+b'A'*150+b' '+'caf\\u00e9 na\\u00efve \\u65e5\\u672c'.encode()+b'!!? 9z 3.14\\t\\r\\n\\0'+b' the end\\0'*3" 122 done 123 both fittie bpefit tie.txt tie.bin 261 124 chk fit-tie fittie 0 tie.bin 125 # known answer, independent of the binary: pairs (32,99) (32,101) (97,98) (256,100) (257,102) 126 want=$(python3 -c "import struct; b=struct.pack('<10H',32,99,32,101,97,98,256,100,257,102); print(b.hex())") 127 have=$(python3 -c "import sys; print(open(sys.argv[1],'rb').read()[24:].hex())" "$REF/tie.bin" 2>/dev/null) 128 [ "$want" = "$have" ] && ok fit-tie-kat "smallest a, then smallest b" || ko fit-tie-kat "referee merges $have, want $want" 129 both fittie28 bpefit tie.txt tie28.bin 262 130 chk fit-out-of-pairs fittie28 28 '!tie28.bin' 131 both fit21 bpefit no0.txt no0.bin 300 5 132 chk fit-maxbytes-no-0 fit21 21 '!no0.bin' 133 both fitedge bpefit edge.txt edge.bin 280 134 chk fit-edge fitedge 0 edge.bin 135 both enc512 bpeenc merges512.bin 512 train.bin train512.tok 136 chk enc512-train enc512 0 train512.tok 137 both enc512h bpeenc merges512.bin 512 held.bin held512.tok 138 chk enc512-held enc512h 0 held512.tok 139 both enc300 bpeenc merges512.bin 300 train.bin train300.tok 140 chk enc300-train enc300 0 train300.tok 141 both enc300h bpeenc merges512.bin 300 held.bin held300.tok 142 chk enc300-held enc300h 0 held300.tok 143 both encedge bpeenc edge.bin 280 edge.txt edge.tok 144 chk enc-edge encedge 0 edge.tok 145 both dec512 bpedec merges512.bin train512.tok train.dec 146 chk dec512-train dec512 0 train.dec 147 for d in "$REF" "$GOT"; do [ -e "$d/train.dec" ] && ! cmp -s "$d/train.dec" "$d/train.bin" && echo " decode != text in $d"; done 148 if cmp -s "$REF/train.dec" "$REF/train.bin" && { [ -z "$BIN" ] || cmp -s "$GOT/train.dec" "$GOT/train.bin"; }; then 149 ok roundtrip "decode(encode(train)) == train" 150 else ko roundtrip "decode(encode(train)) != train"; fi 151 # negative control (§9.2): one pair altered (merge 100 -> (101, 32)), file rehashed; tokens change 152 for d in "$REF" "$GOT"; do 153 python3 -c " 154 import sys, struct 155 sys.path.insert(0, sys.argv[3]); import oracle 156 raw = bytearray(open(sys.argv[1], 'rb').read()) 157 struct.pack_into('<2H', raw, 24 + 4 * 100, 101, 32) 158 struct.pack_into('"$d/odd.tok" 170 wr "$d/big.tok" "struct.pack('<4H', 72, 105, 600, 33)" 171 done 172 both r26 bpeenc badhash.bin 512 held.bin r26.tok 173 chk merges-hash-26 r26 26 '!r26.tok' 174 both r27 bpeenc merges512.bin 513 held.bin r27.tok 175 chk v-over-merges-27 r27 27 '!r27.tok' 176 both r27b bpeenc merges512.bin 256 held.bin r27b.tok 177 chk bpeenc-v256-27 r27b 27 '!r27b.tok' 178 both r21 bpedec merges512.bin odd.tok odd.dec 179 chk odd-token-file-21 r21 21 180 both r25 bpedec merges512.bin big.tok big.dec 181 chk token-over-v-25 r25 25 182 if [ -n "${EXT_MERGES:-}" ]; then 183 ref ext bpeenc "$EXT_MERGES" "$EXT_V" "$EXT_TEXT" ext.tok 184 if [ "$(cat "$REF/ext.rc")" != 0 ]; then ko ext-enc "referee exit $(cat "$REF/ext.rc")" 185 elif d=$(cmp "$EXT_TOK" "$REF/ext.tok" 2>&1); then ok ext-enc "$(cat "$REF/ext.out")" 186 else ko ext-enc "$d"; fi 187 fi 188 189 # ---------------------------------------------------------------- model (§4-§7, §9.3-§9.5) 190 TR="$REF/train300.tok" 191 HE="$REF/held300.tok" 192 M5="$REF/merges512.bin" 193 CFG="300 8 16 2 32 2 4 5 50 3000" 194 both init2 init init2.ck $CFG 2 195 chk init-ck02-g2 init2 0 init2.ck 196 both init1 init init1.ck $CFG 197 chk init-ck01 init1 0 init1.ck 198 both init4 init init4.ck $CFG 4 199 chk init-ck02-g4 init4 0 init4.ck 200 both initg3 init g3.ck $CFG 3 201 chk init-g3-12 initg3 12 '!g3.ck' 202 # shape limits (CONTRACT-V2 §1, CONTRACT-V3 §1): one over each maximum is refused with 12; D and F 203 # at their v2 maxima and L at its v3 maximum init byte-identically 204 for s in "4097 8 16 2 32 2 4" "300 257 16 2 32 2 4" "300 8 386 2 32 2 4" "300 8 34 17 32 2 4" \ 205 "300 8 16 2 1537 2 4" "300 8 16 2 32 17 4" "300 8 16 2 32 2 65"; do 206 both lim init lim.ck $s 5 50 3000 207 chk "limit-12 [$s]" lim 12 '!lim.ck' 208 done 209 both limx init limx.ck 300 8 384 12 1536 2 4 5 50 3000 210 chk "limit-max-d384-f1536" limx 0 limx.ck 211 both liml init liml.ck 300 8 16 2 32 16 4 5 50 3000 212 chk "limit-max-l16" liml 0 liml.ck 213 # the whole v3 maximum (P 29,995,392; 719,889,528-byte checkpoint, deleted after the compare) 214 both limv3 init limv3.ck 4096 256 384 12 1536 16 64 1 30000 3000 16 215 chk "limit-max-v3" limv3 0 limv3.ck 216 rm -f "$REF/limv3.ck" "$GOT/limv3.ck" 217 for d in "$REF" "$GOT"; do wr "$d/offs" "struct.pack('<4Q', 0, 777777, `5000000`, `13000000`)"; done 218 for g in 2 4; do 219 both grad$g grad init$g.ck "$TR" offs g$g.gr 220 if [ "$(cat "$REF/grad$g.rc")" != 0 ]; then ko "grad-g$g" "referee exit $(cat "$REF/grad$g.rc")" 221 elif [ -z "$BIN" ]; then nr "grad-g$g" "no BIN" 222 elif [ "$(cat "$GOT/grad$g.rc")" != 0 ]; then ko "grad-g$g" "exit $(cat "$GOT/grad$g.rc")" 223 else 224 o=$(py cmp gline "$GOT/grad$g.out" "$REF/grad$g.out") 225 case $o in PASS*) tol "grad-g$g" gr "$GOT/g$g.gr" "$REF/g$g.gr" ;; *) ko "grad-g$g" "$o" ;; esac 226 fi 227 done 228 # referee-only run (deliverable): 20 steps EVERY 5 from the referee's init, eval and samples 229 cp "$REF/init2.ck" "$REF/ref20.ck" 230 ref tr20 train ref20.ck "$TR" 20 5 231 ref ev20 eval ref20.ck "$HE" 4 "$M5" 232 ref s0 sample ref20.ck 7 40 0 "Once upon a time" "$M5" 233 ref s800 sample ref20.ck 7 40 800 "Once upon a time" "$M5" 234 for t in tr20 ev20 s0 s800; do 235 [ "$(cat "$REF/$t.rc")" = 0 ] || ko "referee-$t" "exit $(cat "$REF/$t.rc")" 236 done 237 # §9.3: one train step per call from the binary's own checkpoints 238 if [ -z "$BIN" ]; then nr train-chain-20 "no BIN" 239 else 240 cp "$GOT/init2.ck" "$GOT/c0.ck" 241 bad= 242 s=1 243 while [ $s -le 20 ]; do 244 cp "$GOT/c$((s - 1)).ck" "$GOT/c$s.ck" 245 cp "$GOT/c$((s - 1)).ck" "$REF/c$s.ck" 246 both ts$s train c$s.ck "$TR" $s 1 247 if [ "$(cat "$GOT/ts$s.rc")" != 0 ] || ! cmp -s "$GOT/ts$s.out" "$REF/ts$s.out"; then 248 bad="step $s: got '$(cat "$GOT/ts$s.out")' rc $(cat "$GOT/ts$s.rc"), want '$(cat "$REF/ts$s.out")'" 249 break 250 fi 251 o=$(py cmp ck "$GOT/c$s.ck" "$REF/c$s.ck") 252 case $(printf '%s\n' "$o" | tail -n 1) in PASS*) ;; *) bad="step $s: $(printf '%s\n' "$o" | tr '\n' ' ')"; break ;; esac 253 s=$((s + 1)) 254 done 255 [ -z "$bad" ] && ok train-chain-20 "T lines exact, ck within rtol at every step" || ko train-chain-20 "$bad" 256 fi 257 # §9.4 workers: one process, 20 steps, K = 1 and K = 2 258 if [ -z "$BIN" ]; then nr workers-k1-k2 "no BIN"; nr workers-tlines "no BIN" 259 else 260 cp "$GOT/init2.ck" "$GOT/k1.ck" 261 cp "$GOT/init2.ck" "$GOT/k2.ck" 262 got trk1 train k1.ck "$TR" 20 5 1 263 got trk2 train k2.ck "$TR" 20 5 2 264 if [ "$(cat "$GOT/trk1.rc")$(cat "$GOT/trk2.rc")" != 00 ]; then ko workers-k1-k2 "exit $(cat "$GOT/trk1.rc") $(cat "$GOT/trk2.rc")" 265 elif d=$(cmp "$GOT/k2.ck" "$GOT/k1.ck" 2>&1) && d=$(cmp "$GOT/k1.ck" "$GOT/c20.ck" 2>&1); then 266 ok workers-k1-k2 "K=1, K=2 and the 20-call chain byte-identical" 267 else ko workers-k1-k2 "$d"; fi 268 if cmp -s "$GOT/trk1.out" "$REF/tr20.out" && cmp -s "$GOT/trk2.out" "$REF/tr20.out"; then 269 ok workers-tlines "T lines = referee" 270 else ko workers-tlines "got '$(cat "$GOT/trk1.out" | tr '\n' ';')' want '$(cat "$REF/tr20.out" | tr '\n' ';')'"; fi 271 fi 272 both k3 train init2.ck "$TR" 1 1 3 273 chk bad-k3-29 k3 29 274 both k0 train init2.ck "$TR" 1 1 0 275 chk bad-k0-29 k0 29 276 # eval and sample on the binary's 20-step checkpoint (the referee's when no BIN) 277 if [ -n "$BIN" ]; then cp "$GOT/c20.ck" "$GOT/b20.ck"; cp "$GOT/c20.ck" "$REF/b20.ck" 278 else cp "$REF/ref20.ck" "$REF/b20.ck"; fi 279 both evb eval b20.ck "$HE" 4 "$M5" 280 chk eval-w4-bpb evb 0 281 both evnom eval b20.ck "$HE" 4 282 chk eval-no-merges-2 evnom 2 283 both evw eval b20.ck "$HE" 999999 "$M5" 284 chk eval-w-23 evw 23 285 both sb0 sample b20.ck 7 40 0 "Once upon a time" "$M5" 286 chk sample-t0 sb0 0 287 both sb800 sample b20.ck 7 40 800 "Once upon a time" "$M5" 288 chk sample-t800 sb800 0 289 both snom sample b20.ck 7 40 0 "Once" 290 chk sample-no-merges-2 snom 2 291 # data refusals (tokens checked lazily: only rows actually read) 292 for d in "$REF" "$GOT"; do 293 head -c 4001 "$TR" >"$d/odd300.tok" 294 head -c 16 "$TR" >"$d/short.tok" 295 wr "$d/bad.tok" "struct.pack('<200H', *[400 if i == 100 else 5 + i % 200 for i in range(200)])" 296 wr "$d/offs-bad" "struct.pack('<4Q', 0, 10, 20, 95)" 297 wr "$d/offs-good" "struct.pack('<4Q', 0, 10, 20, 30)" 298 wr "$d/offs-22" "struct.pack('<4Q', 0, 10, 20, 192)" 299 wr "$d/offs-21" "struct.pack('<3Q', 0, 10, 20)" 300 done 301 both d21 train init2.ck odd300.tok 1 1 302 chk data-odd-21 d21 21 303 both d20 train init2.ck short.tok 1 1 304 chk data-short-20 d20 20 305 both d25 grad init2.ck bad.tok offs-bad d25.gr 306 chk data-token-25 d25 25 '!d25.gr' 307 both dlazy grad init2.ck bad.tok offs-good dlazy.gr 308 if [ "$(cat "$REF/dlazy.rc")" != 0 ]; then ko data-lazy "referee exit $(cat "$REF/dlazy.rc")" 309 elif [ -z "$BIN" ]; then nr data-lazy "no BIN" 310 elif [ "$(cat "$GOT/dlazy.rc")" != 0 ]; then ko data-lazy "exit $(cat "$GOT/dlazy.rc")" 311 else tol data-lazy gr "$GOT/dlazy.gr" "$REF/dlazy.gr"; fi 312 both o22 grad init2.ck bad.tok offs-22 o22.gr 313 chk offs-22 o22 22 314 both o21 grad init2.ck bad.tok offs-21 o21.gr 315 chk offs-size-21 o21 21 316 # §9.4 V = 256: a CK01 trained by the v1 binary equals the v0 binary's after 20 steps 317 if [ -z "$BIN" ] || [ -z "$V0BIN" ]; then nr v0-v1-ck01 "needs BIN and V0BIN" 318 else 319 r "$GOT" v0i "$V0BIN" init v0.ck 256 8 16 2 32 2 2 5 50 3000 320 got v1i init v1.ck 256 8 16 2 32 2 2 5 50 3000 321 if ! d=$(cmp "$GOT/v1.ck" "$GOT/v0.ck" 2>&1); then ko v0-v1-ck01 "init: $d" 322 else 323 r "$GOT" v0t "$V0BIN" train v0.ck "$REF/held.bin" 20 5 324 got v1t train v1.ck "$REF/held.bin" 20 5 325 if d=$(cmp "$GOT/v1.ck" "$GOT/v0.ck" 2>&1) && cmp -s "$GOT/v1t.out" "$GOT/v0t.out"; then 326 ok v0-v1-ck01 "init and 20 steps byte-identical, T lines equal" 327 else ko v0-v1-ck01 "${d:-T lines differ}"; fi 328 fi 329 fi 330 331 # referee outputs and their hashes 332 (cd "$REF" && sha256sum prep.out train.bin held.bin fit512.out merges512.bin train512.tok held512.tok \ 333 train300.tok held300.tok m300mb.bin tie.bin edge.bin edge.tok init2.ck init1.ck init4.ck \ 334 offs grad2.out g2.gr grad4.out g4.gr tr20.out ref20.ck ev20.out s0.out s800.out >SHA256SUMS 2>/dev/null) 335 echo "SUMMARY pass=$pass fail=$fail not_run=$notrun" 336 [ "$fail" = 0 ]