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 / docs / campaigns / open-model-qwen3 / run-qwen3-v8.sh

207 lines · 16482 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# OPEN-MODEL-QWEN3 v8 qualification (SPEC-v8.md). As run-qwen3-v7.sh with names changed and the R1 CPU reference run with NP1_REFERENCE_ALLEN=default (SPEC-v8 Section 2). v7 derived from run-qwen3-v5.sh with names only changed: the frozen
18# values file (frozen-v8.json), the pinned run base (oq3-v8-runs), the output tag (oq3-v8) and labels. Tasks (tasks-oq3-v5.json),
19# seeds (seed-v5), declaration (oq3-v5.decl.json), row modules, v5-rows.sh, driver, receipt builder and scorer are the v5 files,
20# byte-identical. It refuses a real run while any pin in frozen-v8.json holds the placeholder or its status does not say FROZEN,
21# and afterwards unless every pin read from the checkouts and binaries equals it. The v5 header follows unchanged:
22# OPEN-MODEL-QWEN3 v5 campaign (ACCEPTANCE-v5.md). It refuses a real run while any pin
23# in frozen-v5.json holds the placeholder or its status does not say FROZEN, and afterwards unless every pin read
24# from the checkouts and binaries equals it. Qwen3-4B, derived from run-qwen3-v4.sh: same driver (next-phase-1/run-campaign.sh), receipt builder, v8 rows and
25# scorer; new tasks (tasks-oq3-v5.json), one declaration (qualification) and extra rows (v5-rows.sh, rows-oq3-v5.jq).
26# Shell + jq only. Run inside the caller's hold, one part per hold. Environment as in ACCEPTANCE-v5 Section 7
27# (model, tokenizer, binary, KV context, hardware requirement, checkpoint requirement, declared attempt flag), then:
28# OQ3_PART=1|2|3|4 run-qwen3-v5.sh RUN_BASE OUT_DIR SC_DIR OMEGA_DIR REFERENCE_BIN MERGE_BIN
29# SC_DIR is the sovereign-core checkout the binaries were built from, OMEGA_DIR the omega checkout at its omega.lock;
30# the commits and lock files are read from them (row <id>-PIN). Parts (ACCEPTANCE-v5 Section 8): 1 = D1 D2 D3,
31# 2 = D4 D5 D6, 3 = E1 E2 N1, 4 = N2 R1 and the QUALIFICATION score. Part k needs part k-1 completed in the same
32# RUN_BASE with the same binaries, tasks file, declaration, frozen values, row modules and wrapper.
33# Dry run (gate G6): OQ3_DRY_TASKS=<tasks file with the same ids, kinds, max_tokens, budgets, destinations and seeds>
34# lifts the pinned paths and the frozen-pin checks and writes oq3-v5-DRYRUN-* outputs. A dry run is never a verdict.
35# A dry run still starts the real driver and daemon on the GPU.
36set -u
37PART=${OQ3_PART:-}
38case $PART in 1) LAUNCHES="D1 D2 D3" ;; 2) LAUNCHES="D4 D5 D6" ;; 3) LAUNCHES="E1 E2 N1" ;; 4) LAUNCHES="N2 R1" ;; *) echo "run-qwen3-v8: OQ3_PART must be 1, 2, 3 or 4" >&2; exit 2 ;; esac
39HERE=$(cd "$(dirname "$0")" && pwd)
40NP1=$(cd "$HERE/../next-phase-1" && pwd)
41FROZEN=${OQ3_FROZEN:-$HERE/frozen-v8.json} # D1: only a dry run may point elsewhere (checked below)
42BASE=${1:?RUN_BASE} OUT=${2:?OUT_DIR} SCD=${3:?SC_DIR} OMD=${4:?OMEGA_DIR} REFBIN=${5:?REFERENCE_BIN} MERGEBIN=${6:?MERGE_BIN}
43[ -z "${OQ3_FROZEN:-}" ] || [ -n "${OQ3_DRY_TASKS:-}" ] || { echo "run-qwen3-v8: OQ3_FROZEN is allowed in a dry run only" >&2; exit 2; }
44PLACEHOLDER=$(jq -r .placeholder "$FROZEN")
45
46TASKS=$HERE/tasks-oq3-v5.json TAG=oq3-v8
47if [ -n "${OQ3_DRY_TASKS:-}" ]; then
48 TASKS=$OQ3_DRY_TASKS TAG=oq3-v8-DRYRUN
49 shape='[.tasks[] | [.id, .kind, .max_tokens, .budget_ms, .destination, .seed]]'
50 [ "$(jq -c "$shape" "$TASKS")" = "$(jq -c "$shape" "$HERE/tasks-oq3-v5.json")" ] ||
51 { echo "run-qwen3-v8: dry-run tasks must keep the v5 ids, kinds, max_tokens, budgets, destinations and seeds" >&2; exit 2; }
52else
53 # Real run: the run path is pinned (the prompt embeds the workspace path), the output directory is fresh,
54 # and every frozen pin must be filled in (the comparison with the recorded pins follows below).
55 PINNED_BASE=/home/drakestapleton/workspace/oq3-v8-runs
56 [ "$BASE" = "$PINNED_BASE" ] || { echo "run-qwen3-v8: RUN_BASE must be $PINNED_BASE" >&2; exit 2; }
57 if [ $PART = 1 ]; then
58 [ ! -e "$BASE" ] || { echo "run-qwen3-v8: $BASE already exists (the v6 run is fresh and happens once)" >&2; exit 2; }
59 [ ! -e "$OUT" ] || [ -z "$(ls -A "$OUT" 2>/dev/null)" ] || { echo "run-qwen3-v8: OUT_DIR must be new or empty" >&2; exit 2; }
60 fi
61 [ "$(jq --arg p "$PLACEHOLDER" '[.pins[] | select(. == $p)] | length' "$FROZEN")" = 0 ] ||
62 { echo "run-qwen3-v8: the build pins are not frozen yet (frozen-v8.json, SPEC-v8 Section 6 item 3)" >&2; exit 2; }
63 # Filled pins are not a freeze: a draft freeze-fill change fills them first. The status line changes only at G8.
64 case "$(jq -r .status "$FROZEN")" in FROZEN*) ;; *)
65 echo "run-qwen3-v8: frozen-v8.json status is not FROZEN (SPEC-v8 Section 6 item 6)" >&2; exit 2 ;; esac
66fi
67DECL=$HERE/../scoring/declarations/oq3-v5.decl.json
68SCORER=$HERE/../scoring/score-rows.sh
69[ -f "$DECL" ] && [ -x "$SCORER" ] && [ -x "$REFBIN" ] && [ -x "$MERGEBIN" ] || { echo "run-qwen3-v8: declaration, scorer, reference binary or merge binary missing" >&2; exit 2; }
70: "${AIEN_MODEL_PATH:?}" "${AIEN_TOKENIZER_PATH:?}" "${AIEN_BIN:?}"
71need() { [ "$(printenv "$1")" = "$2" ] || { echo "$1 must be $2 (ACCEPTANCE-v5 Section 7)" >&2; exit 3; }; }
72need AIEN_KV_CONTEXT_TOKENS 4096
73need AIEN_REQUIRE_BLACKWELL 1
74need AIEN_REQUIRE_CHECKPOINT 1
75need AIEN_GB10_QWEN3_DECLARED_ATTEMPT 1
76# The limits are set per launch below; a stale value from the caller is refused, never overridden silently.
77# AIEN_COMPOSE_BUDGET_MS is the retired single budget (sc#284 refuses it too). AIEN_DEV_FALLBACK is new in v5, and so is
78# AIEN_COMPOSE_AUTHORIZE_REQUIRES_DESK (the dev-only desk opt-out of sc#342, valid only with AIEN_DEV_FALLBACK=1).
79for v in AIEN_FORCE_CPU_STUB AIEN_DEV_FALLBACK AIEN_COMPOSE_AUTHORIZE_REQUIRES_DESK AIEN_COMPOSE_MAX_TOKENS AIEN_COMPOSE_DOC_MAX_TOKENS AIEN_COMPOSE_EDIT_BUDGET_MS \
80 AIEN_COMPOSE_DOC_BUDGET_MS AIEN_COMPOSE_BUDGET_MS AIEN_OMEGA_SPIN_US AIEN_OMEGA_CTA_BUDGET; do
81 [ -z "$(printenv $v)" ] || { echo "$v must be unset (ACCEPTANCE-v5 Section 7)" >&2; exit 3; }
82done
83MODEL_DIR=$(dirname "$AIEN_MODEL_PATH")
84chk() { [ "$(sha256sum "$1" | cut -d' ' -f1)" = "$2" ] || { echo "digest mismatch: $1" >&2; exit 3; }; }
85# The model the generation record must bind (row <id>-GR): the index and every shard, re-hashed before each part.
86chk "$AIEN_MODEL_PATH" "$(jq -r .model.index_sha256 "$FROZEN")"
87while read -r n h; do chk "$MODEL_DIR/$n" "$h"; done < <(jq -r '.model.shards[] | "\(.[0]) \(.[1])"' "$FROZEN")
88chk "$AIEN_TOKENIZER_PATH" "$(jq -r .model.tokenizer_sha256 "$FROZEN")"
89chk "$MODEL_DIR/config.json" "$(jq -r .model.config_sha256 "$FROZEN")"
90chk "$MODEL_DIR/generation_config.json" "$(jq -r .model.generation_config_sha256 "$FROZEN")"
91chk "$MODEL_DIR/tokenizer_config.json" "$(jq -r .model.tokenizer_config_sha256 "$FROZEN")"
92# Build pins, read from the checkouts and the binaries (row <id>-PIN). A real run refuses any difference.
93SC=$(git -C "$SCD" rev-parse HEAD 2>/dev/null) && OMC=$(git -C "$OMD" rev-parse HEAD 2>/dev/null) ||
94 { echo "run-qwen3-v8: SC_DIR and OMEGA_DIR must be git checkouts" >&2; exit 2; }
95OMG=$OMC
96[ "$OMC" = "$(tr -d '[:space:]' <"$SCD/omega.lock")" ] || { echo "run-qwen3-v8: OMEGA_DIR HEAD differs from SC_DIR/omega.lock" >&2; exit 2; }
97PINS=$(jq -n --arg sc "$SC" --arg om "$OMC" --arg ph "$(tr -d '[:space:]' <"$OMD/physics.lock" 2>/dev/null)" \
98 --arg ao "$(tr -d '[:space:]' <"$OMD/aienos.lock" 2>/dev/null)" --arg cl "$(sha256sum "$SCD/Cargo.lock" | cut -d' ' -f1)" \
99 --arg cli "$(sha256sum "$AIEN_BIN" | cut -d' ' -f1)" --arg ref "$(sha256sum "$REFBIN" | cut -d' ' -f1)" --arg mrg "$(sha256sum "$MERGEBIN" | cut -d' ' -f1)" \
100 '{sovereign_core_commit: $sc, omega_lock_commit: $om, physics_lock_commit: $ph, aienos_lock_commit: $ao, cargo_lock_sha256: $cl,
101 aien_cli_sha256: $cli, np1_reference_sha256: $ref, np1_edit_merge_sha256: $mrg}')
102if [ -z "${OQ3_DRY_TASKS:-}" ]; then
103 [ -z "$(git -C "$SCD" status --porcelain)" ] || { echo "run-qwen3-v8: SC_DIR has uncommitted changes" >&2; exit 2; }
104 [ "$(jq -c --argjson p "$PINS" '.pins == $p' "$FROZEN")" = true ] ||
105 { echo "run-qwen3-v8: the recorded build pins differ from frozen-v8.json: $(jq -c --argjson p "$PINS" '.pins as $f | [$f | keys[] | select($f[.] != $p[.])]' "$FROZEN")" >&2; exit 2; }
106fi
107RES=$OUT/$TAG-results.jsonl
108if [ $PART = 1 ]; then
109 [ ! -e "$BASE/part1.done" ] && [ ! -e "$RES" ] || { echo "run-qwen3-v8: part 1 already ran here" >&2; exit 2; }
110 mkdir -p "$BASE" "$OUT"; : >"$RES"
111else
112 prev=$((PART - 1))
113 [ -f "$BASE/part$prev.done" ] && [ ! -e "$BASE/part$PART.started" ] || { echo "run-qwen3-v8: part $PART needs a completed part $prev and runs once" >&2; exit 2; }
114 : >"$BASE/part$PART.started"
115fi
116sha256sum "$AIEN_BIN" "$REFBIN" "$MERGEBIN" "$TASKS" "$DECL" "$FROZEN" "$HERE/rows-oq3-v3.jq" "$HERE/rows-oq3-v4.jq" "$HERE/rows-oq3-v5.jq" \
117 "$HERE/v5-rows.sh" "$HERE/run-campaign-allen.sh" "$HERE/build-allen-subject.sh" "$0" > "$BASE/identity-part$PART.sha256"
118if [ $PART != 1 ] && ! cmp -s <(cut -d" " -f1 "$BASE/identity-part1.sha256") <(cut -d" " -f1 "$BASE/identity-part$PART.sha256"); then
119 echo "run-qwen3-v8: part $PART binaries, tasks, declaration, frozen values, rows or wrapper differ from part 1 (one build per run)" >&2; exit 2
120fi
121printf '%s\n' "$PINS" >"$BASE/pins-part$PART.json"
122# Memory before the part (row <id>-MEAS), from /proc/meminfo, in kB.
123MEM=$(awk '/^MemFree:/ {f=$2} /^Cached:/ {c=$2} END {printf "{\"mem_free_kb\":%d,\"cached_kb\":%d}", f, c}' /proc/meminfo)
124printf '%s\n' "$MEM" >"$BASE/meminfo-part$PART.json"
125# Launch wall time on CLOCK_BOOTTIME (monotonic, 10 ms ticks), in ms.
126up_ms() { echo $(( $(tr -d . </proc/uptime | cut -d' ' -f1) * 10 )); }
127# The receipt builder looks for tasks-v8.json, rows-v5/v8.jq and the seed folders next to itself. A staging folder of
128# links to the unchanged next-phase-1 files, with tasks-v8.json replaced by this campaign's tasks file and seed-v5
129# linked in, lets make-receipt.sh and rows-v9.jq be used (rows-v9.jq is rows-v8.jq with the harness approval-desk key allowed in the
130# compose dir, sc#342; rows-v8.jq itself stays byte-identical because completed runs pin it).
131STAGE=$BASE/stage
132# The unchanged make-receipt.sh reads seed/<destination> for any task that has a seed, which only fits edits. A non-edit
133# task whose seed holds other files (D4: its source file; R1: the notes/ folder its destination needs, Section 2) is
134# staged with seed null for the receipt builder only; the driver still gets the real seed from the tasks file
135# (NP1_SEED_DIR below), and v5-rows.sh checks the D4 source file itself (row SRC).
136STAGE_FILTER='(.tasks[] | select(.kind != "edit") | .seed) = null'
137if [ $PART = 1 ]; then
138 mkdir -p "$STAGE"
139 for f in "$NP1"/*; do
140 n=$(basename "$f"); case $n in tasks-v8.json) continue ;; esac
141 ln -s "$f" "$STAGE/$n"
142 done
143 jq "$STAGE_FILTER" "$TASKS" >"$STAGE/tasks-v8.json"
144 ln -s "$HERE/seed-v5" "$STAGE/seed-v5"
145fi
146[ "$(jq "$STAGE_FILTER" "$TASKS")" = "$(cat "$STAGE/tasks-v8.json")" ] || { echo "run-qwen3-v8: staged tasks file differs from the tasks file" >&2; exit 2; }
147# Product limits (ACCEPTANCE-v5 Section 2) come from the task's own max_tokens and budget_ms (row <id>-D scores the
148# same budget_ms); only D6 differs from the product values (Drake 2026-10-09, ACCEPTANCE-v5 Section 2.1).
149for id in $LAUNCHES; do
150 t=$(jq -c --arg id "$id" '.tasks[] | select(.id == $id)' "$TASKS")
151 goal=$(jq -r .goal <<<"$t"); max=$(jq -r .max_tokens <<<"$t"); bud=$(jq -r .budget_ms <<<"$t"); kind=$(jq -r .kind <<<"$t"); seed=$(jq -r '.seed // empty' <<<"$t")
152 seed_dir=; [ -n "$seed" ] && seed_dir=$HERE/$seed
153 # An edit goal (names an existing file) uses the edit cap AIEN_COMPOSE_MAX_TOKENS and budget AIEN_COMPOSE_EDIT_BUDGET_MS;
154 # every other goal creates a new file and uses the document cap and budget. The other cap and budget stay at their product values.
155 if [ "$kind" = edit ]; then ecap=$max dcap=$(jq -r .limits.doc_max_tokens "$TASKS") ebud=$bud dbud=$(jq -r .limits.doc_budget_ms "$TASKS")
156 else ecap=$(jq -r .limits.edit_max_tokens "$TASKS") dcap=$max ebud=$(jq -r .limits.edit_budget_ms "$TASKS") dbud=$bud; fi
157 export AIEN_COMPOSE_EDIT_BUDGET_MS=$ebud AIEN_COMPOSE_DOC_BUDGET_MS=$dbud
158 t0=$(up_ms)
159 NP1_GOAL=$goal AIEN_COMPOSE_MAX_TOKENS=$ecap AIEN_COMPOSE_DOC_MAX_TOKENS=$dcap NP1_SEED_DIR=$seed_dir \
160 NP1_DIR=$NP1 NP1_ALLEN_BUILDER=$HERE/build-allen-subject.sh OQ3_SC_DIR=$SCD OQ3_ALLEN_TARGET=$BASE/allen-target \
161 bash "$HERE/run-campaign-allen.sh" "$BASE/$id" >"$BASE/$id.driver.out" 2>&1
162 drc=$?; t1=$(up_ms)
163 jq -n --arg id "$id" --argjson w $((t1 - t0)) --argjson m "$MEM" --argjson p "$PINS" --argjson rc $drc \
164 '{launch: $id, wall_ms: $w, wall_clock: "CLOCK_BOOTTIME, 10 ms ticks, around the driver call", driver_exit: $rc, meminfo_before: $m, pins: $p}' >"$BASE/$id.launch-v5.json"
165 echo "launch $id driver exit $drc in $((t1 - t0)) ms (edit cap $ecap, document cap $dcap, budgets $AIEN_COMPOSE_EDIT_BUDGET_MS/$AIEN_COMPOSE_DOC_BUDGET_MS ms${seed:+, seed $seed})"
166 ref=
167 if [ "$kind" = identity ] && [ -d "$BASE/$id/ws" ]; then
168 ws=$(cd "$BASE/$id/ws" && pwd -P)
169 NP1_REFERENCE_ALLEN=default "$REFBIN" "$MODEL_DIR" "$goal" "$ws" "$max" new >"$BASE/$id.reference.json" 2>"$BASE/$id.reference.err"
170 echo "launch $id CPU reference exit $?"
171 ref=$BASE/$id.reference.json
172 fi
173 if [ -f "$BASE/$id/run.json" ]; then
174 v8merge=null
175 if [ "$kind" = edit ] && [ -f "$BASE/$id/s3-report.json" ]; then
176 rf=$BASE/$id.accepted-reply.txt
177 if jq -e '[.proposal_attempts // [] | .[] | select(.outcome == "parsed")] | length > 0' "$BASE/$id/s3-report.json" >/dev/null 2>&1; then
178 jq -j '[.proposal_attempts[] | select(.outcome == "parsed")] | last | .text' "$BASE/$id/s3-report.json" >"$rf"
179 m=$("$MERGEBIN" "$(jq -r .destination <<<"$t")" "$HERE/$seed/$(jq -r .destination <<<"$t")" "$rf" 2>"$BASE/$id.merge.err")
180 if jq . <<<"$m" >/dev/null 2>&1; then v8merge=$(jq -c . <<<"$m"); fi
181 fi
182 echo "launch $id edit re-derivation: $(jq -r 'if . == null then "none" else "ok=\(.ok)" end' <<<"$v8merge")"
183 fi
184 v5env=(); [ "$(jq -r '.destination // empty' <<<"$t")" != "" ] && [ "${id#N}" = "$id" ] && \
185 v5env=(TASK_ID="$id" TASK_SPEC="$TASKS" TASK_ACCEPTANCE="$HERE/ACCEPTANCE-v5.md")
186 env "${v5env[@]}" V6_ROWS=rows-v9.jq V8_MERGE="$v8merge" V6_TASK="$id" V6_MAX_TOKENS="$max" V6_REFERENCE="$ref" \
187 SPEC="open-model-qwen3/SPEC-v8.md (rows of ACCEPTANCE-v5.md) spec_version 8${OQ3_DRY_TASKS:+ DRY RUN}" bash "$STAGE/make-receipt.sh" \
188 "$BASE/$id" "$OUT" "$SC" "$OMC" "$OMG" 0 "OPEN-MODEL-QWEN3 v8${OQ3_DRY_TASKS:+ DRY RUN} launch $id" >"$BASE/$id.receipt.out" 2>&1
189 rec=$OUT/$(head -1 "$BASE/$id.receipt.out" | sed -n 's/.*receipt \([0-9a-f]*\.json\).*/\1/p')
190 if [ -f "$rec" ]; then
191 bash "$NP1/v8-results.sh" "$id" "$rec" >>"$RES"
192 bash "$HERE/v5-rows.sh" "$BASE/$id" "$id" "$TASKS" "$OUT" "$(basename "$rec")" "$BASE/$id.launch-v5.json" "$FROZEN" >>"$RES"
193 else bash "$NP1/v8-results.sh" "$id" - "$DECL" "receipt not written" >>"$RES"; fi
194 echo "launch $id receipt $(basename "$rec")"
195 else
196 bash "$NP1/v8-results.sh" "$id" - "$DECL" "launch failed: no run.json" >>"$RES"
197 echo "launch $id FAILED to launch"
198 fi
199 jq -r --arg id "$id" 'select(.row | startswith($id + "/")) | select(.verdict != "PASS") | " \(.verdict) \(.row)"' "$RES"
200done
201: >"$BASE/part$PART.done"
202if [ $PART -le 3 ]; then echo "part $PART done ($LAUNCHES); run part $((PART + 1)) in a new hold"; exit 0; fi
203# Qualification verdict: the declaration and the result file only (ACCEPTANCE-v5 Section 5). Rows a receipt computes
204# but the declaration does not hold (for N1: N1-B, N1-C, N1-H) are listed by the scorer as extras, never counted.
205bash "$SCORER" "$DECL" "$RES" >"$OUT/$TAG-score.json"; rc=$?
206echo "OPEN-MODEL-QWEN3 v8${OQ3_DRY_TASKS:+ DRY RUN (not a verdict)} QUALIFICATION (scoring-v5, score-rows.sh exit $rc): $(jq -r .verdict "$OUT/$TAG-score.json" 2>/dev/null || echo ERROR)"
207exit $rc