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-sovereign-core-mv/blob/main/om/flint/check.sh # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. 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-sovereign-core-mv / om / flint / check.sh` 294 lines ยท 13086 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # Flint P0 manifest gate (Core #802). Builds om/flint/manifest.om with the pinned omc, then: 3 # 1. runs it on a synthetic Flint-shaped checkpoint built by test/gen.py from config.json alone 4 # (must exit 0, print the exact summary and a TSV byte-equal to the referee's); 5 # 2. runs every refusal fixture (each must exit with its own code, print "refused ..." 6 # and write nothing to stdout); 7 # 3. rebuilds the reader with each guard removed and requires that guard's fixture to stop 8 # producing its code, so every refusal above is proven to come from the guard named for it. 9 # Usage: OMC=/path/to/omega-mv/seed/out/omc bash om/flint/check.sh (OMEGA_OMC is accepted too) 10 # Optional real-checkpoint arms, each NOT_RUN when unset: 11 # FLINT_SRC=dir the pinned source capture (config.json, model.safetensors.index.json, 12 # headers/.header.json, shards.lfs-sha256): sparse shards rebuilt from 13 # the exact published header bytes and sizes. 14 # FLINT_SHARDS=dir the 15 downloaded shards (config and index come from FLINT_SRC). 15 # With both set, the forward-operator arm runs ops.om against test/opref.py fixtures; 16 # FLINT_PY is the referee's interpreter (torch + transformers `a672eb5f`), default python3. 17 # FLINT_FORWARD=1 additionally runs the full 49-layer, two-token chained forward and mutants. 18 # Needs: python3 (fixture referees only), sha256sum, cmp, timeout. Host only; no network, no GPU. 19 set -u 20 here=$(cd "$(dirname "$0")" && pwd) 21 root=$(cd "$here/../.." && pwd) 22 OMC=${OMC:-${OMEGA_OMC:-}} 23 : "${OMC:?set OMC to the seed compiler (omega-mv seed/out/omc)}" 24 PIN=`62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b` 25 CFG_PIN=`a57c33d11f725099105b657043c113149763066d204fd472d0b2ee399abc2ba7` 26 IDX_PIN=`e5e9c492685f84c8d2d8369f36c74674b03410715f23f6179313f6f1feb90311` 27 TSV_PIN=`60ff4dbdaa1c3632c934c6935aa60ed5b2def4e15f0ca5083ddc7dd660f083f5` 28 SUMMARY='flint-manifest ok tensors 36734 params `39785287456` routed `37849399296` shards 15 bytes `79570574912`' 29 sha() { sha256sum < "$1" | cut -d' ' -f1; } 30 got=$(sha "$OMC") 31 [ "$got" = "$PIN" ] || { echo "FAIL omc sha256 $got, pinned $PIN"; exit 1; } 32 [ "$(sha "$here/test/config.json")" = "$CFG_PIN" ] || { echo "FAIL test/config.json is not the pinned config"; exit 1; } 33 b=$(mktemp -d) 34 trap 'rm -rf "$b"' EXIT 35 pass=0 36 fail=0 37 ok() { pass=$((pass + 1)); echo "ok $*"; } 38 bad() { fail=$((fail + 1)); echo "FAIL $*"; } 39 40 build() { # out source 41 { printf 'om2\n'; cat "$root/om/vendor/json.om" "$2"; } | "$OMC" > "$1" 2> "$1.err" || { echo "compile: $(cat "$1.err")"; return 1; } 42 chmod 700 "$1" 43 } 44 gen() { rm -rf "$b/fx"; python3 "$here/test/gen.py" "$here/test/config.json" "$b/fx" "$1" < /dev/null; } 45 run() { # binary; sets rc, leaves out.tsv and err in $b/fx 46 (cd "$b/fx" && timeout 60 "$1" config.json index.json shards > out.tsv 2> err < /dev/null) 47 rc=$? 48 } 49 50 build "$b/fm" "$here/manifest.om" || exit 1 51 52 # 1. synthetic checkpoint must load 53 gen base || exit 1 54 run "$b/fm" 55 if [ "$rc" = 0 ] && cmp -s "$b/fx/out.tsv" "$b/fx/expected.tsv" && [ "$(cat "$b/fx/err")" = "$SUMMARY" ]; then 56 ok "base: 36734 tensors, TSV equals referee, summary exact" 57 else 58 bad "base: rc $rc, $(head -c 200 "$b/fx/err")" 59 fi 60 for args in "" "a" "a b" "a b c d"; do 61 # shellcheck disable=SC2086 62 "$b/fm" $args > "$b/u.out" 2> /dev/null < /dev/null 63 r=$? 64 if [ "$r" = 2 ] && [ ! -s "$b/u.out" ]; then ok "usage ($args): 2"; else bad "usage ($args): $r"; fi 65 done 66 67 # 2. refusals: fixture, required exit code 68 FIX='cfg-json 10 69 cfg-field 11 70 cfg-unknown 11 71 cfg-dup 11 72 cfg-missing 11 73 cfg-softmax 11 74 cfg-window 11 75 cfg-tie 11 76 idx-size 20 77 idx-syntax 21 78 idx-shard-name 22 79 idx-unknown 23 80 idx-dup 24 81 idx-total 25 82 idx-missing 26 83 shard-absent 3 84 shard-symlink 4 85 shard-dir 4 86 shard-short 30 87 hdr-len-be 31 88 hdr-len-big 31 89 hdr-json 32 90 hdr-entry 33 91 hdr-meta 34 92 hdr-dtype 35 93 hdr-shape 36 94 hdr-rank 36 95 hdr-off-len 37 96 hdr-off-overflow 37 97 hdr-truncated 37 98 hdr-overlap 38 99 hdr-gap 38 100 hdr-trailing 38 101 hdr-dup 39 102 hdr-mismatch 40 103 hdr-missing 41 104 hdr-unknown 23 105 shard-cap 42' 106 while read -r m want; do 107 gen "$m" || { bad "$m: fixture generator failed"; continue; } 108 run "$b/fm" 109 if [ "$rc" = "$want" ] && [ ! -s "$b/fx/out.tsv" ] && grep -q "^refused $want " "$b/fx/err"; then 110 ok "$m: $want" 111 else 112 bad "$m: want $want, got $rc ($(head -c 120 "$b/fx/err"))" 113 fi 114 done <<< "$FIX" 115 116 # 3. guard mutants: the reader with one guard removed must stop producing that guard's code 117 s=$(cat "$here/manifest.om") 118 mutant() { # name want fixture; reads $b/mut.om 119 build "$b/mut" "$b/mut.om" || { bad "mutant $1: does not compile"; return; } 120 gen "$3" || { bad "mutant $1: fixture generator failed"; return; } 121 run "$b/mut" 122 if [ "$rc" = "$2" ]; then bad "mutant $1: still exits $2 on $3, so the guard is not what refuses it"; else ok "mutant $1: $3 now exits $rc, not $2"; fi 123 } 124 GUARD='3 shard-absent 125 4 shard-symlink 126 10 cfg-json 127 11 cfg-softmax 128 20 idx-size 129 21 idx-syntax 130 22 idx-shard-name 131 23 idx-unknown 132 24 idx-dup 133 25 idx-total 134 26 idx-missing 135 30 shard-short 136 31 hdr-len-be 137 32 hdr-json 138 33 hdr-entry 139 34 hdr-meta 140 35 hdr-dtype 141 36 hdr-shape 142 37 hdr-off-overflow 143 38 hdr-overlap 144 39 hdr-dup 145 40 hdr-mismatch 146 41 hdr-missing 147 42 shard-cap' 148 nl=$'\n' 149 while read -r code fx; do 150 t=${s//"fm_die $code tr$code$nl"/"put gst 14 get gst 14$nl"} 151 [ "$t" != "$s" ] || { bad "mutant die-$code: no guard text found"; continue; } 152 printf '%s\n' "$t" > "$b/mut.om" 153 mutant "die-$code" "$code" "$fx" 154 done <<< "$GUARD" 155 t=${s//"fopen gpth 0 n 557056 0"/"fopen gpth 0 n 524288 0"} 156 if [ "$t" = "$s" ]; then bad "mutant no-nofollow: open flags not found"; else 157 printf '%s\n' "$t" > "$b/mut.om" 158 mutant no-nofollow 4 shard-symlink 159 fi 160 161 # 4. real checkpoint arms 162 if [ -n "${FLINT_SRC:-}" ]; then 163 if [ "$(sha "$FLINT_SRC/config.json")" != "$CFG_PIN" ] || [ "$(sha "$FLINT_SRC/model.safetensors.index.json")" != "$IDX_PIN" ]; then 164 bad "FLINT_SRC: config or index is not the pinned revision `2a247be0`" 165 else 166 mkdir -p "$b/hdr" 167 python3 - "$FLINT_SRC" "$b/hdr" < /dev/null <<'PY' 168 import os, struct, sys 169 src, out = sys.argv[1:3] 170 for line in open(src + "/shards.lfs-sha256"): 171 _, name, size = line.split() 172 h = open(src + "/headers/" + name + ".header.json", "rb").read() 173 with open(out + "/" + name, "wb") as f: 174 f.write(struct.pack(" "$b/hdr.tsv" 2> "$b/hdr.err" < /dev/null 178 r=$? 179 if [ "$r" = 0 ] && [ "$(sha "$b/hdr.tsv")" = "$TSV_PIN" ] && [ "$(cat "$b/hdr.err")" = "$SUMMARY" ]; then 180 ok "FLINT_SRC: published headers and sizes, TSV sha $TSV_PIN" 181 else 182 bad "FLINT_SRC: rc $r, $(head -c 200 "$b/hdr.err")" 183 fi 184 fi 185 else 186 echo "NOT_RUN FLINT_SRC (pinned header capture of RecursiveSI/flint `2a247be0`)" 187 fi 188 if [ -n "${FLINT_SHARDS:-}" ] && [ -n "${FLINT_SRC:-}" ]; then 189 timeout 600 "$b/fm" "$FLINT_SRC/config.json" "$FLINT_SRC/model.safetensors.index.json" "$FLINT_SHARDS" > "$b/real.tsv" 2> "$b/real.err" < /dev/null 190 r=$? 191 if [ "$r" = 0 ] && [ "$(sha "$b/real.tsv")" = "$TSV_PIN" ] && [ "$(cat "$b/real.err")" = "$SUMMARY" ]; then 192 ok "FLINT_SHARDS: downloaded checkpoint, TSV sha $TSV_PIN" 193 else 194 bad "FLINT_SHARDS: rc $r, $(head -c 200 "$b/real.err")" 195 fi 196 else 197 echo "NOT_RUN FLINT_SHARDS (the 15 downloaded shards; needs FLINT_SRC too)" 198 fi 199 200 # 5. forward operators (Core #802): ops.om recomputes, from the real BF16 shard weights, the 201 # outputs that test/opref.py takes from the pinned reference modules, and must land within twice 202 # the reference's own f32 error bound; each mutant must turn its operator's verdict to FAIL 203 # (exit 1, the comparison, not a trap or refusal). FLINT_PY runs the referee (torch and the 204 # transformers `a672eb5f` checkout); default python3. The fixtures, concatenated in FXS order, 205 # must hash to FX_PIN: recorded with torch 2.14.0 (written into every fixture header) on the 206 # Spark host CPU, so another torch, transformers file or CPU result shows up as a FAIL here. 207 FX_PIN=`2d838552a1ee0b726ee1b5cfb2a13a101f2520d522cbc4cf55dfcfe110287b7a` 208 FXS='rmsnorm qkv-2 qkv-5 attn-2 attn-5 router router-swap router-tie shared expert moe' 209 OPS='rmsnorm rmsnorm 210 qkv qkv-2 211 qkv qkv-5 212 attn attn-2 213 attn attn-5 214 router router 215 shared shared 216 expert expert 217 moe moe' 218 MUT='softmax-router|sc = om_sig l|sc = om_exp l|router router 219 shared-gate-sigmoid0|v = add get gacm o get gx3 o|v = add get gacm o mul 0.5f64 get gx3 o|moe moe 220 no-sink|att_sm n get gsk h get gst 4|att_sm n -1.`0e30f64` get gst 4|attn attn-2 221 rope-global|rp = fl_swa L|rp = true|qkv qkv-5 222 expert-permuted|nm_u ex|nm_u sub 255 ex|expert expert 223 window-514|const FWIN ulong 513|const FWIN ulong 514|attn attn-2' 224 opr() { # binary op fixture; sets rc and line 225 line=$(timeout 300 "$1" "$2" "$b/opfx/$3.bin" "$b/real.tsv" "$FLINT_SHARDS" 2>&1 < /dev/null) 226 rc=$? 227 } 228 if [ -n "${FLINT_SHARDS:-}" ] && [ -n "${FLINT_SRC:-}" ] && [ -s "$b/real.tsv" ]; then 229 if ! build "$b/ops" "$here/ops.om"; then bad "ops: ops.om does not compile" 230 elif ! ${FLINT_PY:-python3} "$here/test/opref.py" "$FLINT_SRC" "$FLINT_SHARDS" "$b/opfx" > "$b/opref.out" 2>&1 < /dev/null; then 231 bad "ops: opref.py failed: $(head -c 300 "$b/opref.out")" 232 else 233 fxsha=$(for f in $FXS; do cat "$b/opfx/$f.bin" || echo missing; done | sha256sum | cut -d' ' -f1) 234 cat "$b/opref.out" 235 if [ "$fxsha" = "$FX_PIN" ]; then ok "fixtures sha256 $fxsha (pinned)"; else bad "fixtures sha256 $fxsha, pinned $FX_PIN"; fi 236 line=$(timeout 60 "$b/ops" selftest 2>&1 < /dev/null) 237 rc=$? 238 if [ "$rc" = 0 ] && [[ $line == *" PASS" ]]; then ok "PASS $line"; else bad "selftest rc $rc: $line"; fi 239 while read -r op fx; do 240 opr "$b/ops" "$op" "$fx" 241 if [ "$rc" = 0 ] && [[ $line == *" PASS" ]]; then ok "PASS $fx: $line"; else bad "$fx rc $rc: $line"; fi 242 done <<< "$OPS" 243 opr "$b/ops" router router-swap 244 if [ "$rc" = 1 ] && [[ $line == *" FAIL" ]]; then ok "CAUGHT control router-swap (reference top-6 swapped): $line"; else bad "control router-swap rc $rc: $line"; fi 245 opr "$b/ops" router router-tie 246 if [ "$rc" = 0 ] && [[ $line == *" PASS" ]] && [[ $line != *" ties 0 "* ]]; then ok "PASS router-tie (rank-6/7 near tie reported, not failed): $line"; else bad "control router-tie rc $rc: $line"; fi 247 s=$(cat "$here/ops.om") 248 while IFS='|' read -r name from to target; do 249 n=$(grep -cF -- "$from" "$here/ops.om") 250 [ "$n" = 1 ] || { bad "mutant $name: site found $n times"; continue; } 251 printf '%s\n' "${s/"$from"/"$to"}" > "$b/opmut.om" 252 build "$b/opmut" "$b/opmut.om" || { bad "mutant $name: does not compile"; continue; } 253 opr "$b/opmut" $target 254 if [ "$rc" = 1 ] && [[ $line == *" FAIL" ]]; then ok "CAUGHT mutant $name on ${target#* }: $line"; else bad "mutant $name not caught on ${target#* }: rc $rc $line"; fi 255 done <<< "$MUT" 256 fi 257 else 258 echo "NOT_RUN ops (forward operators; needs FLINT_SRC, FLINT_SHARDS and the FLINT_SHARDS arm's TSV)" 259 fi 260 261 # Full chained forward is opt-in because it streams the real checkpoint and runs all 49 layers. 262 # No intermediate reference tensor is fed back into the native computation. 263 if [ "${FLINT_FORWARD:-0}" = 1 ]; then 264 if [ -z "${FLINT_SRC:-}" ] || [ -z "${FLINT_SHARDS:-}" ] || [ ! -s "$b/real.tsv" ]; then 265 bad "forward requested without FLINT_SRC, FLINT_SHARDS and admitted real.tsv" 266 elif ! ${FLINT_PY:-python3} "$here/test/fwdref.py" "$FLINT_SRC" "$FLINT_SHARDS" "$b/forward.fx" > "$b/fwdref.out" 2>&1 < /dev/null; then 267 bad "forward referee: $(cat "$b/fwdref.out")" 268 elif [ "$(sha "$b/forward.fx")" != `b5e4bae28af3c1fa0c8f7454c496e72da1388e17f51bb3ec9e9b0387aac97031` ]; then 269 bad "forward fixture pin mismatch: $(sha "$b/forward.fx")" 270 else 271 cat "$b/fwdref.out" 272 line=$(timeout 600 "$b/ops" forward "$b/forward.fx" "$b/real.tsv" "$FLINT_SHARDS" 2>&1 < /dev/null) 273 rc=$? 274 echo "$line" 275 if [ "$rc" = 0 ] && [[ $line == *"forward layer 49 "* ]] && [[ $line == *" PASS" ]]; then ok "chained forward, all layers and vocabulary logits"; else bad "forward rc $rc"; fi 276 s=$(cat "$here/ops.om") 277 while IFS='|' read -r name from to; do 278 [ "$(grep -cF -- "$from" "$here/ops.om")" = 1 ] || { bad "forward mutant $name site"; continue; } 279 printf '%s\n' "${s/"$from"/"$to"}" > "$b/fwdmut.om" 280 build "$b/fwdmut" "$b/fwdmut.om" || { bad "forward mutant $name compile"; continue; } 281 line=$(timeout 600 "$b/fwdmut" forward "$b/forward.fx" "$b/real.tsv" "$FLINT_SHARDS" 2>&1 < /dev/null) 282 rc=$? 283 if [ "$rc" = 1 ] && [[ $line == *" FAIL" ]]; then ok "CAUGHT forward mutant $name: ${line##*$'\n'}"; else bad "forward mutant $name rc $rc: $line"; fi 284 done <<'FORWARD_MUTANTS' 285 wrong-token|id = fx_w add 8 t|id = add fx_w add 8 t 1 286 skip-final-norm|put gfh o get gy i|put gfh o get gv i 287 FORWARD_MUTANTS 288 fi 289 else 290 echo "NOT_RUN chained forward (set FLINT_FORWARD=1)" 291 fi 292 293 n=$((pass + fail)) 294 if [ "$fail" = 0 ]; then echo "OM-FLINT-MANIFEST PASS ($n)"; else echo "OM-FLINT-MANIFEST FAIL ($fail of $n)"; exit 1; fi