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 / test-serve-27b.sh

136 lines · 7508 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# 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.
24set -uo pipefail
25ROOT=$(cd "$(dirname "$0")/.." && pwd)
26S=$ROOT/tools/serve-27b.sh
27T=$(mktemp -d)
28trap 'for p in "$T"/*.pid; do [ -f "$p" ] && kill "$(cat "$p")" 2>/dev/null; done; rm -rf "$T"' EXIT
29fail() { echo "FAIL: $*" >&2; exit 1; }
30compgen -G '/dev/nvidia*' >/dev/null || { echo "SKIP: no /dev/nvidia* device files"; exit 0; }
31pass=0
32ok() { echo "ok: $*"; pass=$((pass + 1)); }
33
34mkdir "$T/model" "$T/path"; echo '{}' > "$T/model/config.json"; echo '{}' > "$T/model/tokenizer.json"
35cat > "$T/fake" <<'EOS'
36#!/usr/bin/env bash
37if [ "${1:-}" = "--version" ]; then echo "omega gpu engine: native"; echo "qwen38 engine: native"; exit 0; fi
38case "$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 ;;
44esac
45EOS
46# The stand-in API: answers /v1/models only once the stand-in server says it is up.
47cat > "$T/path/curl" <<'EOS'
48#!/usr/bin/env bash
49[ -e "$FAKE_UP" ] || exit 7
50case "$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"}]}' ;;
53esac
54EOS
55chmod +x "$T/fake" "$T/path/curl"
56run() { # 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
63run refuse
64[ "$rc" -eq 1 ] || fail "refused load must exit 1, got $rc: $out"
65grep -q 'MemAvailable 6144 MiB after taking the GPU lock' <<<"$out" || fail "refusal reason not printed: $out"
66grep -q 'exited (status 1)' <<<"$out" || fail "server exit status not printed: $out"
67grep -q 'did not start' <<<"$out" || fail "no plain 'did not start' line: $out"
68grep -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"
70ok "refusal exits 1 with the server's status and reason"
71
72run early-zero
73[ "$rc" -eq 1 ] || fail "a server that exits 0 without serving must exit 1, got $rc: $out"
74grep -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"
76ok "exit 0 without serving is a failure"
77
78run ready
79[ "$rc" -eq 0 ] || fail "ready must exit 0, got $rc: $out"
80grep -q 'serve-27b: ready, pid' <<<"$out" || fail "no ready line: $out"
81pid=$(cat "$T/ready.pid")
82kill -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"
84kill -TERM "$pid"; for _ in {1..50}; do kill -0 "$pid" 2>/dev/null || break; sleep 0.1; done
85kill -0 "$pid" 2>/dev/null && fail "TERM on the recorded pid did not stop the server"
86ok "ready (API lists qwen3.8-27b-fp8) exits 0; TERM on the recorded pid stops it"
87
88READY_TIMEOUT=3 run hang
89[ "$rc" -eq 2 ] || fail "a hang past READY_TIMEOUT must exit 2, got $rc: $out"
90grep -q 'not ready after 3 s' <<<"$out" || fail "timeout text missing: $out"
91kill -0 "$(cat "$T/hang.pid")" 2>/dev/null || fail "timeout must leave the queued server running"
92ok "hang exits 2 at the timeout and leaves the server running"
93
94READY_TIMEOUT=2 run wrong
95[ "$rc" -eq 2 ] || fail "an API without qwen3.8-27b-fp8 must not count as ready, got $rc: $out"
96grep -q 'does not list qwen3.8-27b-fp8' <<<"$out" || fail "timeout does not name the expected model: $out"
97ok "an API advertising another model is not ready"
98
99kill "$(cat "$T/hang.pid")"; sleep 0.3
100run hang --no-wait
101[ "$rc" -eq 0 ] || fail "--no-wait must exit 0, got $rc: $out"
102grep -q 'started, not waited for' <<<"$out" || fail "--no-wait text missing: $out"
103ok "--no-wait returns at once"
104
105mkdir -p "$T/owned"
106sleep 20 & unrelated=$!
107echo "$unrelated" > "$T/owned/serve-27b.pid"
108out=$(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"
111kill -0 "$unrelated" 2>/dev/null || fail "the script signalled the unrelated pid from the pid file"
112kill "$unrelated"; wait "$unrelated" 2>/dev/null
113ok "an unrelated live pid in the pid file is refused, not signalled"
114
115PATH=$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 &
117fg=$!
118for _ in {1..50}; do [ -e "$T/fg.up" ] && break; sleep 0.1; done
119kill -0 "$fg" 2>/dev/null || fail "--foreground did not stay attached"
120[ ! -e "$T/fg/serve-27b.pid" ] || fail "--foreground wrote a pid file"
121kill "$fg"; wait "$fg" 2>/dev/null
122ok "--foreground stays attached and writes no pid file"
123
124READY_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"
126ok "READY_TIMEOUT is checked"
127
128help=$("$S" --help)
129head -n 1 <<<"$help" | grep -q '^# Start the Qwen3.8-27B model server' || fail "--help does not start at the usage text: $help"
130tail -n 1 <<<"$help" | grep -q 'server keeps running' || fail "--help does not end at the exit codes: $help"
131ok "--help prints the usage text"
132
133grep -q '^NEED_MIB=49497$' "$S" || fail "script memory figure is not 49497 MiB (41305 + 8192)"
134grep -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"
135ok "memory figure"
136echo "PASS ($pass checks)"