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 / own30b-serve-smoke.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 | # OWN-30B cut 8 serve smoke: talks to a running aien-serve-http on the loopback and records |
| 18 | # each exchange with wall-clock timestamps (time-to-first-token and tok/s come from these). |
| 19 | # |
| 20 | # scripts/own30b-serve-smoke.sh <evidence-dir> <phase> [port] |
| 21 | # phase warm : /v1/models, one non-streaming, one streaming, then a 2-turn conversation |
| 22 | # with a ~1500-token system prompt (turn 2 should reuse turn 1's KV) |
| 23 | # phase cold : only turn 2 of that conversation (run against a freshly started server) |
| 24 | # Writes <dir>/<phase>-*.json|.sse|.time and refreshes <dir>/SHA256SUMS. |
| 25 | set -euo pipefail |
| 26 | dir=$1 phase=$2 port=${3:-18091} |
| 27 | base="http://127.0.0.1:$port/v1" |
| 28 | : "${AIEN_SERVE_HTTP_BEARER_TOKEN:?AIEN_SERVE_HTTP_BEARER_TOKEN required for chat}" |
| 29 | mkdir -p "$dir" |
| 30 | now() { date +%s.%N; } |
| 31 | |
| 32 | # A long, dull system prompt (about 1500 tokens): the same paragraph numbered many times. |
| 33 | sys_prompt() { |
| 34 | local i |
| 35 | echo "You are the OWN-30B assistant on the AIEN Spark. Answer in plain English, briefly. Rules of the house follow." |
| 36 | for i in $(seq 1 60); do |
| 37 | echo "Rule $i: keep answers short, never invent facts, say UNKNOWN when unsure, and prefer numbered steps over prose." |
| 38 | done |
| 39 | } |
| 40 | SYS=$(sys_prompt) |
| 41 | json_str() { jq -Rn --arg s "$1" '$s'; } |
| 42 | SYSJ=$(json_str "$SYS") |
| 43 | |
| 44 | post() { # name, body -> writes name.json and name.time |
| 45 | local name=$1 body=$2 t0 t1 |
| 46 | t0=$(now) |
| 47 | curl -s "$base/chat/completions" -H "Authorization: Bearer $AIEN_SERVE_HTTP_BEARER_TOKEN" -H 'content-type: application/json' -d "$body" -o "$dir/$name.json" |
| 48 | t1=$(now) |
| 49 | printf 'start %s\nend %s\nwall_s %s\n' "$t0" "$t1" "$(echo "$t1 - $t0" | bc -l)" > "$dir/$name.time" |
| 50 | jq -c '{finish: .choices[0].finish_reason, usage, text: .choices[0].message.content}' "$dir/$name.json" |
| 51 | } |
| 52 | |
| 53 | post_stream() { # name, body -> name.sse (timestamp per line), name.time |
| 54 | local name=$1 body=$2 t0 t1 |
| 55 | t0=$(now) |
| 56 | curl -sN "$base/chat/completions" -H "Authorization: Bearer $AIEN_SERVE_HTTP_BEARER_TOKEN" -H 'content-type: application/json' -d "$body" \ |
| 57 | | while IFS= read -r line; do printf '%s %s\n' "$(now)" "$line"; done > "$dir/$name.sse" |
| 58 | t1=$(now) |
| 59 | local first last n |
| 60 | first=$(grep -m1 '"content":"[^"]' "$dir/$name.sse" | cut -d' ' -f1 || true) |
| 61 | last=$(grep '"content":"[^"]' "$dir/$name.sse" | tail -1 | cut -d' ' -f1 || true) |
| 62 | n=$(grep -c '"content":"[^"]' "$dir/$name.sse" || true) |
| 63 | printf 'start %s\nfirst_token %s\nlast_token %s\nend %s\nttft_s %s\nchunks %s\ndecode_tok_s %s\n' \ |
| 64 | "$t0" "$first" "$last" "$t1" "$(echo "$first - $t0" | bc -l)" "$n" \ |
| 65 | "$(echo "($n - 1) / ($last - $first)" | bc -l)" > "$dir/$name.time" |
| 66 | cat "$dir/$name.time" |
| 67 | } |
| 68 | |
| 69 | if [ "$phase" = warm ]; then |
| 70 | curl -s "$base/models" > "$dir/models.json"; jq -c . "$dir/models.json" |
| 71 | post nonstream '{"model":"qwen3-30b-a3b-instruct-2507","temperature":0,"max_tokens":48,"messages":[{"role":"user","content":"In one sentence, what is a Grace Blackwell GB10?"}]}' |
| 72 | post_stream stream '{"model":"qwen3-30b-a3b-instruct-2507","temperature":0,"max_tokens":48,"stream":true,"messages":[{"role":"user","content":"Count from one to ten in words, comma separated."}]}' |
| 73 | post_stream sampled '{"model":"qwen3-30b-a3b-instruct-2507","temperature":0.7,"top_p":0.8,"seed":7,"max_tokens":32,"stream":true,"messages":[{"role":"user","content":"Name three colours."}]}' |
| 74 | fi |
| 75 | |
| 76 | # The 2-turn conversation. Turn 1 reply is read back from turn1.json (warm) or from the |
| 77 | # warm run's turn1.json (cold), so both phases send byte-identical turn 2 prompts. |
| 78 | U1="Give me three numbered steps for checking a bolt is torqued correctly." |
| 79 | U2="Now the same for a hose clamp, two steps only." |
| 80 | if [ "$phase" = warm ]; then |
| 81 | post_stream turn1 "{\"model\":\"qwen3-30b-a3b-instruct-2507\",\"temperature\":0,\"max_tokens\":96,\"stream\":true,\"messages\":[{\"role\":\"system\",\"content\":$SYSJ},{\"role\":\"user\",\"content\":$(json_str "$U1")}]}" |
| 82 | A1=$(grep '"content":"' "$dir/turn1.sse" | sed 's/^[0-9.]* data: //' | jq -j '.choices[0].delta.content // empty') |
| 83 | printf '%s' "$A1" > "$dir/turn1.reply.txt" |
| 84 | fi |
| 85 | A1=$(cat "$dir/turn1.reply.txt") |
| 86 | post_stream "$phase-turn2" "{\"model\":\"qwen3-30b-a3b-instruct-2507\",\"temperature\":0,\"max_tokens\":64,\"stream\":true,\"messages\":[{\"role\":\"system\",\"content\":$SYSJ},{\"role\":\"user\",\"content\":$(json_str "$U1")},{\"role\":\"assistant\",\"content\":$(json_str "$A1")},{\"role\":\"user\",\"content\":$(json_str "$U2")}]}" |
| 87 | grep '"content":"' "$dir/$phase-turn2.sse" | sed 's/^[0-9.]* data: //' | jq -j '.choices[0].delta.content // empty' > "$dir/$phase-turn2.reply.txt" |
| 88 | (cd "$dir" && find . -type f ! -name SHA256SUMS | sort | sed "s|^./||" | xargs sha256sum > SHA256SUMS) |
| 89 | echo "smoke $phase done" |