interplane.Get Omega
Read in your language

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

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 <code> ..."
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/<shard>.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.
19set -u
20here=$(cd "$(dirname "$0")" && pwd)
21root=$(cd "$here/../.." && pwd)
22OMC=${OMC:-${OMEGA_OMC:-}}
23: "${OMC:?set OMC to the seed compiler (omega-mv seed/out/omc)}"
24PIN=62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b
25CFG_PIN=a57c33d11f725099105b657043c113149763066d204fd472d0b2ee399abc2ba7
26IDX_PIN=e5e9c492685f84c8d2d8369f36c74674b03410715f23f6179313f6f1feb90311
27TSV_PIN=60ff4dbdaa1c3632c934c6935aa60ed5b2def4e15f0ca5083ddc7dd660f083f5
28SUMMARY='flint-manifest ok tensors 36734 params 39785287456 routed 37849399296 shards 15 bytes 79570574912'
29sha() { sha256sum < "$1" | cut -d' ' -f1; }
30got=$(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; }
33b=$(mktemp -d)
34trap 'rm -rf "$b"' EXIT
35pass=0
36fail=0
37ok() { pass=$((pass + 1)); echo "ok $*"; }
38bad() { fail=$((fail + 1)); echo "FAIL $*"; }
39
40build() { # 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}
44gen() { rm -rf "$b/fx"; python3 "$here/test/gen.py" "$here/test/config.json" "$b/fx" "$1" < /dev/null; }
45run() { # 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
50build "$b/fm" "$here/manifest.om" || exit 1
51
52# 1. synthetic checkpoint must load
53gen base || exit 1
54run "$b/fm"
55if [ "$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"
57else
58 bad "base: rc $rc, $(head -c 200 "$b/fx/err")"
59fi
60for 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
65done
66
67# 2. refusals: fixture, required exit code
68FIX='cfg-json 10
69cfg-field 11
70cfg-unknown 11
71cfg-dup 11
72cfg-missing 11
73cfg-softmax 11
74cfg-window 11
75cfg-tie 11
76idx-size 20
77idx-syntax 21
78idx-shard-name 22
79idx-unknown 23
80idx-dup 24
81idx-total 25
82idx-missing 26
83shard-absent 3
84shard-symlink 4
85shard-dir 4
86shard-short 30
87hdr-len-be 31
88hdr-len-big 31
89hdr-json 32
90hdr-entry 33
91hdr-meta 34
92hdr-dtype 35
93hdr-shape 36
94hdr-rank 36
95hdr-off-len 37
96hdr-off-overflow 37
97hdr-truncated 37
98hdr-overlap 38
99hdr-gap 38
100hdr-trailing 38
101hdr-dup 39
102hdr-mismatch 40
103hdr-missing 41
104hdr-unknown 23
105shard-cap 42'
106while 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
114done <<< "$FIX"
115
116# 3. guard mutants: the reader with one guard removed must stop producing that guard's code
117s=$(cat "$here/manifest.om")
118mutant() { # 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}
124GUARD='3 shard-absent
1254 shard-symlink
12610 cfg-json
12711 cfg-softmax
12820 idx-size
12921 idx-syntax
13022 idx-shard-name
13123 idx-unknown
13224 idx-dup
13325 idx-total
13426 idx-missing
13530 shard-short
13631 hdr-len-be
13732 hdr-json
13833 hdr-entry
13934 hdr-meta
14035 hdr-dtype
14136 hdr-shape
14237 hdr-off-overflow
14338 hdr-overlap
14439 hdr-dup
14540 hdr-mismatch
14641 hdr-missing
14742 shard-cap'
148nl=$'\n'
149while 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"
154done <<< "$GUARD"
155t=${s//"fopen gpth 0 n 557056 0"/"fopen gpth 0 n 524288 0"}
156if [ "$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
159fi
160
161# 4. real checkpoint arms
162if [ -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'
168import os, struct, sys
169src, out = sys.argv[1:3]
170for 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("<Q", len(h)) + h)
175 f.truncate(int(size))
176PY
177 timeout 60 "$b/fm" "$FLINT_SRC/config.json" "$FLINT_SRC/model.safetensors.index.json" "$b/hdr" > "$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
185else
186 echo "NOT_RUN FLINT_SRC (pinned header capture of RecursiveSI/flint 2a247be0)"
187fi
188if [ -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
196else
197 echo "NOT_RUN FLINT_SHARDS (the 15 downloaded shards; needs FLINT_SRC too)"
198fi
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.
207FX_PIN=2d838552a1ee0b726ee1b5cfb2a13a101f2520d522cbc4cf55dfcfe110287b7a
208FXS='rmsnorm qkv-2 qkv-5 attn-2 attn-5 router router-swap router-tie shared expert moe'
209OPS='rmsnorm rmsnorm
210qkv qkv-2
211qkv qkv-5
212attn attn-2
213attn attn-5
214router router
215shared shared
216expert expert
217moe moe'
218MUT='softmax-router|sc = om_sig l|sc = om_exp l|router router
219shared-gate-sigmoid0|v = add get gacm o get gx3 o|v = add get gacm o mul 0.5f64 get gx3 o|moe moe
220no-sink|att_sm n get gsk h get gst 4|att_sm n -1.0e30f64 get gst 4|attn attn-2
221rope-global|rp = fl_swa L|rp = true|qkv qkv-5
222expert-permuted|nm_u ex|nm_u sub 255 ex|expert expert
223window-514|const FWIN ulong 513|const FWIN ulong 514|attn attn-2'
224opr() { # 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}
228if [ -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
257else
258 echo "NOT_RUN ops (forward operators; needs FLINT_SRC, FLINT_SHARDS and the FLINT_SHARDS arm's TSV)"
259fi
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.
263if [ "${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'
285wrong-token|id = fx_w add 8 t|id = add fx_w add 8 t 1
286skip-final-norm|put gfh o get gy i|put gfh o get gv i
287FORWARD_MUTANTS
288 fi
289else
290 echo "NOT_RUN chained forward (set FLINT_FORWARD=1)"
291fi
292
293n=$((pass + fail))
294if [ "$fail" = 0 ]; then echo "OM-FLINT-MANIFEST PASS ($n)"; else echo "OM-FLINT-MANIFEST FAIL ($fail of $n)"; exit 1; fi