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 / q36-batch-20261021 / gate-batch.sh
| 1 | #!/bin/bash |
| 2 | # L354 gate: many conversations at once through the 35B batch door must give each request exactly the |
| 3 | # greedy token ids it gets alone. |
| 4 | # gate-batch.sh <alone_port> <batch_port|-> <label> [stagger_ms] (batch_port - = only collect $AL/) |
| 5 | # alone: every prompt of prompts.txt, one at a time, to <alone_port> (the live single door 18091 = the gated served |
| 6 | # path), kept in $AL/ and reused when complete. together: all prompts to <batch_port> at once, request i |
| 7 | # started (i % 8) * stagger_ms later (rows join and leave mid-spell), max_tokens 8..48 (prompt 0: 24, its host |
| 8 | # golden gen-chat-max-24). turn2: a second turn on prompt 5's conversation (the batch door continues its row). |
| 9 | # PASS = every together reply's ids == alone, turn2 == alone, prompt 0 alone == golden. Exit 0 PASS, 1 FAIL, 2 no verdict. |
| 10 | # Never run this under flock: the servers take /tmp/aien-gb10.lock themselves. |
| 11 | set -u |
| 12 | AL=${ALONE:-alone} # the alone replies folder (ALONE=dir keeps several references) |
| 13 | A=${1:?alone port}; B=${2:?batch port}; L=${3:?label}; ST=${4:-250} |
| 14 | D=$(cd "$(dirname "$0")" && pwd); cd "$D" |
| 15 | G=$D/../q36-host-20261020/gen-chat-max-24.json |
| 16 | mapfile -t P < prompts.txt |
| 17 | N=${#P[@]} |
| 18 | model() { curl -s -m 10 http://127.0.0.1:$1/v1/models | jq -r '.data[0].id // empty'; } |
| 19 | body() { # <model> <max_tokens> <messages json> |
| 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 | ask() { # <port> <model> <max_tokens> <messages json> <out> |
| 22 | local t0=$(date +%s.%N) b; b=$(body "$2" "$3" "$4"); local busy=0 |
| 23 | # A real client's retry on 503 server_busy (every slot taken): wait half a second, ask again. |
| 24 | while curl -s -m 900 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, busy_retries:($busy|tonumber)}' --arg busy $busy "$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 --arg c "$1" '[{role:"user", content:$c}]'; } |
| 28 | MB=$( [ "$B" = - ] && echo - || model $B) |
| 29 | # The alone replies are kept ($AL/done): then 18091 need not serve (it may be stopped for tests). |
| 30 | if [ -f $AL/done ] && [ "$B" != - ]; then MA=$MB; else MA=$(model $A); fi |
| 31 | [ -n "$MA" ] && [ -n "$MB" ] || { echo "gate-batch $L: no answer from port $A or $B -> ERROR (not a verdict)"; exit 2; } |
| 32 | mkdir -p "$AL" "$L" |
| 33 | if [ ! -f $AL/done ]; then |
| 34 | for ((i=0; i<N; i++)); do ask $A "$MA" $(ntok $i) "$(user "${P[$i]}")" $AL/$i.json; done |
| 35 | T5=$(jq -r .text $AL/5.json) |
| 36 | M2=$(jq -cn --arg a "${P[5]}" --arg r "$T5" '[{role:"user",content:$a},{role:"assistant",content:$r},{role:"user",content:"Now say it again in one short sentence."}]') |
| 37 | echo "$M2" > $AL/turn2.messages.json |
| 38 | ask $A "$MA" 16 "$M2" $AL/turn2.json |
| 39 | date -u +%FT%TZ > $AL/done |
| 40 | fi |
| 41 | [ "$B" = - ] && { echo "gate-batch: alone replies kept in $AL/"; exit 0; } |
| 42 | T0=$(date +%s.%N) |
| 43 | for ((i=0; i<N; i++)); do |
| 44 | ( sleep $(echo "scale=3; ($i % 8) * $ST / 1000" | bc); ask $B "$MB" $(ntok $i) "$(user "${P[$i]}")" "$L/$i.json" ) & |
| 45 | done |
| 46 | wait |
| 47 | T1=$(date +%s.%N) |
| 48 | ask $B "$MB" 16 "$(cat $AL/turn2.messages.json)" "$L/turn2.json" |
| 49 | same=0; diff=0; bad="" |
| 50 | for ((i=0; i<N; i++)); do |
| 51 | if [ "$(jq -c .ids $AL/$i.json)" != null ] && [ "$(jq -c .ids $AL/$i.json)" = "$(jq -c .ids $L/$i.json)" ]; then same=$((same+1)); else diff=$((diff+1)); bad="$bad $i"; fi |
| 52 | done |
| 53 | t2=$( [ "$(jq -c .ids $AL/turn2.json)" != null ] && [ "$(jq -c .ids $AL/turn2.json)" = "$(jq -c .ids $L/turn2.json)" ] && echo true || echo false) |
| 54 | gold=$( [ "$(jq -c .ids $AL/0.json)" = "$(jq -c .generated_ids $G)" ] && echo true || echo false) |
| 55 | toks=$(cat $L/[0-9]*.json | jq -s '[.[].ids | length] | add') |
| 56 | V=FAIL; [ $diff = 0 ] && [ $t2 = true ] && [ $gold = true ] && V=PASS |
| 57 | jq -n --arg at "$(date -u +%FT%TZ)" --arg l "$L" --arg a "$A" --arg b "$B" --argjson n $N --argjson same $same --argjson diff $diff --arg bad "$bad" \ |
| 58 | --argjson t2 $t2 --argjson gold $gold --argjson toks "${toks:-0}" --arg wall "$(echo "$T1 - $T0" | bc)" --arg st $ST --arg v $V \ |
| 59 | '{at:$at, label:$l, alone_port:$a, batch_port:$b, prompts:$n, identical:$same, differ:$diff, differ_idx:$bad, turn2_identical:$t2, prompt0_alone_eq_golden:$gold, together_tokens:$toks, together_wall_s:$wall, stagger_ms:$st, verdict:$v}' > "$L/verdict.json" |
| 60 | echo "gate-batch $L: $same/$N identical, differ [$bad ], turn2 $t2, golden $gold, $toks tokens in $(echo "$T1 - $T0" | bc) s -> $V" |
| 61 | [ $V = PASS ] |