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 / scripts / bench / headstart-m6-ab.sh

205 lines · 10216 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Headstart M6 (#538): held A/B samples of provisional preparation, flag off
18# vs flag on, over the shapes of crates/aien-runtime/tests/headstart_ab.rs.
19# Measurement only: this script never edits the checkout, Cargo.toml, CI or
20# the toolchain. It builds the opt-in test target once, then runs ONE sample
21# per process, each under `quietlock hold` (owner HS_M6_OWNER, at most
22# HS_M6_HOLD_MINUTES), so no other build or test on the host runs during a
23# timed sample.
24#
25# Usage:
26# scripts/bench/headstart-m6-ab.sh SAMPLES OUT_DIR
27# Per sample index i (1..SAMPLES) and shape: the arms run in alternating
28# order (odd i: off then on, tags A B; even i: on then off), then an A/A pair
29# (off twice, tags AA1 AA2) unless HS_M6_AA=0.
30#
31# Environment (defaults in brackets):
32# HS_M6_BUILD [linked] linked: the real librx_compose (World commits);
33# stub: no World commit, every line says STUB and is
34# an overhead and correctness check, not a result.
35# HS_M6_OMEGA, HS_M6_PHYSICS, HS_M6_AIENOS
36# checkouts for the linked build, pinned exactly as
37# scripts/test-linked-compose.sh checks them (omega
38# HEAD = omega.lock, physics = omega physics.lock,
39# aienos holds omega aienos.lock).
40# HS_M6_SHAPES [chain parallel failure]
41# HS_M6_THREADS [4] worker threads = M2 max_concurrency, both arms.
42# HS_M6_AA [1] run the A/A pair.
43# HS_M6_OWNER [hs-m6], HS_M6_HOLD_MINUTES [5], HS_M6_REASON
44# HS_M6_TARGET_DIR [<repo>/target/hs-m6-<build>] separate target dir, so
45# a linked build never replaces the stub in target/.
46# HS_M6_PLATFORM [unlabelled] e.g. SPARK or CI-RUNNER; copied into the
47# manifest. Numbers from one platform say nothing
48# about another.
49# Output in OUT_DIR: samples.jsonl (one JSON line per sample, schema
50# headstart-m6-ab/v1), logs/, manifest.json, summary.txt (medians), and
51# failures.txt when a sample failed its correctness gates (exit 1).
52set -euo pipefail
53ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
54die() { echo "headstart-m6-ab: $*" >&2; exit 2; }
55SAMPLES=${1:?usage: headstart-m6-ab.sh SAMPLES OUT_DIR}
56OUT=${2:?usage: headstart-m6-ab.sh SAMPLES OUT_DIR}
57case "$SAMPLES" in '' | *[!0-9]*) die "SAMPLES must be a positive integer" ;; esac
58[ "$SAMPLES" -ge 1 ] || die "SAMPLES must be at least 1"
59BUILD=${HS_M6_BUILD:-linked}
60SHAPES=${HS_M6_SHAPES:-chain parallel failure}
61THREADS=${HS_M6_THREADS:-4}
62AA=${HS_M6_AA:-1}
63OWNER=${HS_M6_OWNER:-hs-m6}
64MINUTES=${HS_M6_HOLD_MINUTES:-5}
65REASON=${HS_M6_REASON:-headstart M6 A/B timing sample (#538)}
66PLATFORM=${HS_M6_PLATFORM:-unlabelled}
67QL=${HS_M6_QUIETLOCK_BIN:-quietlock}
68# Team rule: per-sample holds of at most 5 minutes.
69case "$MINUTES" in [1-5]) ;; *) echo "headstart-m6-ab: HS_M6_HOLD_MINUTES must be 1 to 5 (team rule)" >&2; exit 2 ;; esac
70export CARGO_TARGET_DIR=${HS_M6_TARGET_DIR:-$ROOT/target/hs-m6-$BUILD}
71command -v "$QL" >/dev/null 2>&1 || die "quietlock not found ($QL)"
72for s in $SHAPES; do
73 case "$s" in chain | parallel | failure) ;; *) die "unknown shape $s" ;; esac
74done
75mkdir -p "$OUT/logs"
76[ ! -e "$OUT/samples.jsonl" ] || die "$OUT/samples.jsonl exists: use a new OUT_DIR"
77
78unset AIEN_OMEGA_DIR AIEN_OMEGA_GPU_LIB AIEN_OMEGA_COMPOSE_LIB AIEN_OMEGA_COMPOSE_SHA AIEN_DEV_FALLBACK
79PINS="{}"
80case "$BUILD" in
81 linked)
82 OMW=$(cd "${HS_M6_OMEGA:?HS_M6_OMEGA (omega checkout at omega.lock)}" && pwd)
83 PHW=$(cd "${HS_M6_PHYSICS:?HS_M6_PHYSICS (physics checkout)}" && pwd)
84 AO=$(cd "${HS_M6_AIENOS:?HS_M6_AIENOS (aienos checkout)}" && pwd)
85 pin=$(tr -d '[:space:]' <"$ROOT/omega.lock")
86 [ "$(git -C "$OMW" rev-parse HEAD)" = "$pin" ] || die "omega HEAD != omega.lock $pin"
87 [ "$(git -C "$PHW" rev-parse HEAD)" = "$(tr -d '[:space:]' <"$OMW/physics.lock")" ] || die "physics HEAD != omega physics.lock"
88 [ "$(git -C "$AO" rev-parse HEAD)" = "$(tr -d '[:space:]' <"$OMW/aienos.lock")" ] || die "aienos HEAD != omega aienos.lock"
89 unset AIEN_FORCE_CPU_STUB
90 export AIEN_OMEGA_COMPOSE_DIR="$OMW" AIEN_PHYSICS_DIR="$PHW" AIEN_AIENOS_LOCK_REPO="$AO"
91 PINS="{\"omega\":\"$pin\",\"physics\":\"$(git -C "$PHW" rev-parse HEAD)\",\"aienos\":\"$(git -C "$AO" rev-parse HEAD)\"}"
92 ;;
93 stub)
94 unset AIEN_OMEGA_COMPOSE_DIR AIEN_PHYSICS_DIR AIEN_AIENOS_LOCK_REPO
95 export AIEN_FORCE_CPU_STUB=1
96 ;;
97 *) die "HS_M6_BUILD must be linked or stub" ;;
98esac
99
100# Wait while another session holds the quiet flag, then run under
101# `quietlock run`; exit 75 (taken meanwhile) waits and tries again.
102quiet_run() {
103 local rc
104 while :; do
105 until "$QL" check >/dev/null 2>&1; do sleep 20; done
106 set +e; "$QL" run -- "$@"; rc=$?; set -e
107 [ "$rc" -eq 75 ] || return "$rc"
108 done
109}
110
111echo "headstart-m6-ab: building the test target ($BUILD, CARGO_TARGET_DIR=$CARGO_TARGET_DIR)"
112cd "$ROOT"
113quiet_run cargo test -p aien-runtime --features provisional-prep --test headstart_ab \
114 --no-run --message-format=json -j 8 >"$OUT/logs/build.json" 2>"$OUT/logs/build.err" \
115 || { tail -20 "$OUT/logs/build.err" >&2; die "build failed"; }
116BIN=$(grep -o '"executable":"[^"]*headstart_ab[^"]*"' "$OUT/logs/build.json" | tail -1 | sed 's/^"executable":"//; s/"$//')
117[ -x "$BIN" ] || die "test executable not found in the build output"
118if [ "$BUILD" = linked ] && grep -q "building the stub" "$OUT/logs/build.err" "$OUT/logs/build.json"; then
119 die "a stub was built: the composition library is not linked"
120fi
121
122cat >"$OUT/manifest.json" <<EOF
123{"schema":"headstart-m6-ab-manifest/v1","issue":"aien-spark/aien-sovereign-core#538",
124 "git_head":"$(git rev-parse HEAD)","git_dirty":$( [ -z "$(git status --porcelain --untracked-files=no)" ] && echo false || echo true ),
125 "rustc":"$(rustc -V)","build":"$BUILD","pins":$PINS,"platform":"$PLATFORM",
126 "host":"$(hostname)","arch":"$(uname -m)","kernel":"$(uname -r)","nproc":$(nproc),
127 "samples":$SAMPLES,"shapes":"$SHAPES","threads":$THREADS,"aa":$AA,
128 "quiet_hold":{"owner":"$OWNER","max_minutes":$MINUTES},
129 "binary":"$BIN","started":"$(date -u +%Y-%m-%dT%H:%M:%SZ)"}
130EOF
131
132FAILED=0
133WANT=$( [ "$BUILD" = linked ] && echo LINKED || echo STUB )
134# One held sample: env for the test, one process, appended to samples.jsonl.
135held_sample() {
136 local i=$1 shape=$2 arm=$3 tag=$4 log rc before after line
137 log="$OUT/logs/s$(printf %03d "$i")-$shape-$tag-$arm.log"
138 before=$(wc -l 2>/dev/null <"$OUT/samples.jsonl" || echo 0)
139 while :; do
140 until "$QL" check >/dev/null 2>&1; do sleep 20; done
141 set +e
142 HS_M6_ARM=$arm HS_M6_SHAPE=$shape HS_M6_SAMPLE=$i HS_M6_TAG=$tag HS_M6_THREADS=$THREADS \
143 HS_M6_OUT="$OUT/samples.jsonl" \
144 "$QL" hold --owner "$OWNER" --minutes "$MINUTES" --reason "$REASON" -- \
145 "$BIN" --ignored --exact headstart_ab_sample --nocapture --test-threads=1 >"$log" 2>&1
146 rc=$?
147 set -e
148 # 75 counts as a refusal only with quietlock's own line (as lanes.sh checks).
149 [ "$rc" -eq 75 ] && tail -n 1 "$log" | grep -q "^quietlock: QUIETLOCK_REFUSED " || break
150 echo "headstart-m6-ab: quiet flag taken by someone else, waiting" >&2
151 done
152 # Exactly one new line, and it must be this sample (index, shape, arm,
153 # tag) from the expected build: a linked run must never contain a STUB
154 # line (a cached stub build would otherwise pass unnoticed).
155 if [ "$rc" -eq 0 ]; then
156 after=$(wc -l 2>/dev/null <"$OUT/samples.jsonl" || echo 0)
157 line=$(tail -n 1 "$OUT/samples.jsonl" 2>/dev/null || true)
158 if [ "$after" -ne $((before + 1)) ]; then
159 rc=3
160 else
161 for kv in "\"build\":\"$WANT\"" "\"sample\":$i" "\"shape\":\"$shape\"" "\"arm\":\"$arm\"" "\"tag\":\"$tag\""; do
162 printf "%s\n" "$line" | grep -qE "$kv([,}])" || rc=3
163 done
164 fi
165 fi
166 if [ "$rc" -ne 0 ]; then
167 FAILED=$((FAILED + 1))
168 echo "sample $i $shape $arm $tag: exit $rc (see $log)" >>"$OUT/failures.txt"
169 fi
170 echo "headstart-m6-ab: sample $i $shape $tag $arm exit $rc"
171}
172
173for i in $(seq 1 "$SAMPLES"); do
174 for shape in $SHAPES; do
175 if [ $((i % 2)) -eq 1 ]; then
176 held_sample "$i" "$shape" off A; held_sample "$i" "$shape" on B
177 else
178 held_sample "$i" "$shape" on B; held_sample "$i" "$shape" off A
179 fi
180 if [ "$AA" = 1 ]; then
181 held_sample "$i" "$shape" off AA1; held_sample "$i" "$shape" off AA2
182 fi
183 done
184done
185
186# Medians of wall_ms per shape and tag (observed values only).
187field() { grep -o "\"$1\":[^,}]*" | head -1 | sed "s/^\"$1\"://; s/\"//g"; }
188{
189 echo "build=$BUILD platform=$PLATFORM samples=$SAMPLES threads=$THREADS (wall_ms medians; tag A=off B=on AA1/AA2=off)"
190 for shape in $SHAPES; do
191 for tag in A B AA1 AA2; do
192 vals=$(grep "\"shape\":\"$shape\"" "$OUT/samples.jsonl" 2>/dev/null | grep "\"tag\":\"$tag\"" | while read -r l; do printf '%s\n' "$l" | field wall_ms; done | sort -g || true)
193 n=$(printf '%s\n' "$vals" | grep -c . || true)
194 [ "$n" -gt 0 ] || continue
195 med=$(printf '%s\n' "$vals" | awk -v n="$n" 'NR == int((n + 1) / 2) { a = $1 } NR == int(n / 2) + 1 { b = $1 } END { printf "%.3f", (a + b) / 2 }')
196 echo "$shape $tag n=$n median_wall_ms=$med$( [ "$shape" = failure ] && echo " (not a timing comparison: the on arm waits on purpose)")"
197 done
198 done
199} >"$OUT/summary.txt"
200cat "$OUT/summary.txt"
201sed -i "s/}\$/,\"finished\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"failed_samples\":$FAILED}/" "$OUT/manifest.json"
202if [ "$FAILED" -gt 0 ]; then
203 echo "headstart-m6-ab: $FAILED sample(s) failed (failures.txt)" >&2
204 exit 1
205fi