interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / evidence / CAND1-NATIVE-2eec75b / cand1_native.sh

235 lines · 11885 bytes Raw Blame History
1#!/usr/bin/env bash
2# L5-NATIVE CAND-1 native qualification: one command, build + chip run.
3#
4# bash cand1_native.sh <sovereign-core sha (full 40 hex)>
5#
6# 1. Clean detached checkout of that sha (fresh worktree, refused if dirty or HEAD differs),
7# omega at its omega.lock, physics at omega's physics.lock, each in its own fresh worktree.
8# 2. Release build of aien-cli (scripts/repro-build.sh when the sha has it, else
9# cargo build --release --locked) and release test binaries, AIEN_DEV_FALLBACK unset.
10# Refuses to continue if the Omega engine was not linked (stub build).
11# 3. Chip steps: identity, zero_cuda, strict_real_model (gate, vs reference, vs HF oracle),
12# runtime GB10 e2e tests incl. the native paged_attention_batch case, daemon positive turn,
13# daemon missing checkpoint, identity_after.
14# Output: ~/workspace/evidence-out/CAND1-NATIVE-<sha7>/ (batch.log, results.txt, per-step logs,
15# receipts). Every step runs even if an earlier one failed. Nothing is retried, killed or timed
16# out. Change from the CAND-0 batch: the daemon exit code is captured (CAND-0 got 127 because
17# gpu_procs overwrote the caller's `pid` variable; bash functions share non-local variables).
18set -u
19SHA=${1:?usage: cand1_native.sh <sovereign-core sha>}
20[[ $SHA =~ ^[0-9a-f]{40}$ ]] || { echo "need a full 40-hex sha, got '$SHA'"; exit 2; }
21S7=${SHA:0:7}
22O=$HOME/workspace/overnight-1005
23E=$HOME/workspace/evidence-out/CAND1-NATIVE-$S7
24SC=$O/wt-L5-NATIVE-cand1-$S7-aien-sovereign-core
25TGT=$O/wt-L5-NATIVE-targets/cand1-$S7
26HF=$HOME/.cache/huggingface/hub/models--TinyLlama--TinyLlama-1.1B-Chat-v1.0/snapshots/fe8a4ea1ffedaf415f4da2f062534de366a451e6
27BIN=$E/bin
28unset AIEN_DEV_FALLBACK AIEN_FORCE_CPU_STUB AIEN_OMEGA_GPU_LIB
29export RUST_BACKTRACE=1 CARGO_BUILD_JOBS=6 CARGO_TARGET_DIR=$TGT
30mkdir -p "$E" "$BIN" "$E/lib"
31cp "$0" "$E/cand1_native.sh"
32: > "$E/results.txt"
33
34step() {
35 local name=$1
36 shift
37 echo "=== STEP $name start $(date -u +%FT%TZ)"
38 "$@" > "$E/$name.log" 2>&1
39 local rc=$?
40 echo "=== STEP $name rc=$rc end $(date -u +%FT%TZ)"
41 echo "$name rc=$rc" >> "$E/results.txt"
42 grep -E "test result|ORACLE_GATE (step0|teacher|verdict|receipt|NATIVE)|OMEGA_GATE (teacher|verdict|tokens_match)|STRICT_GATE verdict|GB10_PAGED_BATCH|OP_CALLS|ZERO_CUDA|DAEMON_|BUILD_|CHECKOUT_|MISSING|panicked" "$E/$name.log" | head -40
43 return $rc
44}
45
46# Fresh detached worktree of <repo> at <sha>; refuses an existing dirty or mismatched one.
47checkout() {
48 local repo=$1 sha=$2 dir=$3
49 git -C "$repo" fetch -q origin || return 1
50 git -C "$repo" cat-file -e "$sha^{commit}" || { echo "CHECKOUT_FAIL $sha not in $repo"; return 1; }
51 [ -e "$dir" ] || git -C "$repo" worktree add -q --detach "$dir" "$sha" || return 1
52 local head dirty
53 head=$(git -C "$dir" rev-parse HEAD)
54 dirty=$(git -C "$dir" status --porcelain --untracked-files=no)
55 echo "CHECKOUT $dir head=$head dirty=[${dirty}]"
56 [ "$head" = "$sha" ] && [ -z "$dirty" ] || { echo "CHECKOUT_FAIL $dir not a clean checkout of $sha"; return 1; }
57}
58
59prepare() {
60 checkout "$O/aien-sovereign-core" "$SHA" "$SC" || return 1
61 local osha psha
62 osha=$(tr -d '[:space:]' < "$SC/omega.lock")
63 checkout "$O/omega" "$osha" "$O/wt-L5-NATIVE-omega-${osha:0:7}" || return 1
64 psha=$(tr -d '[:space:]' < "$O/wt-L5-NATIVE-omega-${osha:0:7}/physics.lock")
65 checkout "$O/physics" "$psha" "$O/wt-L5-NATIVE-physics-${psha:0:7}" || return 1
66 export AIEN_OMEGA_DIR=$O/wt-L5-NATIVE-omega-${osha:0:7} AIEN_PHYSICS_DIR=$O/wt-L5-NATIVE-physics-${psha:0:7}
67 cd "$SC" || return 1
68 if [ -x scripts/repro-build.sh ]; then
69 echo "BUILD_CLI scripts/repro-build.sh -p aien-cli"
70 nice -n 10 scripts/repro-build.sh -p aien-cli || return 1
71 else
72 echo "BUILD_CLI cargo build --release --locked -p aien-cli"
73 nice -n 10 cargo build --release --locked -p aien-cli || return 1
74 fi
75 # The engine must really be linked: build.rs sets cfg has_omega_gpu only then.
76 local out
77 out=$(grep -l has_omega_gpu "$TGT"/release/build/aien-omega-gpu-*/output 2>/dev/null | head -1)
78 [ -n "$out" ] || { echo "BUILD_FAIL Omega engine not linked (stub build)"; return 1; }
79 cp "$(dirname "$out")/out/omega-build/libomega_gpu.a" "$E/lib/" || return 1
80 cp "$TGT/release/aien-cli" "$BIN/aien-cli" || return 1
81 local j
82 for spec in "aien-inference-runtime strict_real_model" "aien-runtime runtime_end_to_end_tests"; do
83 set -- $spec
84 j=$(nice -n 10 cargo test --release --locked --no-run --message-format=json -p "$1" --test "$2") || return 1
85 exe=$(printf '%s\n' "$j" | jq -r "select(.reason==\"compiler-artifact\" and .executable!=null and .target.name==\"$2\") | .executable" | tail -1)
86 [ -n "$exe" ] || { echo "BUILD_FAIL no executable for $2"; return 1; }
87 cp "$exe" "$BIN/$2" || return 1
88 done
89 for t in omega_vs_hf_oracle strict_real_model_gate omega_vs_reference_real_model; do
90 "$BIN/strict_real_model" --list --ignored | grep -q "^$t: test" || echo "MISSING test $t in strict_real_model (sha lacks it)"
91 done
92 "$BIN/runtime_end_to_end_tests" --list | grep -q "^gb10_decode_batch_runs_paged_attention_batch_natively: test" ||
93 echo "MISSING test gb10_decode_batch_runs_paged_attention_batch_natively (sha lacks it)"
94 sha256sum "$BIN"/* "$E"/lib/libomega_gpu.a
95 echo "BUILD_OK sovereign-core=$SHA omega=$osha physics=$psha"
96}
97
98gpu_procs() {
99 local p gp
100 echo "## nvidia-smi compute apps"
101 nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv 2>&1
102 echo "## processes holding /dev/nvidia*"
103 for p in /proc/[0-9]*; do
104 if ls -l "$p/fd" 2>/dev/null | grep -q '/dev/nvidia'; then
105 gp=${p#/proc/}
106 echo "$gp $(ps -o etime=,rss=,args= -p "$gp" 2>/dev/null | cut -c1-200)"
107 fi
108 done
109 echo "## load"
110 uptime
111}
112
113identity() {
114 date -u +%FT%TZ
115 uname -a
116 nvidia-smi
117 nvidia-smi --query-gpu=name,uuid,driver_version,pci.bus_id,compute_cap --format=csv
118 gpu_procs
119 echo "## git"
120 echo "sovereign-core: $(git -C "$SC" rev-parse HEAD) dirty=[$(git -C "$SC" status --porcelain --untracked-files=no)]"
121 echo "omega: $(git -C "$AIEN_OMEGA_DIR" rev-parse HEAD) physics: $(git -C "$AIEN_PHYSICS_DIR" rev-parse HEAD)"
122 echo "## sha256"
123 sha256sum "$BIN"/* "$HF/model.safetensors" "$HF/tokenizer.json" \
124 "$SC/crates/aien-inference-abi/fixtures/tinyllama_oracle.safetensors" \
125 "$SC/crates/aien-inference-abi/fixtures/tinyllama_oracle_manifest.json" "$E"/lib/libomega_gpu.a
126}
127
128zero_cuda() {
129 bash scripts/zero-cuda-gate.sh --self-test || return 1
130 local rc=0 b
131 bash scripts/zero-cuda-gate.sh "$BIN"/* || rc=1
132 for b in "$BIN"/*; do
133 echo "## $b"
134 readelf -d "$b" | grep NEEDED
135 echo "undefined CUDA-like dynamic symbols:"
136 nm -D --undefined-only "$b" | awk '{print $NF}' | grep -E '^(cu[A-Z]|cuda[A-Z]|cublas|nvrtc[A-Z]|__cuda)' && rc=1 || echo " none"
137 echo "CUDA library names in strings:"
138 strings "$b" | grep -E 'lib(cuda|cudart|cublas|cublasLt|nvrtc|nvJitLink|cudnn)\.so' && rc=1 || echo " none"
139 done
140 echo "## static archive libomega_gpu.a"
141 nm "$E/lib/libomega_gpu.a" 2>/dev/null | awk '{print $NF}' | grep -E '^(cu[A-Z]|cuda[A-Z]|cublas|nvrtc[A-Z]|__cuda)' && rc=1 || echo " none"
142 return $rc
143}
144
145daemon_positive() {
146 local sock=$E/daemon.sock log=$E/daemon-positive.stderr
147 rm -f "$sock" "$E/daemon.pid" "$E/daemon.rc"
148 # The daemon runs as the direct child of a small subshell that records its pid and its
149 # exit code in files, so no shell variable or job-table detail can lose the exit code.
150 (
151 AIEN_GPU_BACKEND=omega AIEN_REQUIRE_CHECKPOINT=1 \
152 AIEN_MODEL_PATH="$HF/model.safetensors" AIEN_TOKENIZER_PATH="$HF/tokenizer.json" \
153 AIEN_RUNTIME_SOCK="$sock" "$BIN/aien-cli" --daemon > "$E/daemon-positive.stdout" 2> "$log" &
154 echo $! > "$E/daemon.pid"
155 wait $!
156 echo $? > "$E/daemon.rc"
157 ) &
158 local keeper=$!
159 until [ -s "$E/daemon.pid" ]; do sleep 0.2; done
160 local dpid
161 dpid=$(cat "$E/daemon.pid")
162 echo "DAEMON_PID $dpid"
163 until [ -S "$sock" ] || [ -s "$E/daemon.rc" ]; do sleep 1; done
164 if ! [ -S "$sock" ]; then
165 wait "$keeper"
166 echo "DAEMON_EXITED_BEFORE_SOCKET rc=$(cat "$E/daemon.rc")"
167 cat "$E/daemon-positive.stdout" "$log"
168 return 1
169 fi
170 cat "$E/daemon-positive.stdout"
171 printf '{"protocol_version":1,"request_id":1,"operation_id":%s,"operator_session":1,"command":{"StreamTurn":{"messages":[{"role":"system","content":"You are a sovereign AI assistant."},{"role":"user","content":"Explain the role of an operating system in one sentence."}],"max_tokens":16,"temperature":0.0}}}\n' "$(date +%s%N)" |
172 socat -t 86400 - "UNIX-CONNECT:$sock" > "$E/daemon-turn.jsonl"
173 echo "DAEMON_TURN_SOCAT rc=$?"
174 echo "## /proc/$dpid/maps libraries (CUDA libraries must be absent)"
175 awk '{print $6}' "/proc/$dpid/maps" 2>/dev/null | grep -E '\.so|/dev/nvidia' | sort -u
176 awk '{print $6}' "/proc/$dpid/maps" 2>/dev/null | grep -E 'lib(cuda|cudart|cublas|nvrtc|nvJitLink)' && echo "DAEMON_CUDA_MAPPED yes" || echo "DAEMON_CUDA_MAPPED no"
177 gpu_procs
178 printf '{"protocol_version":1,"request_id":2,"operation_id":%s,"operator_session":1,"command":"Shutdown"}\n' "$(date +%s%N)" |
179 socat -t 86400 - "UNIX-CONNECT:$sock"
180 wait "$keeper"
181 local drc
182 drc=$(cat "$E/daemon.rc" 2>/dev/null || echo missing)
183 echo "DAEMON_EXIT rc=$drc"
184 echo "## daemon stderr"
185 cat "$log"
186 echo "## turn"
187 cat "$E/daemon-turn.jsonl"
188 local ok=0
189 grep -q '"TurnFinished"' "$E/daemon-turn.jsonl" && echo "DAEMON_TURN_FINISHED yes" || { echo "DAEMON_TURN_FINISHED no"; ok=1; }
190 grep -q 'OmegaGb10Backend (native Omega engine, no CUDA, NVIDIA GB10 sm_121)' "$E/daemon-positive.stdout" && echo "DAEMON_BACKEND omega-native" || { echo "DAEMON_BACKEND not-omega"; ok=1; }
191 grep -qE 'STRICT_REAL_MODEL_VIOLATION|panicked' "$log" && { echo "DAEMON_STRICT_VIOLATION yes"; ok=1; } || echo "DAEMON_STRICT_VIOLATION no"
192 [ "$drc" = 0 ] || ok=1
193 return $ok
194}
195
196daemon_missing_checkpoint() {
197 AIEN_MODEL_PATH=/nonexistent/aien-l5/model.safetensors AIEN_RUNTIME_SOCK=$E/daemon-neg.sock \
198 "$BIN/aien-cli" --daemon
199 local rc=$?
200 echo "DAEMON_MISSING_CHECKPOINT rc=$rc"
201 [ "$rc" -ne 0 ] && ! [ -S "$E/daemon-neg.sock" ]
202}
203
204{
205 echo "L5-NATIVE CAND-1 batch sha=$SHA $(date -u +%FT%TZ)"
206 if step prepare prepare; then
207 osha=$(tr -d '[:space:]' < "$SC/omega.lock")
208 export AIEN_OMEGA_DIR=$O/wt-L5-NATIVE-omega-${osha:0:7}
209 export AIEN_PHYSICS_DIR=$O/wt-L5-NATIVE-physics-$(tr -d '[:space:]' < "$AIEN_OMEGA_DIR/physics.lock" | cut -c1-7)
210 cd "$SC" || exit 3
211 step identity identity
212 step zero_cuda zero_cuda
213 step strict_gate env AIEN_E2E_CHECKPOINT="$HF" AIEN_STRICT_RECEIPT="$E/receipt-strict-gate.json" \
214 "$BIN/strict_real_model" --ignored --nocapture --exact strict_real_model_gate
215 step omega_vs_ref env AIEN_E2E_CHECKPOINT="$HF" AIEN_STRICT_RECEIPT="$E/receipt-omega-vs-ref.json" \
216 "$BIN/strict_real_model" --ignored --nocapture --exact omega_vs_reference_real_model
217 step omega_vs_oracle env AIEN_E2E_CHECKPOINT="$HF" AIEN_STRICT_RECEIPT="$E/receipt-omega-vs-oracle.json" \
218 "$BIN/strict_real_model" --ignored --nocapture --exact omega_vs_hf_oracle
219 step runtime_e2e_gb10 env AIEN_REQUIRE_RELEASE=1 "$BIN/runtime_end_to_end_tests" --nocapture --test-threads=1 \
220 test_end_to_end_gb10_hardware_execution_if_available release_golden_path_records_whether_gb10_ran
221 step paged_batch_gb10 "$BIN/runtime_end_to_end_tests" --nocapture --test-threads=1 \
222 decode_batch_reaches_paged_attention_batch_on_reference gb10_decode_batch_runs_paged_attention_batch_natively
223 # A skipped GB10 body exits 0; these two steps make a skip a FAIL.
224 step gb10_bodies_ran sh -c '! grep -q "Skipping GB10" "$1" "$2"' _ "$E/runtime_e2e_gb10.log" "$E/paged_batch_gb10.log"
225 step paged_batch_verdict grep -q "GB10_PAGED_BATCH verdict: PASS" "$E/paged_batch_gb10.log"
226 step daemon_positive daemon_positive
227 step daemon_missing_checkpoint daemon_missing_checkpoint
228 step identity_after gpu_procs
229 else
230 echo "PREPARE FAILED: no chip step ran (NOT_RUN)"
231 fi
232 echo "## results"
233 cat "$E/results.txt"
234 echo "L5-NATIVE CAND-1 batch done $(date -u +%FT%TZ)"
235} 2>&1 | tee "$E/batch.log"