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 / evidence / merge-train / l369 / long-prompts.sh
| 1 | #!/bin/bash |
| 2 | # L369 on the merge train (L387): long prompts through the batch door. The chip prefill reads a prompt in chunks of 128; |
| 3 | # the words must be the reference build's (prompts token by token), request by request. |
| 4 | # long-prompts.sh ref <port> <dir> reference: each request ALONE, one at a time, against the reference build |
| 5 | # long-prompts.sh run <port> <out> the train case: the 3 long prompts (~256/~2k/~8k), one SAMPLED request on the ~2k |
| 6 | # prompt (temperature 0.8, top_p 0.95, seed 7) and the suite's 32 short prompts all |
| 7 | # at once (short rows join while the long ones are read), then turn 2 on the ~2k |
| 8 | # conversation; PASS = every reply's ids == the reference (long, sampled, turn 2) |
| 9 | # and == the store's alone replies (short). Exit 0 PASS, 1 FAIL, 2 no verdict. |
| 10 | # Reference: $REFS_DIR (default the train's CURRENT reference)/l369-long. Adapted from L369's targets/l369/door/door-gate.sh. |
| 11 | set -u |
| 12 | D=$(cd "$(dirname "$0")" && pwd); MT=$(cd "$D/.." && pwd); REPO=$(cd "$MT/../.." && pwd) |
| 13 | MODEL_NAME=$(jq -r .model_dir "$MT/suite.json") |
| 14 | REFS_DIR=${REFS_DIR:-$HOME/.local/state/aien-q36/merge-train/refs/$MODEL_NAME/CURRENT} |
| 15 | mapfile -t S < "$REPO/$(jq -r .prompts "$MT/suite.json")" |
| 16 | body() { # <model> <max_tokens> <messages json> [sampled] |
| 17 | if [ "${4:-}" = sampled ]; then |
| 18 | jq -cn --arg m "$1" --argjson n "$2" --argjson msg "$3" '{model:$m, messages:$msg, temperature:0.8, top_p:0.95, seed:7, max_tokens:$n, chat_template_kwargs:{enable_thinking:false}, aien_return_token_ids:true}' |
| 19 | else |
| 20 | jq -cn --arg m "$1" --argjson n "$2" --argjson msg "$3" '{model:$m, messages:$msg, temperature:0, max_tokens:$n, chat_template_kwargs:{enable_thinking:false}, aien_return_token_ids:true}' |
| 21 | fi; } |
| 22 | ask() { # <port> <model> <max_tokens> <messages json> <out> [sampled] |
| 23 | local t0 b busy=0; t0=$(date +%s.%N); b=$(body "$2" "$3" "$4" "${6:-}") |
| 24 | while curl -s -m 1800 "http://127.0.0.1:$1/v1/chat/completions" -H 'Content-Type: application/json' -d "$b" > "$5.raw"; grep -q '"server_busy"' "$5.raw" && [ $busy -lt 2400 ]; do busy=$((busy+1)); sleep 0.5; done |
| 25 | jq --arg t0 "$t0" --arg t1 "$(date +%s.%N)" '{ids:.usage.aien_token_ids, text:.choices[0].message.content, finish:.choices[0].finish_reason, prompt_tokens:.usage.prompt_tokens, t0:$t0, t1:$t1}' "$5.raw" > "$5" 2>/dev/null || echo '{"ids":null}' > "$5"; } |
| 26 | ntok() { if [ "$1" = 0 ]; then echo 24; else echo $(( 8 + ($1 * 7) % 41 )); fi; } |
| 27 | user() { jq -cn --rawfile c "$1" '[{role:"user", content:$c}]'; } |
| 28 | userline() { jq -cn --arg c "$1" '[{role:"user", content:$c}]'; } |
| 29 | turn2() { # <port> <model> <dir> |
| 30 | local r; r=$(jq -r .text "$3/long-2048.json") |
| 31 | jq -cn --rawfile a "$D/long-2048.txt" --arg r "$r" '[{role:"user",content:$a},{role:"assistant",content:$r},{role:"user",content:"Now say it again in five words."}]' > "$3/turn2.messages" |
| 32 | ask "$1" "$2" 16 "$(cat "$3/turn2.messages")" "$3/turn2.json"; } |
| 33 | model() { curl -s -m 10 "http://127.0.0.1:$1/v1/models" | jq -r '.data[0].id // empty'; } |
| 34 | case ${1:?ref|run} in |
| 35 | ref) |
| 36 | P=${2:?port}; O=${3:?dir}; mkdir -p "$O"; M=$(model "$P"); [ -n "$M" ] || { echo "long-prompts: no answer from $P"; exit 2; } |
| 37 | for n in 256 2048 8192; do ask "$P" "$M" 24 "$(user "$D/long-$n.txt")" "$O/long-$n.json"; done |
| 38 | ask "$P" "$M" 24 "$(user "$D/long-2048.txt")" "$O/sampled-2048.json" sampled |
| 39 | turn2 "$P" "$M" "$O" |
| 40 | for f in "$O"/*.json; do [ "$(jq -c .ids "$f")" != null ] || { echo "long-prompts ref: $f has no ids"; exit 2; }; done |
| 41 | echo "$(date -u +%FT%TZ) port $P model $M $(curl -s -m 10 "http://127.0.0.1:$P/health" | jq -c '{build:(.build // .version // null)}') ${REF_NOTE:-}" > "$O/done" |
| 42 | echo "long-prompts ref $O: $(for n in 256 2048 8192; do jq -r .prompt_tokens "$O/long-$n.json"; done | tr '\n' ' ')prompt tokens" |
| 43 | ;; |
| 44 | run) |
| 45 | P=${2:?port}; O=${3:?out}/l369-long; R=$REFS_DIR/l369-long; A=$REFS_DIR/alone; mkdir -p "$O" |
| 46 | [ -s "$R/done" ] || { echo "long-prompts: no reference at $R"; exit 2; } |
| 47 | M=$(model "$P"); [ -n "$M" ] || { echo "long-prompts: no answer from $P"; exit 2; } |
| 48 | for n in 8192 2048 256; do ask "$P" "$M" 24 "$(user "$D/long-$n.txt")" "$O/long-$n.json" & sleep 0.3; done |
| 49 | ask "$P" "$M" 24 "$(user "$D/long-2048.txt")" "$O/sampled-2048.json" sampled & |
| 50 | for ((i=0; i<${#S[@]}; i++)); do ( sleep "$(echo "scale=3; ($i % 8) * 0.25" | bc)"; ask "$P" "$M" "$(ntok $i)" "$(userline "${S[$i]}")" "$O/short-$i.json" ) & done |
| 51 | wait |
| 52 | turn2 "$P" "$M" "$O" |
| 53 | same=0; bad="" |
| 54 | for f in "$R"/*.json; do n=$(basename "$f"); a=$(jq -c .ids "$f"); b=$(jq -c .ids "$O/$n" 2>/dev/null) |
| 55 | if [ "$a" != null ] && [ "$a" = "$b" ]; then same=$((same+1)); else bad="$bad $n"; fi; done |
| 56 | for ((i=0; i<${#S[@]}; i++)); do a=$(jq -c .ids "$A/$i.json" 2>/dev/null); b=$(jq -c .ids "$O/short-$i.json" 2>/dev/null) |
| 57 | if [ -n "$a" ] && [ "$a" != null ] && [ "$a" = "$b" ]; then same=$((same+1)); else bad="$bad short-$i"; fi; done |
| 58 | nulls=$(cat "$O"/*.json | jq -s '[.[] | select(.ids == null)] | length') |
| 59 | V=FAIL; [ -z "$bad" ] && [ "$same" -gt 0 ] && V=PASS |
| 60 | echo "long-prompts run: $same identical, differ [$bad ], no-ids $nulls; prompt tokens $(for n in 256 2048 8192; do jq -r .prompt_tokens "$O/long-$n.json"; done | tr '\n' ' ')-> $V" |
| 61 | [ $V = PASS ] && exit 0; [ "$nulls" -gt 0 ] && exit 2; exit 1 |
| 62 | ;; |
| 63 | esac |