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
GitHub aien-dev/aien-sovereign-core-mv#656 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/aien-sovereign-core-mv/patches/a2dcb1484934bb24.bundle -o a2dcb1484934bb24.bundle git fetch a2dcb1484934bb24.bundle refs/pull/656/head
Provenance
github-import 1
aien-dev/aien-sovereign-core-mv
656
76b1ae98ba301466a300587999031b7faf31fb6d
{"kind":"github-import","owner":"aien-dev","repo":"aien-sovereign-core-mv","number":656,"url":"https://github.com/aien-dev/aien-sovereign-core-mv/pull/656","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:37:47Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index 468dd7f8..40ce1297 100644 --- a/.crumb +++ b/.crumb @@ -106,8 +106,8 @@ "purpose": "" }, { - "digest": "af5f9d6a21e7bdc0bce013df14b00648a9571513c9b719874799917e19e4e203", - "last_commit": "53beb962", + "digest": "f7850b9890e153f1a930c5c6cf4962f19f0e2b5393ef8473a172eba7a74aa3fe", + "last_commit": "98de0ebd", "name": "scripts", "purpose": "" }, @@ -124,15 +124,15 @@ "purpose": "Local CI sandbox exec contract (C8), aien-run user/caches install, Forgejo trigger hook, health " } ], - "children_root": "sha256:ab951d662c7c12e63d462c163e2f5efff2d207bf22e5b6be32f5537a5735e522", - "compiled_at": "2026-10-30T03:34:03Z", + "children_root": "sha256:4e64ddf58cab7780667b2e4013ffe4d320d15388d42c1505746798b9f7efbf06", + "compiled_at": "2026-10-30T03:35:22Z", "compiler": "crumb-compile/1", - "digest": "sha256:049a1845ce1f40dac5dc933c76d3897c9e8ecc914a515d6a5ffb48b150eff975", + "digest": "sha256:539ae79c4c11a164e3e904500f3c761d9b85fbd8fde03d5345c40814bc82ffbb", "evidence_files": 3591, "evidence_root": "sha256:6c2e9cccc6ed61200b4fcb946ede8cb91e143d50573afb34e011daa9966cf957", - "files": 8078, - "generated_at_commit": "c07cfb42b2d5171e55c28dc9bdf4410cbca22af5", - "source_tree": "sha256:1185898be2aac726fc049a6c0148bceb6af9531f81411abd6e37bd0e88d738ec" + "files": 8082, + "generated_at_commit": "f6316259523b283cbf991720b4e18b32ee88d500", + "source_tree": "sha256:84c6f98efc92640ec9733be6285e257bd7a3f58176082bd250bee0ca65fd64d4" } }, "history": [], diff --git a/docs/inference/own30b-quiet-window.md b/docs/inference/own30b-quiet-window.md new file mode 100644 index 00000000..8326f575 --- /dev/null +++ b/docs/inference/own30b-quiet-window.md @@ -0,0 +1,35 @@ +# OWN-30B: measuring in an uncontended GPU window + +Issue #625. OWN-30B decode ran at about 36 to 39 tok/s on an idle GB10 and about 2.4 to 2.6 tok/s while a heavyweight model shared the GPU (evidence: `docs/inference/evidence/own30b-omega4799-20261015/NOTES.md`). That gap is hardware contention, not a kernel change, so a speed number means nothing unless the run says whether the GPU was shared. + +## The runner + +`scripts/bench/own30b-quiet-run.sh` wraps one benchmark or HTTP session: + +``` +scripts/bench/own30b-quiet-run.sh --owner <you> --out <new dir> \ + --server-pid <aien-serve-http pid> --server-bin <path to aien-serve-http> \ + --model <model dir> --omega-pin <omega commit> --minutes 10 \ + -- <benchmark client command> +``` + +1. **Preflight.** Records GPU compute processes, GPU utilization, AIEN listeners, repo HEAD, server binary SHA-256, model path and size, Omega pin and `OWN30B_DECODE_GRAPH`. +2. **Refusal.** Any GPU compute process other than `--server-pid`, or an `nvidia-smi` that cannot answer, stops the run with exit 3 before anything starts. `--allow-contended "<why>"` runs it anyway, records the reason and marks the run not comparable. +3. **Quiet hold.** The command runs under `quietlock hold` (1 to 20 minutes, owner and reason recorded). Ctrl-C or SIGTERM stops the command through quietlock and the flag is released. A quiet flag already held by someone else stops the run with exit 75. +4. **Postflight.** The same GPU query again. A foreign process seen then also marks the run not comparable. +5. **Manifest.** `<out>/manifest.json` (schema `own30b-quiet-run/v1`) holds everything above, the exact command, the exit status, `comparable` and every reason it is false. + +Only a manifest with `"comparable": true` supports an uncontended speed claim. + +## What it does not do + +- It never takes `/tmp/aien-gb10.lock`. `aien-serve-http` takes that lock itself for each generation; holding it from outside would deadlock the server. +- File locks coordinate cooperating workloads only. A GPU process that ignores the quiet flag is detected, not excluded, and a process that starts and stops between the two samples is not seen. +- It never kills, pauses or renices anything. + +## Asking for a window + +1. Check `quietlock check`. If someone holds the flag, wait or ask the holder; do not remove a live flag. +2. Check `nvidia-smi`. If another model is loaded on the GPU, ask its owner to stop it for the window. Do not stop it yourself. +3. Run the runner. If it refuses as contended, the manifest names the process. +4. Self-test (no GPU, fakes only): `bash scripts/bench/own30b-quiet-run-selftest.sh`. With `QUIETLOCK_REAL=$(command -v quietlock)` it repeats the hold and interrupt cases against the real binary in a private state directory. diff --git a/scripts/.crumb b/scripts/.crumb index 4e5fac04..7a1aa432 100644 --- a/scripts/.crumb +++ b/scripts/.crumb @@ -4,14 +4,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-26T15:46:25Z", + "compiled_at": "2026-10-27T01:46:18Z", "compiler": "crumb-compile/1", - "digest": "sha256:af5f9d6a21e7bdc0bce013df14b00648a9571513c9b719874799917e19e4e203", + "digest": "sha256:f7850b9890e153f1a930c5c6cf4962f19f0e2b5393ef8473a172eba7a74aa3fe", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 56, - "generated_at_commit": "bf15e82a44fbfa04cbffdafce433d4cd5ed66df4", - "source_tree": "sha256:a1ba69a25e552a054b8b894064f4e7e464b8c4faf2b97a4cfd6b42daa1c5564e" + "files": 58, + "generated_at_commit": "98de0ebd3861a310b39cf42c051ce3c9efab3d24", + "source_tree": "sha256:9a49d8ab0cbac6f0d79267536b97b168fef0b69bd01480727a79b8b55a3f00d2" } }, "parent": { diff --git a/scripts/bench/own30b-quiet-run-selftest.sh b/scripts/bench/own30b-quiet-run-selftest.sh new file mode 100755 index 00000000..945b3c24 --- /dev/null +++ b/scripts/bench/own30b-quiet-run-selftest.sh @@ -0,0 +1,181 @@ +#!/usr/bin/env bash +# Self-test for scripts/bench/own30b-quiet-run.sh (#625). Bash + jq only. +# Fakes quietlock, nvidia-smi, ss and flock on PATH; the "server" is a +# command that sleeps or exits. Covers: normal completion, child failure, +# SIGINT, SIGTERM, repeat invocations, contended refusal, recorded override, +# a declared server PID, a foreign process seen only after the run, a quiet +# flag already held, and that /tmp/aien-gb10.lock is never touched. +# With QUIETLOCK_REAL=/path/to/quietlock the hold and interrupt cases run +# again against the real binary in a private QUIETLOCK_DIR. +# +# bash scripts/bench/own30b-quiet-run-selftest.sh (exit 0 = all checks passed) +set -uo pipefail + +HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +RUN="$HERE/own30b-quiet-run.sh" +T=$(mktemp -d "${TMPDIR:-/tmp}/own30b-quiet-run-selftest.XXXXXX") +if [ "${QR_SELFTEST_KEEP:-0}" = 1 ]; then echo "keeping $T"; else trap 'rm -rf "$T"' EXIT; fi +PASS=0; FAIL=0 +check() { # check <name> <command...> + local name=$1; shift + if "$@" >/dev/null 2>&1; then PASS=$((PASS + 1)); echo "ok $name" + else FAIL=$((FAIL + 1)); echo "FAIL $name"; fi +} +jqt() { jq -e "$@"; } + +BIN="$T/bin"; QD="$T/ql"; mkdir -p "$BIN" "$QD" +cat >"$BIN/quietlock" <<'FAKE' +#!/usr/bin/env bash +# Fake quietlock: a flag file, acquire/release lines in a log, and TERM +# forwarded to the held command (the real one forwards to its process group). +D=${FAKE_QL_DIR:?} +case "$1" in + check) [ ! -e "$D/held" ] || { echo "quietlock: QUIETLOCK_REFUSED fake" >&2; exit 75; }; exit 0 ;; + hold) + shift; owner="" minutes="" + while [ "$1" != -- ]; do case "$1" in --owner) owner=$2 ;; --minutes) minutes=$2 ;; esac; shift 2; done + shift + [ ! -e "$D/held" ] || { echo "quietlock: QUIETLOCK_REFUSED fake" >&2; exit 75; } + : >"$D/held"; echo "acquire $owner $minutes" >>"$D/log" + "$@" & c=$! + trap 'echo "forward TERM" >>"$D/log"; kill -TERM $c 2>/dev/null' TERM + while :; do wait $c; rc=$?; kill -0 $c 2>/dev/null || break; done + rm -f "$D/held"; echo "release $rc" >>"$D/log"; exit $rc ;; + *) exit 2 ;; +esac +FAKE +cat >"$BIN/nvidia-smi" <<'FAKE' +#!/usr/bin/env bash +[ ! -e "${FAKE_SMI_DIR:?}/broken" ] || exit 9 +case "$1" in + --query-gpu=*) echo "NVIDIA GB10, 0 %, [N/A], [N/A]" ;; + --query-compute-apps=*) cat "$FAKE_SMI_DIR/apps" 2>/dev/null; true ;; +esac +FAKE +cat >"$BIN/ss" <<'FAKE' +#!/usr/bin/env bash +echo 'LISTEN 0 128 127.0.0.1:18091 0.0.0.0:* users:(("aien-serve-http",pid=4242,fd=13))' +echo 'LISTEN 0 128 127.0.0.1:18080 0.0.0.0:* users:(("cortex-rs",pid=5060,fd=12))' +FAKE +cat >"$BIN/flock" <<'FAKE' +#!/usr/bin/env bash +echo "flock $*" >>"${FAKE_FLOCK_LOG:?}"; exit 1 +FAKE +chmod +x "$BIN"/* +export PATH="$BIN:$PATH" FAKE_QL_DIR="$QD" FAKE_SMI_DIR="$T/smi" FAKE_FLOCK_LOG="$T/flock.log" +mkdir -p "$FAKE_SMI_DIR" +reset() { rm -f "$QD/held" "$QD/log" "$FAKE_SMI_DIR/apps" "$FAKE_SMI_DIR/broken"; } +qr() { # qr <out> [runner args...] -- cmd... (exit status in $RC) + local out=$1; shift + "$RUN" --owner selftest --minutes 2 --out "$T/$out" "$@" 2>"$T/$out.err"; RC=$? +} +M() { echo "$T/$1/manifest.json"; } +not_held() { [ ! -e "$QD/held" ]; } +log_has() { grep -qx "$1" "$QD/log"; } + +# 1. idle GPU, normal completion +reset; qr ok1 --server-bin "$BIN/ss" --model "$BIN" --omega-pin abc123 -- true +check "normal: exit 0" test "$RC" -eq 0 +check "normal: hold acquired with owner and bound" log_has "acquire selftest 2" +check "normal: hold released" log_has "release 0" +check "normal: no flag left" not_held +check "normal: manifest comparable" jqt '.schema == "own30b-quiet-run/v1" and .comparable and .outcome == "completed" and .exit_status == 0' "$(M ok1)" +check "normal: identity recorded" jqt '(.identity.repo_head | length) >= 7 and (.identity.server_bin.sha256 | length) == 64 and .identity.model.kib >= 0 and .identity.omega_pin == "abc123"' "$(M ok1)" +check "normal: GPU line kept raw (N/A memory)" jqt '.preflight.gpu == "NVIDIA GB10, 0 %, [N/A], [N/A]" and .postflight.available' "$(M ok1)" +check "normal: only AIEN listeners recorded" jqt '.preflight.aien_listeners | length == 1 and (.[0] | test("aien-serve-http"))' "$(M ok1)" +check "normal: command recorded" jqt '.command == ["true"]' "$(M ok1)" + +# 2. child failure +reset; qr fail1 -- sh -c 'exit 7' +check "child failure: exit status passed through" test "$RC" -eq 7 +check "child failure: hold released" log_has "release 7" +check "child failure: no flag left" not_held +check "child failure: outcome" jqt '.outcome == "exit 7" and .exit_status == 7' "$(M fail1)" + +# 3. repeat invocations, and a reused output directory +reset; qr rep1 -- true; r1=$RC; qr rep2 -- true; r2=$RC +check "repeat: both runs succeed" test "$r1$r2" = 00 +check "repeat: two acquire/release pairs" test "$(grep -c '^acquire ' "$QD/log")$(grep -c '^release 0' "$QD/log")" = 22 +qr rep1 -- true +check "NEGATIVE: reused --out refused" test "$RC" -eq 2 + +# 4/5. interrupts: the held command is stopped and the flag released +interrupt() { # interrupt <out> <signal> <expected exit> + reset; rm -f "$T/$1.child" + # Job control on: a background job of a non-interactive shell starts with + # SIGINT ignored, which a terminal-run (foreground) runner never has. + set -m + "$RUN" --owner selftest --minutes 2 --out "$T/$1" -- sh -c 'echo $$ >"$0"; exec sleep 30' "$T/$1.child" 2>"$T/$1.err" & + local rp=$! i + set +m + for i in $(seq 1 100); do [ -s "$T/$1.child" ] && break; sleep 0.1; done + kill "-$2" "$rp"; wait "$rp"; RC=$? + check "$2: runner exits $3" test "$RC" -eq "$3" + check "$2: no flag left" not_held + check "$2: held command stopped" bash -c "! kill -0 \$(cat '$T/$1.child')" + check "$2: manifest says interrupted, not comparable" jqt --arg s "SIG$2" '.outcome == "interrupted: \($s)" and (.comparable | not)' "$(M "$1")" +} +interrupt int1 INT 130 +check "INT: passed on as TERM" log_has "forward TERM" +interrupt term1 TERM 143 + +# 6. contended: refused, nothing run, no hold taken +reset; printf '999, ./max-model, 70000 MiB\n' >"$FAKE_SMI_DIR/apps" +qr busy1 -- touch "$T/busy1.ran" +check "contended: exit 3" test "$RC" -eq 3 +check "contended: command not run" test ! -e "$T/busy1.ran" +check "contended: no hold taken" test ! -e "$QD/log" +check "contended: reason names the process" jqt '(.comparable | not) and (.not_comparable_reasons[0] | test("999 ./max-model")) and .override == null' "$(M busy1)" + +# 7. contended with override: runs, recorded, not comparable +qr busy2 --allow-contended "MAX model shares the GPU on purpose" -- touch "$T/busy2.ran" +check "override: runs" test "$RC" -eq 0 -a -e "$T/busy2.ran" +check "override: reason recorded, not comparable" jqt '(.comparable | not) and .override.reason == "MAX model shares the GPU on purpose" and (.not_comparable_reasons | any(startswith("override:")))' "$(M busy2)" + +# 8. the declared server is allowed on the GPU +reset; printf '4242, ./aien-serve-http, 81717 MiB\n' >"$FAKE_SMI_DIR/apps" +qr srv1 --server-pid 4242 -- true +check "server pid: comparable" jqt '.comparable and .server_pids == [4242] and (.preflight.compute_apps | length) == 1 and (.preflight.foreign | length) == 0' "$(M srv1)" + +# 9. a foreign process that appears during the run +reset; qr post1 -- sh -c "printf '777, ./repro2, 9 MiB\n' >'$FAKE_SMI_DIR/apps'" +check "postflight: run completes" test "$RC" -eq 0 +check "postflight: foreign process marks not comparable" jqt '(.comparable | not) and (.not_comparable_reasons[0] | test("^postflight: .*777"))' "$(M post1)" + +# 10. nvidia-smi unavailable never counts as idle +reset; : >"$FAKE_SMI_DIR/broken" +qr nosmi -- touch "$T/nosmi.ran" +check "no nvidia-smi: refused" test "$RC" -eq 3 -a ! -e "$T/nosmi.ran" +check "no nvidia-smi: recorded" jqt '(.preflight.available | not) and (.not_comparable_reasons[0] | test("unavailable"))' "$(M nosmi)" + +# 11. quiet flag already held by someone else +reset; : >"$QD/held" +qr held1 -- touch "$T/held1.ran" +check "quiet held: exit 75, command not run" test "$RC" -eq 75 -a ! -e "$T/held1.ran" +check "quiet held: other holder's flag untouched" test -e "$QD/held" + +# 12. usage errors +reset +check "NEGATIVE: --minutes 21 refused" bash -c "! '$RUN' --owner x --minutes 21 --out '$T/u1' -- true" +check "NEGATIVE: missing --owner refused" bash -c "! '$RUN' --out '$T/u2' -- true" +check "NEGATIVE: no command refused" bash -c "! '$RUN' --owner x --out '$T/u3' --" + +# 13. the GPU lock is never taken from outside the server +check "never runs flock" test ! -e "$FAKE_FLOCK_LOG" +check "script does not open the GPU lock" bash -c "! grep -v '^#' '$RUN' | grep -q 'aien-gb10.lock'" + +# 14. optional: the real quietlock in a private state dir +if [ -n "${QUIETLOCK_REAL:-}" ]; then + export OWN30B_QR_QUIETLOCK="$QUIETLOCK_REAL" QUIETLOCK_DIR="$T/realq"; mkdir -p "$QUIETLOCK_DIR" + reset; qr real1 -- true + check "real quietlock: normal run releases" test "$RC" -eq 0 -a ! -e "$QUIETLOCK_DIR/.spark-quiet" + qr real2 -- sh -c 'exit 5' + check "real quietlock: child failure releases" test "$RC" -eq 5 -a ! -e "$QUIETLOCK_DIR/.spark-quiet" + interrupt realint INT 130 + check "real quietlock: INT releases" test ! -e "$QUIETLOCK_DIR/.spark-quiet" + interrupt realterm TERM 143 + check "real quietlock: TERM releases" test ! -e "$QUIETLOCK_DIR/.spark-quiet" +fi + +echo "own30b-quiet-run-selftest: $PASS passed, $FAIL failed" +[ "$FAIL" -eq 0 ] diff --git a/scripts/bench/own30b-quiet-run.sh b/scripts/bench/own30b-quiet-run.sh new file mode 100755 index 00000000..a25d36f4 --- /dev/null +++ b/scripts/bench/own30b-quiet-run.sh @@ -0,0 +1,205 @@ +#!/usr/bin/env bash +# Run one OWN-30B HTTP or benchmark session inside a bounded Spark quiet window +# (#625), and record whether the GPU was really uncontended. +# +# What it does, in order: +# 1. Preflight: GPU compute processes, GPU utilization, AIEN listeners and the +# identity of what is being measured (repo HEAD, server binary SHA-256, +# model path and size, Omega pin, OWN30B_DECODE_GRAPH). +# 2. Refuses (exit 3, command not run) when a GPU compute process other than +# the declared server (--server-pid) is present, or when nvidia-smi cannot +# say, unless --allow-contended REASON is given. An override runs the +# command, records the reason and marks the run not comparable. +# 3. Runs CMD under `quietlock hold` (bounded, owner and reason recorded; +# quietlock releases the flag when CMD and its process group exit). +# 4. Postflight: the same GPU query again. A foreign process seen then also +# marks the run not comparable. +# 5. Writes OUT_DIR/manifest.json (schema own30b-quiet-run/v1). +# +# It never takes /tmp/aien-gb10.lock: aien-serve-http takes that lock itself +# for each generation, and holding it from outside would deadlock the server. +# The quiet flag and the GPU lock serve different purposes. +# +# File locks only coordinate cooperating workloads. A GPU process that ignores +# the quiet flag is detected (preflight and postflight), never excluded, and +# this script never kills, pauses or renices anything. A process that starts +# and stops between the two samples is not seen. +# +# Usage: +# scripts/bench/own30b-quiet-run.sh --owner ID --out DIR [options] -- CMD... +# Options: +# --minutes N quiet hold bound, 1 to 20 [10] (quietlock needs an +# approval token above 20; this script does not go there) +# --reason TEXT recorded in the quiet flag and the manifest +# --server-pid PID the server under test; allowed on the GPU (repeatable) +# --server-bin PATH server binary, hashed into the manifest +# --model PATH model file or directory, path and size recorded +# --omega-pin TEXT Omega pin of the native backend, recorded as given +# --allow-contended TEXT run even when the GPU is not idle; TEXT is recorded +# Environment: OWN30B_QR_QUIETLOCK [quietlock], OWN30B_QR_NVIDIA_SMI +# [nvidia-smi], OWN30B_QR_SS [ss] (the self-test points these at fakes). +# +# Exit: CMD's exit status; 2 usage; 3 refused as contended; 75 quiet flag +# already held (command not run); 128+N when interrupted by signal N (the held +# command is stopped with SIGTERM through quietlock and the flag released). +set -uo pipefail +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" +die() { echo "own30b-quiet-run: $*" >&2; exit 2; } +QL=${OWN30B_QR_QUIETLOCK:-quietlock} +SMI=${OWN30B_QR_NVIDIA_SMI:-nvidia-smi} +SS=${OWN30B_QR_SS:-ss} + +OWNER="" OUT="" MINUTES=10 REASON="OWN-30B uncontended measurement (#625)" +SERVER_BIN="" MODEL="" OMEGA_PIN="" OVERRIDE="" SERVER_PIDS=() +while [ $# -gt 0 ]; do + case "$1" in + --owner) OWNER=${2:-}; shift 2 ;; + --out) OUT=${2:-}; shift 2 ;; + --minutes) MINUTES=${2:-}; shift 2 ;; + --reason) REASON=${2:-}; shift 2 ;; + --server-pid) SERVER_PIDS+=("${2:-}"); shift 2 ;; + --server-bin) SERVER_BIN=${2:-}; shift 2 ;; + --model) MODEL=${2:-}; shift 2 ;; + --omega-pin) OMEGA_PIN=${2:-}; shift 2 ;; + --allow-contended) OVERRIDE=${2:-}; [ -n "$OVERRIDE" ] || die "--allow-contended needs a reason"; shift 2 ;; + --) shift; break ;; + *) die "unknown argument $1 (usage: --owner ID --out DIR [options] -- CMD...)" ;; + esac +done +[ $# -gt 0 ] || die "no command after --" +[ -n "$OWNER" ] || die "--owner is required" +[ -n "$OUT" ] || die "--out is required" +case "$MINUTES" in '' | *[!0-9]*) die "--minutes must be 1 to 20" ;; esac +[ "$MINUTES" -ge 1 ] && [ "$MINUTES" -le 20 ] || die "--minutes must be 1 to 20" +for p in ${SERVER_PIDS[@]+"${SERVER_PIDS[@]}"}; do + case "$p" in '' | *[!0-9]*) die "--server-pid must be a number" ;; esac +done +command -v jq >/dev/null 2>&1 || die "jq not found" +command -v "$QL" >/dev/null 2>&1 || die "quietlock not found ($QL)" +mkdir -p "$OUT" || die "cannot create $OUT" +[ ! -e "$OUT/manifest.json" ] || die "$OUT/manifest.json exists: use a new --out" + +now() { date -u +%Y-%m-%dT%H:%M:%SZ; } +allowed_json=$(printf '%s\n' ${SERVER_PIDS[@]+"${SERVER_PIDS[@]}"} | jq -R -s -c 'split("\n") | map(select(length > 0) | tonumber)') +CMD_JSON=$(jq -n -c '$ARGS.positional' --args -- "$@") + +# gpu_sample: one JSON object with the raw GPU line, the compute processes and +# the foreign ones (not a declared server). available=false when nvidia-smi +# is missing or fails; that never counts as idle. +gpu_sample() { + local gpu apps + if ! gpu=$("$SMI" --query-gpu=name,utilization.gpu,memory.used,memory.total --format=csv,noheader 2>/dev/null) || + ! apps=$("$SMI" --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>/dev/null); then + jq -n -c --arg t "$(now)" '{at: $t, available: false, gpu: null, compute_apps: [], foreign: []}' + return + fi + jq -n -c --arg t "$(now)" --arg gpu "$gpu" --arg apps "$apps" --argjson allowed "$allowed_json" ' + ($apps | split("\n") | map(select(test("\\S")) | split(", ") + | {pid: (.[0] | tonumber? // .[0]), name: .[1], used_memory: .[2]})) as $a + | {at: $t, available: true, gpu: $gpu, compute_apps: $a, + foreign: [$a[] | select(.pid as $p | $allowed | index($p) | not)]}' +} + +listeners() { + local out + if out=$("$SS" -ltnpH 2>/dev/null); then + printf '%s\n' "$out" | grep -i aien | jq -R -s -c 'split("\n") | map(select(length > 0) | gsub("\\s+"; " "))' + else + echo null + fi +} + +sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi; } + +identity() { + local head dirty bin_sha="" model_kib="" + head=$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || echo unknown) + if [ -n "$(git -C "$ROOT" status --porcelain 2>/dev/null)" ]; then dirty=true; else dirty=false; fi + if [ -n "$SERVER_BIN" ]; then [ -f "$SERVER_BIN" ] && bin_sha=$(sha256 "$SERVER_BIN"); fi + if [ -n "$MODEL" ]; then [ -e "$MODEL" ] && model_kib=$(du -skL "$MODEL" 2>/dev/null | cut -f1); fi + jq -n -c --arg head "$head" --argjson dirty "$dirty" --arg bin "$SERVER_BIN" --arg sha "$bin_sha" \ + --arg model "$MODEL" --arg kib "$model_kib" --arg pin "$OMEGA_PIN" --arg graph "${OWN30B_DECODE_GRAPH-}" ' + {repo_head: $head, repo_dirty: $dirty, + server_bin: (if $bin == "" then null else {path: $bin, sha256: (if $sha == "" then null else $sha end)} end), + model: (if $model == "" then null else {path: $model, kib: ($kib | tonumber? // null)} end), + omega_pin: (if $pin == "" then null else $pin end), + own30b_decode_graph: (if $graph == "" then null else $graph end)}' +} + +STARTED=$(now) +PRE=$(gpu_sample) +LISTEN=$(listeners) +IDENT=$(identity) +REASONS='[]' +add_reason() { REASONS=$(jq -c --arg r "$1" '. + [$r]' <<<"$REASONS"); } +if [ "$(jq -r .available <<<"$PRE")" != true ]; then + add_reason "preflight: nvidia-smi unavailable, GPU idleness not established" +fi +if [ "$(jq '.foreign | length' <<<"$PRE")" -gt 0 ]; then + add_reason "preflight: foreign GPU compute process present: $(jq -r '[.foreign[] | "\(.pid) \(.name)"] | join(", ")' <<<"$PRE")" +fi + +POST=null RC=0 OUTCOME="" +write_manifest() { + jq -n --arg owner "$OWNER" --arg reason "$REASON" --argjson minutes "$MINUTES" \ + --arg started "$STARTED" --arg ended "$(now)" --argjson rc "$RC" --arg outcome "$OUTCOME" \ + --argjson reasons "$REASONS" --arg override "$OVERRIDE" --argjson pre "$PRE" --argjson post "$POST" \ + --argjson listeners "$LISTEN" --argjson identity "$IDENT" --argjson allowed "$allowed_json" --argjson cmd "$CMD_JSON" ' + {schema: "own30b-quiet-run/v1", owner: $owner, reason: $reason, hold_minutes: $minutes, + command: $cmd, started: $started, ended: $ended, exit_status: $rc, outcome: $outcome, + comparable: ($reasons | length == 0), not_comparable_reasons: $reasons, + override: (if $override == "" then null else {reason: $override} end), + server_pids: $allowed, identity: $identity, preflight: ($pre + {aien_listeners: $listeners}), + postflight: $post, + note: "File locks coordinate cooperating workloads only; a GPU process that ignores the quiet flag is detected by the preflight and postflight samples, never excluded."}' \ + >"$OUT/manifest.json" +} + +if [ "$(jq length <<<"$REASONS")" -gt 0 ] && [ -z "$OVERRIDE" ]; then + RC=3 OUTCOME="refused: GPU not idle" + write_manifest + echo "own30b-quiet-run: refused, GPU not idle (see $OUT/manifest.json); --allow-contended REASON runs it as not comparable" >&2 + exit 3 +fi +[ -z "$OVERRIDE" ] || add_reason "override: $OVERRIDE" + +if ! "$QL" check >/dev/null 2>&1; then + RC=75 OUTCOME="refused: quiet flag held by someone else" + write_manifest + echo "own30b-quiet-run: quiet flag already held; nothing run" >&2 + exit 75 +fi + +# quietlock runs in the background so a signal to this script reaches it at +# once. A non-interactive shell starts background jobs with SIGINT ignored, so +# every stop request is passed on as SIGTERM, which quietlock forwards to the +# held command's process group before it releases the flag. +SIG="" +"$QL" hold --owner "$OWNER" --minutes "$MINUTES" --reason "$REASON" -- "$@" & +QPID=$! +on_signal() { SIG=$1; kill -TERM "$QPID" 2>/dev/null; } +trap 'on_signal INT' INT +trap 'on_signal TERM' TERM +trap 'on_signal HUP' HUP +while :; do + wait "$QPID"; RC=$? + kill -0 "$QPID" 2>/dev/null || break +done +trap - INT TERM HUP + +POST=$(gpu_sample) +if [ "$(jq '.foreign | length' <<<"$POST")" -gt 0 ]; then + add_reason "postflight: foreign GPU compute process present: $(jq -r '[.foreign[] | "\(.pid) \(.name)"] | join(", ")' <<<"$POST")" +fi +if [ -n "$SIG" ]; then + OUTCOME="interrupted: SIG$SIG" + add_reason "interrupted by SIG$SIG" + case "$SIG" in INT) RC=130 ;; TERM) RC=143 ;; HUP) RC=129 ;; esac +elif [ "$RC" -eq 0 ]; then + OUTCOME="completed" +else + OUTCOME="exit $RC" +fi +write_manifest +echo "own30b-quiet-run: $OUTCOME; comparable=$(jq -r .comparable "$OUT/manifest.json"); manifest $OUT/manifest.json" >&2 +exit "$RC" diff --git a/tests/gates/run.sh b/tests/gates/run.sh index 64c97cb6..89c57f84 100755 --- a/tests/gates/run.sh +++ b/tests/gates/run.sh @@ -101,6 +101,7 @@ case "$step" in ;; aien-verify-tests) sh tools/aien-verify/tests/run.sh ;; pins-selftest) bash scripts/test-pins.sh ;; + own30b-quiet-run-selftest) bash scripts/bench/own30b-quiet-run-selftest.sh ;; native-identity) bash scripts/test-native-identity.sh ;; install-test) bash scripts/test-install.sh ;; scoring-v5) bash docs/campaigns/scoring/test-scoring-v5.sh ;; diff --git a/tests/gates/sc-own30b-quiet-run-selftest.gate b/tests/gates/sc-own30b-quiet-run-selftest.gate new file mode 100644 index 00000000..156df96b --- /dev/null +++ b/tests/gates/sc-own30b-quiet-run-selftest.gate @@ -0,0 +1,20 @@ +# tests/gates/sc-own30b-quiet-run-selftest.gate +# Self-test of the OWN-30B quiet-window runner (#625): fakes only, no GPU, no real quiet flag. +gate: SC-OWN30B-QUIET-RUN-SELFTEST +manifest_version: 2 +owner: aien-sovereign-core +requires: + - host +inputs: + - scripts/bench/own30b-quiet-run.sh + - scripts/bench/own30b-quiet-run-selftest.sh + - tests/gates/ +run: + exec: tests/gates/run.sh + args: ["own30b-quiet-run-selftest"] +expects: + exit: 0 + verdict: PASS +timeout: 5m +exactness: EXACT +cache_scope: machine