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/aienux/blob/main/native/om/lm1b/gate.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. 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 `aienux / native / om / lm1b / gate.sh` 139 lines ยท 8661 bytes Raw Blame History 1 #!/bin/sh 2 # gate.sh: rebuild lm1b from a clean checkout and judge it against the Rust reference. 3 # Existing-tool class (POSIX sh, awk, sha256sum, cmp, cargo for the reference). Prints RC=0 when 4 # every check passes, RC=1 otherwise. Raw logs go to out/gate/ (not committed). 5 # OMC seed-born Omega compiler (default ~/workspace/arch314/omega-mv/seed/out/omc) 6 # MODEL pinned GGUF (default ~/models/aien-mail/Llama-3.2-1B-Instruct-Q4_K_M.gguf) 7 set -u 8 HERE=$(cd "$(dirname "$0")" && pwd) 9 ROOT=$(cd "$HERE/../../.." && pwd) 10 OMC=${OMC:-$HOME/workspace/arch314/omega-mv/seed/out/omc} 11 MODEL=${MODEL:-$HOME/models/aien-mail/Llama-3.2-1B-Instruct-Q4_K_M.gguf} 12 OMC_SHA=`734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61` 13 MODEL_SHA=`3f5a22426976ab26cfe84dba63c1d08391717abb1af893e10f1b2968d862dcc1` 14 EOS=128009 15 O=$HERE/out/gate 16 rm -rf "$O" 17 mkdir -p "$O" 18 FAILS="" 19 pass() { echo "PASS $1"; } 20 fail() { echo "FAIL $1: $2"; FAILS="$FAILS $1"; } 21 check() { if [ "$2" = "$3" ]; then pass "$1"; else fail "$1" "want [$3] got [$2]"; fi; } 22 23 # 1. pinned inputs 24 check omc-sha "$(sha256sum "$OMC" | cut -d' ' -f1)" "$OMC_SHA" 25 check model-sha "$(sha256sum "$MODEL" | cut -d' ' -f1)" "$MODEL_SHA" 26 27 # 2. the committed program is exactly what the generator makes from the template 28 cp "$HERE/lm1b.om" "$O/lm1b.committed.om" 29 sh "$HERE/gen.sh" > "$O/gen.log" 2>&1 || fail gen "gen.sh failed" 30 if cmp -s "$HERE/lm1b.om" "$O/lm1b.committed.om"; then pass gen-in-sync; else fail gen-in-sync "lm1b.om differs from gen.sh output"; fi 31 32 # 3. no host words the boot fixture will not provide (arguments, environment, clocks, other services) 33 BAD=$(grep -v '^note' "$HERE/lm1b.om" | tr ' ' '\n' | grep -x -E 'argcnt|argread|envcnt|envread|monons|realns|sleepns|fopen|fclose|fsync|fdsync|memfd|fchmod|chmod|chown|faccess|getuid|geteuid|getgid|getegid|fchdir|getppid|setsid|getpgid|getsid|syncfs|shutdown|setpgid|umask|fseek|ftrunc|truncate|unlink|makedir|rmdir|cwd|chdir|readlnk|getdnts|fstat|stat|lstat|renames|link|symlnk|socknew|bind|connect|listen|accept|sockname|sockopt|recv|send|waitio|fork|getpid|killpid|waitpid|pipefds|dupfd|execprog|random|pwrite|devctl|mapnew|mapdrop|mapread|mapwrite' | sort -u | tr '\n' ' ') 34 check host-words "$BAD" "" 35 36 # 4. compile; the ELF must hold only read 63, write 64, pread64 67 and exit 93 service numbers 37 "$OMC" < "$HERE/lm1b.om" > "$O/lm1b" 2> "$O/omc.err" 38 check compile "$?" 0 39 chmod +x "$O/lm1b" 40 sha256sum "$O/lm1b" | cut -d' ' -f1 > "$O/lm1b.sha256" 41 objdump -D -b binary -maarch64 "$O/lm1b" > "$O/lm1b.dis" 2>&1 42 SVC=$(awk '/mov\tx8, #/{split($0,a,"// #"); v=a[2]+0; last=NR} /\tsvc\t/{ if (NR-last<=4) print v; else print "unknown" }' "$O/lm1b.dis" | sort -u -n | tr '\n' ' ') 43 check svc-numbers "$SVC" "63 64 67 93 " 44 45 # 5. the pinned manifest agrees with the reference parser (an independent reader of the same file) 46 ( cd "$HERE/oracle/manifest-dump" && cargo build --release -q ) > "$O/oracle-build.log" 2>&1 47 "$HERE/oracle/manifest-dump/target/release/lm1b-manifest-dump" "$MODEL" > "$O/manifest.ref.txt" 2>&1 48 if cmp -s "$O/manifest.ref.txt" "$HERE/manifest.txt"; then pass manifest-oracle; else fail manifest-oracle "reference parser output differs"; fi 49 50 # 6. reference runs (aienos-infer plain f32 path, logit bits on) 51 ( cd "$ROOT" && cargo build --release -q --example model_probe -p aienos-infer ) > "$O/probe-build.log" 2>&1 52 P=$ROOT/target/release/examples/model_probe 53 for p in cow rainbow; do 54 AIENOS_BITS=1 "$P" "$MODEL" "$HERE/prompts/$p.txt" 8 $EOS > "$O/ref-$p.txt" 2>&1 55 awk '$1=="step"{t=t" "$3} $1=="bits"{b=b" "$3} END{print "tokens" t; print "bits" b}' "$O/ref-$p.txt" > "$O/ref-$p.want" 56 done 57 58 # helpers over lm1b output 59 jtok() { awk -v j="$2" '$1=="job" && $2==j && $3=="status" {f=1; s=""; for(i=7;i<=NF;i++) s=s" "$i; print "tokens" substr(s, index(s,"tokens")+6); next} f && $1=="bits" {print; f=0}' "$1"; } 60 jline() { awk -v j="$2" '$1=="job" && $2==j {print; exit}' "$1"; } 61 62 # 7. three jobs in one process: cow, rainbow, cow again 63 "$O/lm1b" 3< "$MODEL" < "$HERE/prompts/main-jobs.txt" > "$O/main.out" 2> "$O/main.err" 64 check main-exit "$?" 0 65 check main-load "$(head -1 "$O/main.out")" "load ok bytes `807694368` tensors 147 sha256 $MODEL_SHA passes 0" 66 check job1-vs-ref "$(jtok "$O/main.out" cow1)" "$(cat "$O/ref-cow.want")" 67 check job2-vs-ref "$(jtok "$O/main.out" rain)" "$(cat "$O/ref-rainbow.want")" 68 check job3-eq-job1 "$(jtok "$O/main.out" cow3)" "$(jtok "$O/main.out" cow1)" 69 check job1-status "$(jline "$O/main.out" cow1 | cut -d' ' -f3-6)" "status ok passes 26" 70 check job3-acct "$(grep '^acct job cow3' "$O/main.out" | cut -d' ' -f4-)" "$(grep '^acct job cow1' "$O/main.out" | cut -d' ' -f4-)" 71 72 # 8. negative controls 73 # 8a. one flipped byte in the tensor data: load refused (digest) 74 cp "$MODEL" "$O/flipped.gguf" 75 printf '\377' | dd of="$O/flipped.gguf" bs=1 seek=`400000000` count=1 conv=notrunc 2> /dev/null 76 "$O/lm1b" 3< "$O/flipped.gguf" < /dev/null > "$O/flip.out" 2>&1 77 RCF=$? 78 rm -f "$O/flipped.gguf" 79 check flip-refused "$(cat "$O/flip.out") rc=$RCF" "load refused reason sha256 rc=3" 80 # 8b. a copy of the program whose manifest names the wrong type for one tensor: load refused 81 sed 's/t blk.0.attn_k.weight 12 2 2048 512/t blk.0.attn_k.weight 14 2 2048 512/' "$HERE/lm1b.om" > "$O/wrongtype.om" 82 check wrongtype-edited "$(cmp -s "$HERE/lm1b.om" "$O/wrongtype.om"; echo $?)" 1 83 "$OMC" < "$O/wrongtype.om" > "$O/wrongtype" && chmod +x "$O/wrongtype" 84 "$O/wrongtype" 3< "$MODEL" < /dev/null > "$O/wrongtype.out" 2>&1 85 RCW=$? 86 check wrongtype-refused "$(cat "$O/wrongtype.out") rc=$RCW" "load refused reason manifest rc=3" 87 # 8c. refusals keep serving; a budget too small cancels at a step boundary; the next job is correct 88 C=$(sed 's/^ids //' "$HERE/prompts/cow.txt") 89 LONG=$(awk 'BEGIN{for(i=0;i<257;i++) printf " 9"; print ""}') 90 L250=$(awk 'BEGIN{for(i=0;i<250;i++) printf " 9"; print ""}') 91 { 92 echo "job big gen 1 budget 9 stop $EOS fault 0 ids$LONG" 93 echo "job ctx gen 8 budget 9 stop $EOS fault 0 ids$L250" 94 echo "job bad gen 1 budget 9 stop $EOS fault 0 ids 128256" 95 echo "job two spaces" 96 echo "hello" 97 echo "job b1 gen 8 budget 5 stop $EOS fault 0 ids $C" 98 echo "job b2 gen 2 budget 1000 stop $EOS fault 0 ids $C" 99 } > "$O/neg-jobs.txt" 100 "$O/lm1b" 3< "$MODEL" < "$O/neg-jobs.txt" > "$O/neg.out" 2> "$O/neg.err" 101 check neg-exit "$?" 0 102 check over-limit "$(jline "$O/neg.out" big)" "job big status refused reason toomany" 103 check over-context "$(jline "$O/neg.out" ctx)" "job ctx status refused reason context" 104 check bad-id "$(jline "$O/neg.out" bad)" "job bad status refused reason badid" 105 check malformed "$(grep -c '^job ? status refused reason syntax$' "$O/neg.out")" 2 106 check budget-cancel "$(jline "$O/neg.out" b1)" "job b1 status cancelled passes 5 tokens" 107 check after-cancel "$(jtok "$O/neg.out" b2)" "$(awk 'NR==1{print $1" "$2" "$3} NR==2{print $1" "$2" "$3}' "$O/ref-cow.want")" 108 # 8d. fault 1: the process traps in the middle of the job (exit 100 + 12) 109 echo "job f1 gen 2 budget 1000 stop $EOS fault 1 ids $C" > "$O/fault-jobs.txt" 110 "$O/lm1b" 3< "$MODEL" < "$O/fault-jobs.txt" > "$O/fault.out" 2> "$O/fault.err" 111 check fault-exit "$?" 112 112 check fault-no-reply "$(grep -c '^job f1' "$O/fault.out")" 0 113 # 8e. omc bounds-checks every get and put on a global in these bytes (aienux#481): rowcp's pool split assumes the next 114 # pool is long enough, and the fallback is Omega's per-access trap 3 (exit 103). Three copies of the program differ 115 # from lm1b.om in one line of fn mv: a row read past the end of the last pool (m48 holds 2,388,000 bytes), a row copy 116 # one byte longer than rb, and a control that rewrites the same line with the same value. The two out-of-range copies 117 # must trap with no reply; the control must answer like the reference. 118 bvar() { 119 sed "s/^$2\$/$3/" "$HERE/lm1b.om" > "$O/$1.om" 120 check "$1-edited" "$(cmp -s "$HERE/lm1b.om" "$O/$1.om"; echo $?)" 1 121 "$OMC" < "$O/$1.om" > "$O/$1" 2> "$O/$1.err" 122 check "$1-compile" "$?" 0 123 chmod +x "$O/$1" 124 echo "job $1 gen 2 budget 1000 stop $EOS fault 0 ids $C" | "$O/$1" 3< "$MODEL" > "$O/$1.out" 2>&1 125 } 126 bvar oob-get 'base = get tof ti' 'base = ulong `807694268`' 127 check oob-get-exit "$?" 103 128 check oob-get-no-reply "$(grep -c '^job oob-get' "$O/oob-get.out")" 0 129 bvar oob-put 'rowcp add base mul r rbs rbs' 'rowcp add base mul r rbs 8193' 130 check oob-put-exit "$?" 103 131 check oob-put-no-reply "$(grep -c '^job oob-put' "$O/oob-put.out")" 0 132 bvar oob-ctl 'base = get tof ti' 'base = add get tof ti ulong 0' 133 check oob-ctl-exit "$?" 0 134 check oob-ctl-vs-ref "$(jtok "$O/oob-ctl.out" oob-ctl)" "$(awk 'NR==1{print $1" "$2" "$3} NR==2{print $1" "$2" "$3}' "$O/ref-cow.want")" 135 136 if [ -z "$FAILS" ]; then echo "RC=0"; exit 0; fi 137 echo "failed:$FAILS" 138 echo "RC=1" 139 exit 1