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 / tools / qwen38_receipt.sh

131 lines · 7407 bytes Raw Blame History
1# SPDX-License-Identifier: Apache-2.0
2# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# qwen38_receipt.sh: helpers shared by tools/qwen38_serve_gate.sh and tools/qwen38_serve_speed.sh.
17# Sourced, not run. Collects what a run needs to be checked later: which server binary answered
18# (sha256 and its --version build line), which model folder, the machine state, and one JSON
19# receipt per run. Needs curl, jq, sha256sum and awk.
20#
21# Which server: the process listening on the URL's port (found with ss, works for your own
22# processes), or set SERVER_BIN and MODEL_DIR explicitly. Anything that cannot be found is
23# written as "unknown", never guessed.
24#
25# AIEN_CHECK_MODEL=1 also runs sha256sum -c of the shipped model checksum list in the model
26# folder (reads about 31 GB, several minutes).
27
28Q38_REPO=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
29Q38_MODEL_SUMS="$Q38_REPO/docs/qwen38/qwen3.8-27b-fp8-017b9c7a.sha256"
30# Weight bytes read per generated token and the 273 GB/s nominal memory rate: docs/qwen38/CEILING.md.
31# shellcheck disable=SC2034 # read by qwen38_serve_speed.sh
32Q38_CEILING_TOK_S=10.15
33
34# q38_server_facts <base-url>: sets Q38_PID, Q38_BIN, Q38_BIN_SHA256, Q38_BUILD, Q38_MODEL_DIR.
35q38_server_facts() {
36 local url=$1 port pid="" cmd
37 port=$(sed -E 's#^[a-z]+://[^:/]+:?([0-9]*).*#\1#' <<<"$url"); port=${port:-80}
38 if command -v ss >/dev/null; then
39 pid=$(ss -ltnpH "sport = :$port" 2>/dev/null | grep -o 'pid=[0-9]*' | head -1 | cut -d= -f2 || true)
40 fi
41 Q38_PID=${pid:-unknown}
42 Q38_BIN=${SERVER_BIN:-}
43 if [ -z "$Q38_BIN" ] && [ -n "$pid" ] && [ -r "/proc/$pid/exe" ]; then Q38_BIN=/proc/$pid/exe; fi
44 if [ -n "$Q38_BIN" ] && [ -r "$Q38_BIN" ]; then
45 Q38_BIN_SHA256=$(sha256sum "$Q38_BIN" | cut -d' ' -f1)
46 # --version loads nothing (aien-serve-http builds from alpha/serve-path on). Older builds
47 # refuse the flag and exit, so their build line is unknown.
48 Q38_BUILD=$(timeout 20 "$Q38_BIN" --version 2>/dev/null | grep '^sovereign-core commit:' | sed 's/^sovereign-core commit: //' || true)
49 Q38_BUILD=${Q38_BUILD:-unknown (binary has no --version)}
50 else
51 Q38_BIN_SHA256=unknown; Q38_BUILD=unknown
52 fi
53 Q38_MODEL_DIR=${MODEL_DIR:-}
54 if [ -z "$Q38_MODEL_DIR" ] && [ -n "$pid" ] && [ -r "/proc/$pid/cmdline" ]; then
55 cmd=$(tr '\0' '\n' < "/proc/$pid/cmdline")
56 Q38_MODEL_DIR=$(awk 'p {print; exit} $0 == "--model-dir" {p = 1}' <<<"$cmd")
57 fi
58 Q38_MODEL_DIR=${Q38_MODEL_DIR:-unknown}
59}
60
61# q38_machine_json: driver, kernel, load average and free memory now, as one JSON object.
62q38_machine_json() {
63 local drv="" load mem
64 [ -r /proc/driver/nvidia/version ] && drv=$(grep -o '[0-9]\{3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /proc/driver/nvidia/version | head -1 || true)
65 load=$(cut -d' ' -f1-3 /proc/loadavg 2>/dev/null || echo unknown)
66 mem=$(awk '/^MemAvailable:/ {print $2}' /proc/meminfo 2>/dev/null || echo 0)
67 jq -n --arg drv "${drv:-unknown}" --arg kernel "$(uname -r)" --arg arch "$(uname -m)" \
68 --arg load "$load" --argjson mem "${mem:-0}" --arg at "$(date -u +%FT%TZ)" \
69 '{at:$at, nvidia_driver:$drv, kernel:$kernel, arch:$arch, loadavg_1_5_15:$load, mem_available_kib:$mem}'
70}
71
72# q38_model_check_json: the shipped checksum list, its sha256, and (AIEN_CHECK_MODEL=1) the result.
73q38_model_check_json() {
74 local result="not run (set AIEN_CHECK_MODEL=1; reads about 31 GB)" list_sha=missing
75 [ -f "$Q38_MODEL_SUMS" ] && list_sha=$(sha256sum "$Q38_MODEL_SUMS" | cut -d' ' -f1)
76 if [ "${AIEN_CHECK_MODEL:-0}" = 1 ]; then
77 if [ -d "$Q38_MODEL_DIR" ] && [ -f "$Q38_MODEL_SUMS" ]; then
78 if (cd "$Q38_MODEL_DIR" && sha256sum --quiet -c "$Q38_MODEL_SUMS" >/dev/null 2>&1); then result=MATCH; else result=MISMATCH; fi
79 else
80 result="not run (model folder or list missing)"
81 fi
82 fi
83 jq -n --arg list "docs/qwen38/qwen3.8-27b-fp8-017b9c7a.sha256" --arg sha "$list_sha" --arg r "$result" \
84 '{sha256_list:$list, sha256_list_sha256:$sha, check:$r}'
85}
86
87# q38_log_line <server-log> <reply-id>: the server's own qwen38 log line for one reply ("" if absent).
88q38_log_line() {
89 [ -f "$1" ] || return 0
90 grep -B1 "$2:" "$1" 2>/dev/null | grep 'qwen38:' | head -1 | sed 's/aien-serve-http: qwen38: //' || true
91}
92
93# q38_run_json <name> <reply.json> <client-wall-s> <server-log>: one request's figures as JSON.
94q38_run_json() {
95 local name=$1 f=$2 wall=$3 log=$4 id line ids chip swall lock
96 id=$(jq -r '.id // ""' "$f" 2>/dev/null)
97 line=$(q38_log_line "$log" "$id")
98 ids=$(jq -c '.usage.aien_token_ids // null' "$f" 2>/dev/null || echo null)
99 chip=$(grep -o 'graph chip [0-9.]* ms/token' <<<"$line" | grep -o '[0-9.]*' | head -1 || true)
100 swall=$(grep -o 'wall [0-9.]* ms/token' <<<"$line" | grep -o '[0-9.]*' | head -1 || true)
101 lock=$(grep -o 'lock wait [0-9]* ms' <<<"$line" | grep -o '[0-9]*' | head -1 || true)
102 jq -n --arg name "$name" --arg id "$id" --arg wall "${wall:-}" --arg line "$line" \
103 --arg chip "${chip:-}" --arg swall "${swall:-}" --arg lock "${lock:-}" \
104 --arg ids_sha "$(printf '%s\n' "$ids" | sha256sum | cut -c1-12)" \
105 --argjson pt "$(jq '.usage.prompt_tokens // null' "$f" 2>/dev/null || echo null)" \
106 --argjson ct "$(jq '.usage.completion_tokens // null' "$f" 2>/dev/null || echo null)" \
107 '{name:$name, reply_id:$id, prompt_tokens:$pt, completion_tokens:$ct,
108 client_wall_s:($wall|tonumber? // null),
109 client_ms_per_token:(if ($ct // 0) > 0 and ($wall|tonumber? // null) != null then (($wall|tonumber) * 1000 / $ct) else null end),
110 chip_ms_per_token:($chip|tonumber? // null), server_wall_ms_per_token:($swall|tonumber? // null),
111 lock_wait_ms:($lock|tonumber? // null), ids_sha256_12:$ids_sha, server_log_line:$line}'
112}
113
114# q38_write_receipt <out-file> <kind> <url> <runs.jsonl> <extra-json>: the run's receipt.
115q38_write_receipt() {
116 local out=$1 kind=$2 url=$3 runs=$4 extra=$5
117 jq -n --arg schema "aien-qwen38-serve-receipt/1" --arg kind "$kind" --arg url "$url" \
118 --arg tools_commit "$(git -C "$Q38_REPO" rev-parse HEAD 2>/dev/null || echo unknown)" \
119 --arg tools_dirty "$([ -n "$(git -C "$Q38_REPO" status --porcelain --untracked-files=no 2>/dev/null)" ] && echo yes || echo no)" \
120 --arg pid "$Q38_PID" --arg bin "${Q38_BIN:-unknown}" --arg bin_sha "$Q38_BIN_SHA256" --arg build "$Q38_BUILD" \
121 --arg model "$Q38_MODEL_DIR" \
122 --argjson machine_start "$Q38_MACHINE_START" --argjson machine_end "$(q38_machine_json)" \
123 --argjson model_check "$(q38_model_check_json)" \
124 --slurpfile runs "$runs" --argjson extra "$extra" \
125 '{schema:$schema, kind:$kind, server_url:$url,
126 tools:{repo_commit:$tools_commit, uncommitted_changes:$tools_dirty},
127 server:{pid:$pid, binary:$bin, binary_sha256:$bin_sha, build:$build},
128 model:({dir:$model} + $model_check),
129 machine:{start:$machine_start, end:$machine_end},
130 runs:$runs} + $extra' > "$out"
131}