Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/scripts/test-gb10-model-dir.sh # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / scripts / test-gb10-model-dir.sh` 166 lines ยท 9383 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 # test-gb10-model-dir.sh (SC-GB10-MODEL-DIR): where SC-GB10-SERVE-CHAT finds its checkpoint, tested 18 # without a GPU (sc#760 review). Each case gives tests/gates/step-home.sh step_home (what run.sh runs) 19 # a read-only original HOME, then runs the real scripts/gb10-serve-chat.sh in the HOME and environment 20 # step_home leaves. Proves: (1) a read-only HOME with a models/ mount and a distinct writable per-step 21 # HOME resolves the checkpoint under the mount; (2) a missing mount, config.json or tokenizer.json is 22 # NOT_RUN model_missing (exit 77) before the memory check, the build and any GPU start; (3) an explicit 23 # MODEL_DIR is receipted as model_dir_source "override", also when the mount holds the default. 24 # Negative controls: the mount checks fail against the pre-#760 resolution ($HOME/models, the fresh 25 # HOME) and against a step_home that drops the models/ mount (the pre-#760 run.sh). 26 # 27 # Nothing here can build or start a server: the gate always gets a pins env.sh that does not exist 28 # (it fails on that right after the memory check), and a cargo stub first on PATH records any call, 29 # which fails the test. No GPU, no /tmp/aien-gb10.lock, no port is touched; /proc/meminfo is only read 30 # by the gate's own memory check, whose outcome no assertion depends on. 31 set -uo pipefail 32 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 33 T=$(mktemp -d); trap 'chmod -R u+w "$T" 2>/dev/null; rm -rf "$T"' EXIT 34 # run.sh exports AIEN_MODELS_DIR in the sandbox; every case sets its own environment. 35 unset MODEL_DIR AIEN_MODELS_DIR AIEN_GB10_LOCK_HELD MIRI_SYSROOT 36 M=qwen3.8-27b-fp8-`017b9c7a` 37 fail=0 bad=0 checks=0 38 chk() { checks=$((checks + 1)); if eval "$1"; then echo " ok $2"; else echo " FAIL $2"; bad=1; fi; } 39 ov() { sed -n "s/^AIEN-OBS $2 //p" "$1"; } # ov OUT NAME: the gate's observation NAME 40 41 mkdir -p "$T/stub" 42 printf '#!/bin/sh\n: > "%s/cargo-ran"\nexit 97\n' "$T" > "$T/stub/cargo"; chmod +x "$T/stub/cargo" 43 44 ckpt() { # ckpt DIR [no-config|no-tokenizer]: a checkpoint directory the gate accepts, or not 45 mkdir -p "$1" 46 [ "${2:-}" = no-config ] || echo '{}' > "$1/config.json" 47 [ "${2:-}" = no-tokenizer ] || echo '{}' > "$1/tokenizer.json" 48 } 49 rohome() { # rohome [none|no-config|no-tokenizer]: a new read-only original HOME with models/$M, prints it 50 local h; h=$(mktemp -d "$T/ro-home.XXXXXX") 51 [ "${1:-}" = none ] || ckpt "$h/models/$M" "${1:-}" 52 chmod -R a-w "$h"; echo "$h" 53 } 54 probe=$(rohome) 55 if [ -w "$probe" ]; then 56 echo "test-gb10-model-dir: NOT_RUN: a read-only directory is writable here (root?); step_home cannot be exercised" 57 exit 77 58 fi 59 60 step() { # step ROOTDIR HOMEDIR OUT [VAR=VALUE]...: step_home from ROOTDIR under HOME=HOMEDIR, then the gate 61 local root=$1 home=$2 out=$3; shift 3 62 rm -f "$T/cargo-ran"; rc=0 63 ( 64 export HOME="$home" 65 for kv in "$@"; do export "${kv?}"; done 66 # shellcheck source=tests/gates/step-home.sh 67 . "$root/tests/gates/step-home.sh" 68 step_home 69 printf '%s\n' "$HOME" > "$out.home" 70 if [ -w "$HOME" ]; then echo writable >> "$out.home"; fi 71 PATH="$T/stub:$PATH" bash "$root/scripts/gb10-serve-chat.sh" "$T/no-pins/env.sh" > "$out" 2> "$out.err" 72 ) || rc=$? 73 fresh=$(head -n 1 "$out.home") 74 } 75 # Nothing past the memory check ran: no cargo call, no build, chip-lock or server observation. 76 no_build() { 77 [ ! -e "$T/cargo-ran" ] && [ -z "$(ov "$1" build_rc)" ] && [ -z "$(ov "$1" chip_lock)" ] \ 78 && [ -z "$(ov "$1" serve_rc)" ] 79 } 80 81 case_mount() { # case_mount ROOTDIR: (1), returns 1 when any check fails 82 bad=0; local h out=$T/mount 83 h=$(rohome) 84 step "$1" "$h" "$out" 85 chk '[ "$fresh" != "$h" ] && grep -qx writable "$out.home"' "step_home swapped the read-only HOME for a distinct writable one" 86 chk '[ "$(ov "$out" model_dir)" = "\"$h/models/$M\"" ]' "model_dir is the read-only home's models/$M (got $(ov "$out" model_dir))" 87 chk '[ "$(ov "$out" model_dir_source)" = "\"models-mount\"" ]' "model_dir_source is models-mount" 88 chk '! grep -q model_missing "$out" "$out.err"' "no model_missing" 89 chk '[ -n "$(ov "$out" mem_available_mib)" ]' "the gate went on to its memory check" 90 chk '{ [ "$rc" -eq 77 ] && grep -q "NOT_RUN memory_short" "$out.err"; } || { [ "$rc" -eq 1 ] && grep -q "pins env file .* is missing" "$out.err"; }' \ 91 "it stopped at memory_short or the missing pins env.sh (rc $rc)" 92 chk 'no_build "$out"' "no cargo call, no build, no chip lock, no server start" 93 return "$bad" 94 } 95 96 case_missing() { # case_missing VARIANT WANT_SOURCE: (2) 97 bad=0; local h out=$T/missing-$1 want=$2 98 h=$(rohome "$1") 99 step "$ROOT" "$h" "$out" 100 chk '[ "$rc" -eq 77 ] && [ "$(ov "$out" not_run_reason)" = "\"model_missing\"" ] && grep -q "NOT_RUN model_missing" "$out.err"' \ 101 "$1: NOT_RUN model_missing, exit 77 (rc $rc)" 102 chk '[ "$(ov "$out" model_dir_source)" = "\"$want\"" ]' "$1: model_dir_source is $want" 103 chk '[ -z "$(ov "$out" mem_available_mib)" ] && no_build "$out"' "$1: before the memory check, the build and any server start" 104 return "$bad" 105 } 106 107 echo "test-gb10-model-dir: (1) read-only HOME with a models/ mount" 108 case_mount "$ROOT" || fail=1 109 110 echo "test-gb10-model-dir: (2) missing mount, config.json or tokenizer.json" 111 case_missing none home || fail=1 112 chk '[ "$(ov "$T/missing-none" model_dir)" = "\"$fresh/models/$M\"" ]' "none: without a mount the gate looks in the fresh HOME and says so" 113 [ "$bad" -eq 0 ] || fail=1 114 case_missing no-config models-mount || fail=1 115 case_missing no-tokenizer models-mount || fail=1 116 117 echo "test-gb10-model-dir: (3) an explicit MODEL_DIR stays visible in the receipt" 118 bad=0 119 h=$(rohome); ckpt "$T/override/$M" 120 step "$ROOT" "$h" "$T/ovr" "MODEL_DIR=$T/override/$M" 121 chk '[ "$(ov "$T/ovr" model_dir)" = "\"$T/override/$M\"" ] && [ "$(ov "$T/ovr" model_dir_source)" = "\"override\"" ]' \ 122 "override beside a populated mount: model_dir is the override, model_dir_source override" 123 chk '! grep -q model_missing "$T/ovr" "$T/ovr.err" && no_build "$T/ovr"' "override: accepted, still no build" 124 step "$ROOT" "$h" "$T/ovr-missing" "MODEL_DIR=$T/nowhere/$M" 125 chk '[ "$rc" -eq 77 ] && [ "$(ov "$T/ovr-missing" not_run_reason)" = "\"model_missing\"" ]' \ 126 "missing override: NOT_RUN model_missing, the mount's checkpoint is not substituted (rc $rc)" 127 chk '[ "$(ov "$T/ovr-missing" model_dir)" = "\"$T/nowhere/$M\"" ] && [ "$(ov "$T/ovr-missing" model_dir_source)" = "\"override\"" ]' \ 128 "missing override: receipt names the override" 129 wh="$T/writable-home"; ckpt "$wh/models/$M" 130 step "$ROOT" "$wh" "$T/wh" 131 chk '[ "$fresh" = "$wh" ] && [ "$(ov "$T/wh" model_dir)" = "\"$wh/models/$M\"" ] && [ "$(ov "$T/wh" model_dir_source)" = "\"home\"" ]' \ 132 "writable HOME (hosted, developer): kept, model_dir_source home" 133 [ "$bad" -eq 0 ] || fail=1 134 135 echo "test-gb10-model-dir: negative controls (each must make (1) fail)" 136 broken() { # broken NAME APPEND: a copy of the gate at $T/NAME whose step-home.sh ends with APPEND 137 local d="$T/$1" 138 mkdir -p "$d/scripts" "$d/tests/gates" \ 139 && cp "$ROOT/scripts/gb10-serve-chat.sh" "$d/scripts/" \ 140 && cp "$ROOT/tests/gates/step-home.sh" "$d/tests/gates/" \ 141 && printf '%s\n' "$2" >> "$d/tests/gates/step-home.sh" 142 } 143 # A control passes only when the copy was made, the copied gate ran and reported model_missing, and 144 # the reason (1) fails is the one under test: the checkpoint resolved outside the mount. Any other 145 # failure (a broken copy, a gate that never ran) fails the control. 146 control() { # control NAME APPEND LABEL 147 checks=$((checks + 1)) 148 if ! broken "$1" "$2"; then 149 echo " FAIL control $3: could not make the broken copy under $T/$1"; fail=1; return 150 fi 151 if (case_mount "$T/$1") > "$T/control.log" 2>&1; then 152 echo " FAIL control $3: the mount checks passed"; fail=1 153 elif grep -qE "FAIL model_dir is the read-only home's models/$M \(got \"/.+/models/$M\"\)" "$T/control.log" \ 154 && grep -q "FAIL no model_missing" "$T/control.log"; then 155 echo " ok control $3: the mount checks fail:"; grep FAIL "$T/control.log" | sed 's/^ */ /' 156 else 157 echo " FAIL control $3: (1) failed, but not because the checkpoint resolved outside the mount:" 158 sed 's/^ */ /' "$T/control.log"; fail=1 159 fi 160 } 161 # shellcheck disable=SC2016 162 control pre760 'gb10_model_dir() { MODEL_DIR=${MODEL_DIR:-$HOME/models/$GB10_MODEL}; MODEL_DIR_SOURCE=home; }' \ 163 "gate resolves \$HOME/models (pre-#760, the fresh HOME)" 164 control nomount 'step_home_models() { :; }' "step_home drops the models/ mount (pre-#760 run.sh)" 165 166 if [ "$fail" -eq 0 ]; then echo "test-gb10-model-dir: PASS ($checks checks)"; else echo "test-gb10-model-dir: FAIL"; exit 1; fi