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 / expert-bytes / gate.sh

88 lines · 4277 bytes Raw Blame History
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).
17set -u
18here=$(cd "$(dirname "$0")" && pwd)
19root=$(cd "$here/../.." && pwd)
20MODEL=qwen3.6-35b-a3b-fp8-95a723d0
21CONTRACT='expect_expert 3146112 expect_weight 3145728 expect_scale 384 '
22obs() { printf 'AIEN-OBS %s %s\n' "$1" "$2"; }
23not_run() { echo "expert-bytes gate: NOT_RUN $1: $2" >&2; obs not_run_reason "\"$1\""; exit 77; }
24
25omc=${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"
28pin=$(sed -n 's/^omc_sha256: //p' "$here/omega.pin")
29got=$(sha256sum < "$omc" | cut -d' ' -f1)
30[ "$got" = "$pin" ] || not_run omc_unpinned "omc sha256 $got, pinned $pin"
31
32if [ -n "${MODEL_DIR:-}" ]; then dir=$MODEL_DIR
33elif [ -n "${AIEN_MODELS_DIR:-}" ]; then dir=$AIEN_MODELS_DIR/$MODEL
34else dir=$HOME/models/$MODEL
35fi
36[ -f "$dir/layers-0.safetensors" ] || not_run model_missing "$dir/layers-0.safetensors"
37
38b=$(mktemp -d)
39trap '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; }
42chmod 700 "$b/eb"
43obs omc_sha256 "\"$got\""
44obs check_sha256 "\"$(sha256sum < "$b/eb" | cut -d' ' -f1)\""
45obs model_dir "\"$dir\""
46
47fail=0
48arm() { # 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}
60if arm real 512 2 0 PASS; then
61 if [[ $line != *" $CONTRACT"* ]]; then echo "FAIL real: contract figures ($CONTRACT) not printed"; fail=1; fi
62fi
63arm control-width-768 768 2 1 FAIL
64arm 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).
67mut=$b/mut
68mkdir "$mut"
69for 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
73done
74h5=$b/h5
75n=$(od -An -t u8 -N8 "$dir/layers-5.safetensors" | tr -d ' ')
76dd if="$dir/layers-5.safetensors" of="$h5" bs=65536 count=$((8 + n)) iflag=count_bytes status=none
77sed -i 's/\("model\.language_model\.layers\.5\.mlp\.experts\.7\.down_proj\.weight":{"dtype":"F8_E4M3","shape":\[2048,\)512\]/\1768]/' "$h5"
78dd if="$h5" of="$mut/layers-5.safetensors" conv=notrunc status=none
79dir=$mut
80if 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
84fi
85if [ "$fail" = 0 ]; then obs verdict '"PASS"'; echo "SC-EXPERT-BYTES PASS"; exit 0; fi
86obs verdict '"FAIL"'
87echo "SC-EXPERT-BYTES FAIL"
88exit 1