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
aien-sovereign-core-mv / om / expert-bytes / gate.sh
| 1 | #!/usr/bin/env bash |
| 2 | # om/expert-bytes/gate.sh: SC-EXPERT-BYTES (DRA-63, aien-dev/aien-sovereign-core-mv#855). |
| 3 | # Builds om/expert-bytes/expert-bytes.om with the pinned seeded omc and runs it on the |
| 4 | # Qwen3.6-35B-A3B-FP8 checkpoint headers (no tensor data is read): |
| 5 | # 1. width 512, BF16 scales: must exit 0 with the contract figures 3146112 B per expert |
| 6 | # (3145728 B FP8 weight + 384 B BF16 scales); |
| 7 | # 2. negative control, width 768: must exit 1 with verdict FAIL; |
| 8 | # 3. negative control, FP32 scales (the old 768 B scale figure): must exit 1 with verdict FAIL; |
| 9 | # 4. input-side control: a header-only sparse copy of the checkpoint (same file sizes, no tensor |
| 10 | # data) whose layer 5 expert 7 down_proj shape reads [2048,768] must exit 1 with verdict FAIL, |
| 11 | # shape_bad 1 and experts_ok 10239 (only fully correct experts count). |
| 12 | # The shell only sequences; every judgment about the header is made by the .om program. |
| 13 | # Compiler: AIEN_OMC (OMC and OMEGA_OMC are accepted too) must hash to omega.pin, else NOT_RUN. |
| 14 | # Model: MODEL_DIR, else $AIEN_MODELS_DIR/qwen3.6-35b-a3b-fp8-95a723d0, else |
| 15 | # $HOME/models/qwen3.6-35b-a3b-fp8-95a723d0; missing is NOT_RUN. |
| 16 | # Exit 0 PASS, 1 FAIL, 77 NOT_RUN (with an AIEN-OBS not_run_reason line). |
| 17 | set -u |
| 18 | here=$(cd "$(dirname "$0")" && pwd) |
| 19 | root=$(cd "$here/../.." && pwd) |
| 20 | MODEL=qwen3.6-35b-a3b-fp8-95a723d0 |
| 21 | CONTRACT='expect_expert 3146112 expect_weight 3145728 expect_scale 384 ' |
| 22 | obs() { printf 'AIEN-OBS %s %s\n' "$1" "$2"; } |
| 23 | not_run() { echo "expert-bytes gate: NOT_RUN $1: $2" >&2; obs not_run_reason "\"$1\""; exit 77; } |
| 24 | |
| 25 | omc=${AIEN_OMC:-${OMC:-${OMEGA_OMC:-}}} |
| 26 | [ -n "$omc" ] || not_run omc_missing "set AIEN_OMC to omega-mv seed/out/omc at the commit in om/expert-bytes/omega.pin" |
| 27 | [ -x "$omc" ] || not_run omc_missing "$omc is not executable" |
| 28 | pin=$(sed -n 's/^omc_sha256: //p' "$here/omega.pin") |
| 29 | got=$(sha256sum < "$omc" | cut -d' ' -f1) |
| 30 | [ "$got" = "$pin" ] || not_run omc_unpinned "omc sha256 $got, pinned $pin" |
| 31 | |
| 32 | if [ -n "${MODEL_DIR:-}" ]; then dir=$MODEL_DIR |
| 33 | elif [ -n "${AIEN_MODELS_DIR:-}" ]; then dir=$AIEN_MODELS_DIR/$MODEL |
| 34 | else dir=$HOME/models/$MODEL |
| 35 | fi |
| 36 | [ -f "$dir/layers-0.safetensors" ] || not_run model_missing "$dir/layers-0.safetensors" |
| 37 | |
| 38 | b=$(mktemp -d) |
| 39 | trap 'rm -rf "$b"' EXIT |
| 40 | { printf 'om2\n'; cat "$root/om/vendor/json.om" "$here/expert-bytes.om"; } | "$omc" > "$b/eb" 2> "$b/eb.err" \ |
| 41 | || { echo "FAIL compile: $(cat "$b/eb.err")"; exit 1; } |
| 42 | chmod 700 "$b/eb" |
| 43 | obs omc_sha256 "\"$got\"" |
| 44 | obs check_sha256 "\"$(sha256sum < "$b/eb" | cut -d' ' -f1)\"" |
| 45 | obs model_dir "\"$dir\"" |
| 46 | |
| 47 | fail=0 |
| 48 | arm() { # name width scale_bytes want_rc want_verdict |
| 49 | line=$(timeout 120 "$b/eb" "$dir" "$2" "$3" 2>&1 < /dev/null) |
| 50 | rc=$? |
| 51 | echo "$line" |
| 52 | if [ "$rc" = "$4" ] && [[ $line == "expert-bytes verdict $5 "* ]]; then |
| 53 | echo "ok $1: exit $rc, verdict $5" |
| 54 | return 0 |
| 55 | fi |
| 56 | echo "FAIL $1: exit $rc, want $4 and verdict $5" |
| 57 | fail=1 |
| 58 | return 1 |
| 59 | } |
| 60 | if arm real 512 2 0 PASS; then |
| 61 | if [[ $line != *" $CONTRACT"* ]]; then echo "FAIL real: contract figures ($CONTRACT) not printed"; fail=1; fi |
| 62 | fi |
| 63 | arm control-width-768 768 2 1 FAIL |
| 64 | arm control-fp32-scales 512 4 1 FAIL |
| 65 | # Input mutant: copy each header into a sparse file of the original size, then rewrite one shape in |
| 66 | # layers-5 in place (512 -> 768 keeps the header length). |
| 67 | mut=$b/mut |
| 68 | mkdir "$mut" |
| 69 | for f in "$dir"/*.safetensors; do |
| 70 | n=$(od -An -t u8 -N8 "$f" | tr -d ' ') |
| 71 | truncate -s "$(stat -c %s "$f")" "$mut/${f##*/}" |
| 72 | dd if="$f" of="$mut/${f##*/}" bs=65536 count=$((8 + n)) iflag=count_bytes conv=notrunc status=none |
| 73 | done |
| 74 | h5=$b/h5 |
| 75 | n=$(od -An -t u8 -N8 "$dir/layers-5.safetensors" | tr -d ' ') |
| 76 | dd if="$dir/layers-5.safetensors" of="$h5" bs=65536 count=$((8 + n)) iflag=count_bytes status=none |
| 77 | sed -i 's/\("model\.language_model\.layers\.5\.mlp\.experts\.7\.down_proj\.weight":{"dtype":"F8_E4M3","shape":\[2048,\)512\]/\1768]/' "$h5" |
| 78 | dd if="$h5" of="$mut/layers-5.safetensors" conv=notrunc status=none |
| 79 | dir=$mut |
| 80 | if arm control-input-shape 512 2 1 FAIL; then |
| 81 | if [[ $line != *" experts_ok 10239 "* || $line != *" shape_bad 1 "* ]]; then |
| 82 | echo "FAIL control-input-shape: want experts_ok 10239 and shape_bad 1"; fail=1 |
| 83 | fi |
| 84 | fi |
| 85 | if [ "$fail" = 0 ]; then obs verdict '"PASS"'; echo "SC-EXPERT-BYTES PASS"; exit 0; fi |
| 86 | obs verdict '"FAIL"' |
| 87 | echo "SC-EXPERT-BYTES FAIL" |
| 88 | exit 1 |