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
aien-sovereign-core-mv / scripts / test-serve-27b.sh
| 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 | # Tests tools/serve-27b.sh without loading a model: a stand-in server binary that refuses to load, |
| 18 | # exits 0 without serving, comes up, advertises the wrong model, or hangs in the GPU-lock queue, |
| 19 | # and a stand-in curl on PATH that answers /v1/models for it. Needs /dev/nvidia* (the script |
| 20 | # checks it) and touches no port, no model and no chip. Checks: an exited server exits 1 with its |
| 21 | # status and reason, ready (the API lists qwen3.8-27b-fp8) exits 0, a server that never lists the |
| 22 | # model exits 2 at READY_TIMEOUT and keeps running, --no-wait returns at once, an unrelated pid in |
| 23 | # the pid file is never signalled, --foreground stays attached, and the memory figure is 49,497 MiB. |
| 24 | set -uo pipefail |
| 25 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 26 | S=$ROOT/tools/serve-27b.sh |
| 27 | T=$(mktemp -d) |
| 28 | trap 'for p in "$T"/*.pid; do [ -f "$p" ] && kill "$(cat "$p")" 2>/dev/null; done; rm -rf "$T"' EXIT |
| 29 | fail() { echo "FAIL: $*" >&2; exit 1; } |
| 30 | compgen -G '/dev/nvidia*' >/dev/null || { echo "SKIP: no /dev/nvidia* device files"; exit 0; } |
| 31 | pass=0 |
| 32 | ok() { echo "ok: $*"; pass=$((pass + 1)); } |
| 33 | |
| 34 | mkdir "$T/model" "$T/path"; echo '{}' > "$T/model/config.json"; echo '{}' > "$T/model/tokenizer.json" |
| 35 | cat > "$T/fake" <<'EOS' |
| 36 | #!/usr/bin/env bash |
| 37 | if [ "${1:-}" = "--version" ]; then echo "omega gpu engine: native"; echo "qwen38 engine: native"; exit 0; fi |
| 38 | case "$FAKE" in |
| 39 | refuse) echo "aien-serve-http: qwen38 load failed: needs 41305 MiB plus 8192 MiB kept free (49497 MiB in all), MemAvailable 6144 MiB after taking the GPU lock; refusing" >&2; exit 1 ;; |
| 40 | early-zero) echo "aien-serve-http: fixture exits 0 before serving" >&2; exit 0 ;; |
| 41 | ready) echo "aien-serve-http: serving qwen3.8-27b-fp8 at http://127.0.0.1:1/v1 (engine omega)" >&2; touch "$FAKE_UP"; exec sleep 30 ;; |
| 42 | wrong) echo "aien-serve-http: serving fixture-wrong-model" >&2; touch "$FAKE_UP"; exec sleep 30 ;; |
| 43 | hang) echo "aien-serve-http: loading Qwen3.8 (qwen3_5) onto the Omega engine" >&2; exec sleep 30 ;; |
| 44 | esac |
| 45 | EOS |
| 46 | # The stand-in API: answers /v1/models only once the stand-in server says it is up. |
| 47 | cat > "$T/path/curl" <<'EOS' |
| 48 | #!/usr/bin/env bash |
| 49 | [ -e "$FAKE_UP" ] || exit 7 |
| 50 | case "$FAKE" in |
| 51 | ready) echo '{"object":"list","data":[{"id":"qwen3.8-27b-fp8","object":"model"}]}' ;; |
| 52 | *) echo '{"object":"list","data":[{"id":"fixture-wrong-model","object":"model"}]}' ;; |
| 53 | esac |
| 54 | EOS |
| 55 | chmod +x "$T/fake" "$T/path/curl" |
| 56 | run() { # name, extra args...; sets rc and out |
| 57 | local name=$1; shift |
| 58 | out=$(PATH=$T/path:$PATH FAKE=$name FAKE_UP=$T/$name.up BIN=$T/fake MODEL_DIR=$T/model PORT=1 \ |
| 59 | STATE_DIR=$T/$name LOG=$T/$name.log "$S" "$@" 2>&1); rc=$? |
| 60 | [ -f "$T/$name/serve-27b.pid" ] && cp "$T/$name/serve-27b.pid" "$T/$name.pid" |
| 61 | } |
| 62 | |
| 63 | run refuse |
| 64 | [ "$rc" -eq 1 ] || fail "refused load must exit 1, got $rc: $out" |
| 65 | grep -q 'MemAvailable 6144 MiB after taking the GPU lock' <<<"$out" || fail "refusal reason not printed: $out" |
| 66 | grep -q 'exited (status 1)' <<<"$out" || fail "server exit status not printed: $out" |
| 67 | grep -q 'did not start' <<<"$out" || fail "no plain 'did not start' line: $out" |
| 68 | grep -q 'started' <<<"$out" && fail "refused load still printed 'started': $out" |
| 69 | [ ! -e "$T/refuse/serve-27b.pid" ] || fail "pid file left behind after a refusal" |
| 70 | ok "refusal exits 1 with the server's status and reason" |
| 71 | |
| 72 | run early-zero |
| 73 | [ "$rc" -eq 1 ] || fail "a server that exits 0 without serving must exit 1, got $rc: $out" |
| 74 | grep -q 'exited (status 0)' <<<"$out" || fail "status 0 not printed: $out" |
| 75 | [ ! -e "$T/early-zero/serve-27b.pid" ] || fail "pid file left behind after an early exit 0" |
| 76 | ok "exit 0 without serving is a failure" |
| 77 | |
| 78 | run ready |
| 79 | [ "$rc" -eq 0 ] || fail "ready must exit 0, got $rc: $out" |
| 80 | grep -q 'serve-27b: ready, pid' <<<"$out" || fail "no ready line: $out" |
| 81 | pid=$(cat "$T/ready.pid") |
| 82 | kill -0 "$pid" 2>/dev/null || fail "ready server pid $pid is not alive" |
| 83 | [ "$(ps -o pgid= -p "$pid" | tr -d ' ')" = "$pid" ] || fail "ready server is not in its own session" |
| 84 | kill -TERM "$pid"; for _ in {1..50}; do kill -0 "$pid" 2>/dev/null || break; sleep 0.1; done |
| 85 | kill -0 "$pid" 2>/dev/null && fail "TERM on the recorded pid did not stop the server" |
| 86 | ok "ready (API lists qwen3.8-27b-fp8) exits 0; TERM on the recorded pid stops it" |
| 87 | |
| 88 | READY_TIMEOUT=3 run hang |
| 89 | [ "$rc" -eq 2 ] || fail "a hang past READY_TIMEOUT must exit 2, got $rc: $out" |
| 90 | grep -q 'not ready after 3 s' <<<"$out" || fail "timeout text missing: $out" |
| 91 | kill -0 "$(cat "$T/hang.pid")" 2>/dev/null || fail "timeout must leave the queued server running" |
| 92 | ok "hang exits 2 at the timeout and leaves the server running" |
| 93 | |
| 94 | READY_TIMEOUT=2 run wrong |
| 95 | [ "$rc" -eq 2 ] || fail "an API without qwen3.8-27b-fp8 must not count as ready, got $rc: $out" |
| 96 | grep -q 'does not list qwen3.8-27b-fp8' <<<"$out" || fail "timeout does not name the expected model: $out" |
| 97 | ok "an API advertising another model is not ready" |
| 98 | |
| 99 | kill "$(cat "$T/hang.pid")"; sleep 0.3 |
| 100 | run hang --no-wait |
| 101 | [ "$rc" -eq 0 ] || fail "--no-wait must exit 0, got $rc: $out" |
| 102 | grep -q 'started, not waited for' <<<"$out" || fail "--no-wait text missing: $out" |
| 103 | ok "--no-wait returns at once" |
| 104 | |
| 105 | mkdir -p "$T/owned" |
| 106 | sleep 20 & unrelated=$! |
| 107 | echo "$unrelated" > "$T/owned/serve-27b.pid" |
| 108 | out=$(PATH=$T/path:$PATH FAKE=refuse FAKE_UP=$T/owned.up BIN=$T/fake MODEL_DIR=$T/model PORT=1 \ |
| 109 | STATE_DIR=$T/owned LOG=$T/owned.log "$S" 2>&1); rc=$? |
| 110 | [ "$rc" -eq 1 ] || fail "a live pid in the pid file must refuse the start, got $rc: $out" |
| 111 | kill -0 "$unrelated" 2>/dev/null || fail "the script signalled the unrelated pid from the pid file" |
| 112 | kill "$unrelated"; wait "$unrelated" 2>/dev/null |
| 113 | ok "an unrelated live pid in the pid file is refused, not signalled" |
| 114 | |
| 115 | PATH=$T/path:$PATH FAKE=ready FAKE_UP=$T/fg.up BIN=$T/fake MODEL_DIR=$T/model PORT=1 \ |
| 116 | STATE_DIR=$T/fg LOG=$T/fg.log "$S" --foreground >/dev/null 2>&1 & |
| 117 | fg=$! |
| 118 | for _ in {1..50}; do [ -e "$T/fg.up" ] && break; sleep 0.1; done |
| 119 | kill -0 "$fg" 2>/dev/null || fail "--foreground did not stay attached" |
| 120 | [ ! -e "$T/fg/serve-27b.pid" ] || fail "--foreground wrote a pid file" |
| 121 | kill "$fg"; wait "$fg" 2>/dev/null |
| 122 | ok "--foreground stays attached and writes no pid file" |
| 123 | |
| 124 | READY_TIMEOUT=soon run refuse |
| 125 | [ "$rc" -eq 1 ] && grep -q 'READY_TIMEOUT must be a positive number' <<<"$out" || fail "a bad READY_TIMEOUT was accepted: $out" |
| 126 | ok "READY_TIMEOUT is checked" |
| 127 | |
| 128 | help=$("$S" --help) |
| 129 | head -n 1 <<<"$help" | grep -q '^# Start the Qwen3.8-27B model server' || fail "--help does not start at the usage text: $help" |
| 130 | tail -n 1 <<<"$help" | grep -q 'server keeps running' || fail "--help does not end at the exit codes: $help" |
| 131 | ok "--help prints the usage text" |
| 132 | |
| 133 | grep -q '^NEED_MIB=49497$' "$S" || fail "script memory figure is not 49497 MiB (41305 + 8192)" |
| 134 | grep -q 'KEEP_FREE: u64 = 8 << 30' "$ROOT/crates/aien-serve-http/src/qwen38_engine.rs" || fail "loader keep-free changed; update the docs and this test" |
| 135 | ok "memory figure" |
| 136 | echo "PASS ($pass checks)" |