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-v3.sh

173 lines · 12206 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 v3 campaign (ACCEPTANCE-v3.md; FROZEN when this file is on main: it refuses to run unless the
18# commits and the binaries sha256 below match). Eight launches in three parts, Qwen3-4B, adapted from
19# run-qwen3-v2.sh: same driver (next-phase-1/run-campaign.sh), same receipt builder and v8 rows, same
20# scorer; new tasks (tasks-oq3-v3.json), declaration (oq3-v3.decl.json) and extra rows (v3-rows.sh).
21# Shell + jq only. Run inside the caller's quietlock hold.
22# AIEN_BIN=... AIEN_MODEL_PATH=.../model.safetensors.index.json AIEN_TOKENIZER_PATH=... \
23# AIEN_KV_CONTEXT_TOKENS=4096 AIEN_REQUIRE_BLACKWELL=1 AIEN_GB10_QWEN3_DECLARED_ATTEMPT=1 \
24# OQ3_PART=1|2|3 run-qwen3-v3.sh RUN_BASE OUT_DIR SC_COMMIT OMEGA_COMPOSE_COMMIT OMEGA_GPU_COMMIT REFERENCE_BIN MERGE_BIN
25# Parts (ACCEPTANCE-v3 Section 8): 1 = G1 G2 G3, 2 = E1 E2 N1 N2, 3 = R1 and the score. Part k needs part k-1
26# completed in the same RUN_BASE with the same binaries, tasks file, declaration and wrapper.
27# Dry run (ACCEPTANCE-v3 Section 9): OQ3_DRY_TASKS=<tasks file with the same ids, kinds, max_tokens,
28# budgets, destinations and seeds and made-up goals> lifts the pinned paths and writes oq3-v3-DRYRUN-*
29# outputs. A dry run is never a verdict.
30set -u
31PART=${OQ3_PART:?OQ3_PART must be 1, 2 or 3}
32case $PART in 1) LAUNCHES="G1 G2 G3" ;; 2) LAUNCHES="E1 E2 N1 N2" ;; 3) LAUNCHES="R1" ;; *) echo "run-qwen3-v3: OQ3_PART must be 1, 2 or 3" >&2; exit 2 ;; esac
33HERE=$(cd "$(dirname "$0")" && pwd)
34NP1=$(cd "$HERE/../next-phase-1" && pwd)
35BASE=${1:?RUN_BASE} OUT=${2:?OUT_DIR} SC=${3:?SC_COMMIT} OMC=${4:?OMEGA_COMPOSE} OMG=${5:?OMEGA_GPU} REFBIN=${6:?REFERENCE_BIN} MERGEBIN=${7:?MERGE_BIN}
36
37# ---- Build identity (ACCEPTANCE-v3 Section 7), filled at the freeze: sovereign-core main 8f3e8c8 (sc#285, #284, #287 merged),
38# omega.lock 01f6a74 (omega#331). A real run refuses unless the commit arguments and the three binaries sha256 equal these.
39PLACEHOLDER="TO BE FILLED at freeze, after all required changes merge and the combined build passes review and checks"
40FROZEN_SC_COMMIT=8f3e8c8b879e10dd83883cee150f16508284d643
41FROZEN_OMEGA_COMMIT=01f6a74636b8383b010cdb95597839582c415c27
42FROZEN_AIEN_CLI_SHA256=689027ea9ac09f52ec130a2d0b0310995b7539113ccd3a63b06f1037ad2cf4de
43FROZEN_NP1_REFERENCE_SHA256=df91eede1223f454b7c6afd47589aac6406c8e69e393018fdbe3377b2103f686
44FROZEN_NP1_EDIT_MERGE_SHA256=abc345a47e872728e8b59d050ccf41794c78266e19da882ad6e3d1db681c6377
45
46TASKS=$HERE/tasks-oq3-v3.json TAG=oq3-v3
47if [ -n "${OQ3_DRY_TASKS:-}" ]; then
48 TASKS=$OQ3_DRY_TASKS TAG=oq3-v3-DRYRUN
49 shape='[.tasks[] | [.id, .kind, .max_tokens, .budget_ms, .destination, .seed]]'
50 [ "$(jq -c "$shape" "$TASKS")" = "$(jq -c "$shape" "$HERE/tasks-oq3-v3.json")" ] ||
51 { echo "run-qwen3-v3: dry-run tasks must keep the v3 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 the build identity must be filled in and must match.
55 PINNED_BASE=/home/drakestapleton/workspace/oq3-v3-runs
56 [ "$BASE" = "$PINNED_BASE" ] || { echo "run-qwen3-v3: RUN_BASE must be $PINNED_BASE" >&2; exit 2; }
57 if [ $PART = 1 ]; then
58 [ ! -e "$BASE" ] || { echo "run-qwen3-v3: $BASE already exists (the v3 run is fresh and happens once)" >&2; exit 2; }
59 [ ! -e "$OUT" ] || [ -z "$(ls -A "$OUT" 2>/dev/null)" ] || { echo "run-qwen3-v3: OUT_DIR must be new or empty" >&2; exit 2; }
60 fi
61 for v in "$FROZEN_SC_COMMIT" "$FROZEN_OMEGA_COMMIT" "$FROZEN_AIEN_CLI_SHA256" "$FROZEN_NP1_REFERENCE_SHA256" "$FROZEN_NP1_EDIT_MERGE_SHA256"; do
62 [ "$v" != "$PLACEHOLDER" ] || { echo "run-qwen3-v3: the build identity is not frozen yet (ACCEPTANCE-v3 Section 7)" >&2; exit 2; }
63 done
64 [ "$SC" = "$FROZEN_SC_COMMIT" ] && [ "$OMC" = "$FROZEN_OMEGA_COMMIT" ] && [ "$OMG" = "$FROZEN_OMEGA_COMMIT" ] ||
65 { echo "run-qwen3-v3: SC_COMMIT, OMEGA_COMPOSE_COMMIT and OMEGA_GPU_COMMIT must equal the frozen commits" >&2; exit 2; }
66fi
67DECL=$HERE/../scoring/declarations/oq3-v3.decl.json
68SCORER=$HERE/../scoring/score-rows.sh
69[ -f "$DECL" ] && [ -x "$SCORER" ] && [ -x "$REFBIN" ] && [ -x "$MERGEBIN" ] || { echo "run-qwen3-v3: 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-v3 Section 7)" >&2; exit 3; }; }
72need AIEN_KV_CONTEXT_TOKENS 4096
73need AIEN_REQUIRE_BLACKWELL 1
74need AIEN_GB10_QWEN3_DECLARED_ATTEMPT 1
75# The limits are set per launch below; a stale value from the caller is refused, never overridden silently.
76# AIEN_COMPOSE_BUDGET_MS is the retired single budget (sc#284 refuses it too).
77for v in AIEN_FORCE_CPU_STUB AIEN_COMPOSE_MAX_TOKENS AIEN_COMPOSE_DOC_MAX_TOKENS AIEN_COMPOSE_EDIT_BUDGET_MS \
78 AIEN_COMPOSE_DOC_BUDGET_MS AIEN_COMPOSE_BUDGET_MS AIEN_OMEGA_SPIN_US AIEN_OMEGA_CTA_BUDGET; do
79 [ -z "$(printenv $v)" ] || { echo "$v must be unset (ACCEPTANCE-v3 Section 7)" >&2; exit 3; }
80done
81MODEL_DIR=$(dirname "$AIEN_MODEL_PATH")
82chk() { [ "$(sha256sum "$1" | cut -d' ' -f1)" = "$2" ] || { echo "digest mismatch: $1" >&2; exit 3; }; }
83chk "$AIEN_MODEL_PATH" d6c42883a895dfef5b0080ed2116a1bcd764f558406b98923d675978a1abf29c
84chk "$MODEL_DIR/model-00001-of-00003.safetensors" 75311d91bb08cf0b882913da464a1e722a31fb44db35208663487efb7a3d8ed6
85chk "$MODEL_DIR/model-00002-of-00003.safetensors" 0b48adbb1f60e901153d91907ba11ce63bd4b8b584482e730f48808d055dfba1
86chk "$MODEL_DIR/model-00003-of-00003.safetensors" 7dd39ccca5e4de123c74c14af44c9bf2eb75df33b4614382af0134528e060d5d
87chk "$AIEN_TOKENIZER_PATH" aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4
88chk "$MODEL_DIR/config.json" 5beea1a4a34c62782bfb2f911c606741a3bab8f92d80a118fa053c28af12e8ba
89chk "$MODEL_DIR/generation_config.json" 835fffe355c9438e7a25be099b3fccaa98350b83451f9fd2d99512e74f1ade48
90if [ -z "${OQ3_DRY_TASKS:-}" ]; then
91 chk "$AIEN_BIN" "$FROZEN_AIEN_CLI_SHA256"
92 chk "$REFBIN" "$FROZEN_NP1_REFERENCE_SHA256"
93 chk "$MERGEBIN" "$FROZEN_NP1_EDIT_MERGE_SHA256"
94fi
95RES=$OUT/$TAG-results.jsonl
96if [ $PART = 1 ]; then
97 [ ! -e "$BASE/part1.done" ] && [ ! -e "$RES" ] || { echo "run-qwen3-v3: part 1 already ran here" >&2; exit 2; }
98 mkdir -p "$BASE" "$OUT"; : >"$RES"
99else
100 prev=$((PART - 1))
101 [ -f "$BASE/part$prev.done" ] && [ ! -e "$BASE/part$PART.started" ] || { echo "run-qwen3-v3: part $PART needs a completed part $prev and runs once" >&2; exit 2; }
102 : >"$BASE/part$PART.started"
103fi
104sha256sum "$AIEN_BIN" "$REFBIN" "$MERGEBIN" "$TASKS" "$DECL" "$HERE/rows-oq3-v3.jq" "$HERE/v3-rows.sh" "$0" > "$BASE/identity-part$PART.sha256"
105if [ $PART != 1 ] && ! cmp -s <(cut -d" " -f1 "$BASE/identity-part1.sha256") <(cut -d" " -f1 "$BASE/identity-part$PART.sha256"); then
106 echo "run-qwen3-v3: part $PART binaries, tasks, declaration, rows or wrapper differ from part 1 (one build per run)" >&2; exit 2
107fi
108# The receipt builder looks for tasks-v8.json, rows-v5/v8.jq and the seed folders next to itself. A staging folder of
109# links to the unchanged next-phase-1 files, with tasks-v8.json replaced by this campaign's tasks file and seed-v3
110# linked in, lets the unchanged make-receipt.sh and rows-v8.jq be used (ACCEPTANCE-v3 Section 6).
111STAGE=$BASE/stage
112if [ $PART = 1 ]; then
113 mkdir -p "$STAGE"
114 for f in "$NP1"/*; do
115 n=$(basename "$f"); case $n in tasks-v8.json) continue ;; esac
116 ln -s "$f" "$STAGE/$n"
117 done
118 cp "$TASKS" "$STAGE/tasks-v8.json"
119 ln -s "$HERE/seed-v3" "$STAGE/seed-v3"
120fi
121cmp -s "$TASKS" "$STAGE/tasks-v8.json" || { echo "run-qwen3-v3: staged tasks file differs from the tasks file" >&2; exit 2; }
122# Product limits (ACCEPTANCE-v3 Section 1), the same for every launch.
123export AIEN_COMPOSE_EDIT_BUDGET_MS=$(jq -r .limits.edit_budget_ms "$TASKS") AIEN_COMPOSE_DOC_BUDGET_MS=$(jq -r .limits.doc_budget_ms "$TASKS")
124for id in $LAUNCHES; do
125 t=$(jq -c --arg id "$id" '.tasks[] | select(.id == $id)' "$TASKS")
126 goal=$(jq -r .goal <<<"$t"); max=$(jq -r .max_tokens <<<"$t"); kind=$(jq -r .kind <<<"$t"); seed=$(jq -r '.seed // empty' <<<"$t")
127 seed_dir=; [ -n "$seed" ] && seed_dir=$HERE/$seed
128 # An edit goal (names an existing file) uses the edit cap AIEN_COMPOSE_MAX_TOKENS; every other goal creates a
129 # new file and uses the document cap AIEN_COMPOSE_DOC_MAX_TOKENS. The other cap stays at its product value.
130 if [ "$kind" = edit ]; then ecap=$max dcap=$(jq -r .limits.doc_max_tokens "$TASKS"); else ecap=$(jq -r .limits.edit_max_tokens "$TASKS") dcap=$max; fi
131 NP1_GOAL=$goal AIEN_COMPOSE_MAX_TOKENS=$ecap AIEN_COMPOSE_DOC_MAX_TOKENS=$dcap NP1_SEED_DIR=$seed_dir \
132 bash "$NP1/run-campaign.sh" "$BASE/$id" >"$BASE/$id.driver.out" 2>&1
133 echo "launch $id driver exit $? (edit cap $ecap, document cap $dcap, budgets $AIEN_COMPOSE_EDIT_BUDGET_MS/$AIEN_COMPOSE_DOC_BUDGET_MS ms${seed:+, seed $seed})"
134 ref=
135 if [ "$kind" = identity ] && [ -d "$BASE/$id/ws" ]; then
136 ws=$(cd "$BASE/$id/ws" && pwd -P)
137 "$REFBIN" "$MODEL_DIR" "$goal" "$ws" "$max" new >"$BASE/$id.reference.json" 2>"$BASE/$id.reference.err"
138 echo "launch $id CPU reference exit $?"
139 ref=$BASE/$id.reference.json
140 fi
141 if [ -f "$BASE/$id/run.json" ]; then
142 v8merge=null
143 if [ "$kind" = edit ] && [ -f "$BASE/$id/s3-report.json" ]; then
144 rf=$BASE/$id.accepted-reply.txt
145 if jq -e '[.proposal_attempts // [] | .[] | select(.outcome == "parsed")] | length > 0' "$BASE/$id/s3-report.json" >/dev/null 2>&1; then
146 jq -j '[.proposal_attempts[] | select(.outcome == "parsed")] | last | .text' "$BASE/$id/s3-report.json" >"$rf"
147 m=$("$MERGEBIN" "$(jq -r .destination <<<"$t")" "$HERE/$seed/$(jq -r .destination <<<"$t")" "$rf" 2>"$BASE/$id.merge.err")
148 if jq . <<<"$m" >/dev/null 2>&1; then v8merge=$(jq -c . <<<"$m"); fi
149 fi
150 echo "launch $id edit re-derivation: $(jq -r 'if . == null then "none" else "ok=\(.ok)" end' <<<"$v8merge")"
151 fi
152 v5env=(); [ "$(jq -r '.destination // empty' <<<"$t")" != "" ] && [ "${id#N}" = "$id" ] && \
153 v5env=(TASK_ID="$id" TASK_SPEC="$TASKS" TASK_ACCEPTANCE="$HERE/ACCEPTANCE-v3.md")
154 env "${v5env[@]}" V6_ROWS=rows-v8.jq V8_MERGE="$v8merge" V6_TASK="$id" V6_MAX_TOKENS="$max" V6_REFERENCE="$ref" \
155 SPEC="open-model-qwen3/ACCEPTANCE-v3.md spec_version 3${OQ3_DRY_TASKS:+ DRY RUN}" bash "$STAGE/make-receipt.sh" \
156 "$BASE/$id" "$OUT" "$SC" "$OMC" "$OMG" 0 "OPEN-MODEL-QWEN3 v3${OQ3_DRY_TASKS:+ DRY RUN} launch $id" >"$BASE/$id.receipt.out" 2>&1
157 rec=$OUT/$(head -1 "$BASE/$id.receipt.out" | sed -n 's/.*receipt \([0-9a-f]*\.json\).*/\1/p')
158 if [ -f "$rec" ]; then
159 bash "$NP1/v8-results.sh" "$id" "$rec" >>"$RES"
160 bash "$HERE/v3-rows.sh" "$BASE/$id" "$id" "$TASKS" "$OUT" "$(basename "$rec")" >>"$RES"
161 else bash "$NP1/v8-results.sh" "$id" - "$DECL" "receipt not written" >>"$RES"; fi
162 echo "launch $id receipt $(basename "$rec")"
163 else
164 bash "$NP1/v8-results.sh" "$id" - "$DECL" "launch failed: no run.json" >>"$RES"
165 echo "launch $id FAILED to launch"
166 fi
167 jq -r --arg id "$id" 'select(.row | startswith($id + "/")) | select(.verdict != "PASS") | " \(.verdict) \(.row)"' "$RES"
168done
169: >"$BASE/part$PART.done"
170if [ $PART != 3 ]; then echo "part $PART done ($LAUNCHES); run part $((PART + 1)) in a new hold"; exit 0; fi
171bash "$SCORER" "$DECL" "$RES" >"$OUT/$TAG-score.json"; rc=$?
172echo "OPEN-MODEL-QWEN3 v3${OQ3_DRY_TASKS:+ DRY RUN (not a verdict)} (scoring-v5, score-rows.sh exit $rc): $(jq -r .verdict "$OUT/$TAG-score.json" 2>/dev/null || echo ERROR)"
173exit $rc