interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

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)
7set -u
8HERE=$(cd "$(dirname "$0")" && pwd)
9ROOT=$(cd "$HERE/../../.." && pwd)
10OMC=${OMC:-$HOME/workspace/arch314/omega-mv/seed/out/omc}
11MODEL=${MODEL:-$HOME/models/aien-mail/Llama-3.2-1B-Instruct-Q4_K_M.gguf}
12OMC_SHA=734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61
13MODEL_SHA=3f5a22426976ab26cfe84dba63c1d08391717abb1af893e10f1b2968d862dcc1
14EOS=128009
15O=$HERE/out/gate
16rm -rf "$O"
17mkdir -p "$O"
18FAILS=""
19pass() { echo "PASS $1"; }
20fail() { echo "FAIL $1: $2"; FAILS="$FAILS $1"; }
21check() { if [ "$2" = "$3" ]; then pass "$1"; else fail "$1" "want [$3] got [$2]"; fi; }
22
23# 1. pinned inputs
24check omc-sha "$(sha256sum "$OMC" | cut -d' ' -f1)" "$OMC_SHA"
25check model-sha "$(sha256sum "$MODEL" | cut -d' ' -f1)" "$MODEL_SHA"
26
27# 2. the committed program is exactly what the generator makes from the template
28cp "$HERE/lm1b.om" "$O/lm1b.committed.om"
29sh "$HERE/gen.sh" > "$O/gen.log" 2>&1 || fail gen "gen.sh failed"
30if 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)
33BAD=$(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' ' ')
34check 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"
38check compile "$?" 0
39chmod +x "$O/lm1b"
40sha256sum "$O/lm1b" | cut -d' ' -f1 > "$O/lm1b.sha256"
41objdump -D -b binary -maarch64 "$O/lm1b" > "$O/lm1b.dis" 2>&1
42SVC=$(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' ' ')
43check 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
48if 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
52P=$ROOT/target/release/examples/model_probe
53for 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"
56done
57
58# helpers over lm1b output
59jtok() { 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"; }
60jline() { 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"
64check main-exit "$?" 0
65check main-load "$(head -1 "$O/main.out")" "load ok bytes 807694368 tensors 147 sha256 $MODEL_SHA passes 0"
66check job1-vs-ref "$(jtok "$O/main.out" cow1)" "$(cat "$O/ref-cow.want")"
67check job2-vs-ref "$(jtok "$O/main.out" rain)" "$(cat "$O/ref-rainbow.want")"
68check job3-eq-job1 "$(jtok "$O/main.out" cow3)" "$(jtok "$O/main.out" cow1)"
69check job1-status "$(jline "$O/main.out" cow1 | cut -d' ' -f3-6)" "status ok passes 26"
70check 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)
74cp "$MODEL" "$O/flipped.gguf"
75printf '\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
77RCF=$?
78rm -f "$O/flipped.gguf"
79check 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
81sed '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"
82check 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
85RCW=$?
86check 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
88C=$(sed 's/^ids //' "$HERE/prompts/cow.txt")
89LONG=$(awk 'BEGIN{for(i=0;i<257;i++) printf " 9"; print ""}')
90L250=$(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"
101check neg-exit "$?" 0
102check over-limit "$(jline "$O/neg.out" big)" "job big status refused reason toomany"
103check over-context "$(jline "$O/neg.out" ctx)" "job ctx status refused reason context"
104check bad-id "$(jline "$O/neg.out" bad)" "job bad status refused reason badid"
105check malformed "$(grep -c '^job ? status refused reason syntax$' "$O/neg.out")" 2
106check budget-cancel "$(jline "$O/neg.out" b1)" "job b1 status cancelled passes 5 tokens"
107check 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)
109echo "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"
111check fault-exit "$?" 112
112check 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.
118bvar() {
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}
126bvar oob-get 'base = get tof ti' 'base = ulong 807694268'
127check oob-get-exit "$?" 103
128check oob-get-no-reply "$(grep -c '^job oob-get' "$O/oob-get.out")" 0
129bvar oob-put 'rowcp add base mul r rbs rbs' 'rowcp add base mul r rbs 8193'
130check oob-put-exit "$?" 103
131check oob-put-no-reply "$(grep -c '^job oob-put' "$O/oob-put.out")" 0
132bvar oob-ctl 'base = get tof ti' 'base = add get tof ti ulong 0'
133check oob-ctl-exit "$?" 0
134check 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
136if [ -z "$FAILS" ]; then echo "RC=0"; exit 0; fi
137echo "failed:$FAILS"
138echo "RC=1"
139exit 1