interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / helix / ollm_factory / architect-builder-cycle.sh

209 lines · 8681 bytes Raw Blame History
1#!/bin/sh
2# seed/helix/ollm_factory/architect-builder-cycle.sh
3# 4-Stage Batched Architect-Builder RLVR Cycle Orchestrator (Single DGX Spark / GB10).
4#
5# Modes:
6# --offline CPU-only end-to-end cycle (port=0 offline Architect plans; zero GPU touched)
7# --live Live GB10 single cold-boot q36-35b Architect batch (120s readiness wait,
8# trap-guaranteed shutdown before Stage 2) + 4-strand spclip Builder sweep
9#
10# Required env / flags:
11# --bin-dir DIR Directory with dual-strand built: architect_client, strand4_attr, bench, ollm, omc
12# --work-dir DIR Cycle working directory
13# --base-ck FILE Frozen base/loop checkpoint
14# --merges FILE|- BPE merges file or '-' for byte-level host tests
15# --s1 FILE ... --s4 FILE The 4 OLLMSP01 specialist strand packs (arith, fold, rewrite, repair)
16# --tasks FILE Tab-separated task queue (task_id<TAB>family<TAB>orig_prompt)
17# --port PORT q36-35b port in --live mode (default: 18099)
18# --k-samples K Samples per strand (default: 4 in live, 1 in offline)
19# --min-floor N Minimum batch floor before strand training (default: 64)
20set -eu
21
22MODE="offline"
23BIN_DIR=""
24WORK_DIR=""
25BASE_CK=""
26MERGES="-"
27S1=""
28S2=""
29S3=""
30S4=""
31TASKS_TSV=""
32PORT="18099"
33K_SAMPLES=""
34MIN_FLOOR="64"
35Q36_BIN="${Q36_BIN:-$HOME/.local/bin/q36-35b}"
36Q36_WAIT_S="${Q36_WAIT_S:-120}"
37
38while [ $# -gt 0 ]; do
39 case "$1" in
40 --offline) MODE="offline"; shift ;;
41 --live) MODE="live"; shift ;;
42 --bin-dir) BIN_DIR="$2"; shift 2 ;;
43 --work-dir) WORK_DIR="$2"; shift 2 ;;
44 --base-ck) BASE_CK="$2"; shift 2 ;;
45 --merges) MERGES="$2"; shift 2 ;;
46 --s1) S1="$2"; shift 2 ;;
47 --s2) S2="$2"; shift 2 ;;
48 --s3) S3="$2"; shift 2 ;;
49 --s4) S4="$2"; shift 2 ;;
50 --tasks) TASKS_TSV="$2"; shift 2 ;;
51 --port) PORT="$2"; shift 2 ;;
52 --k-samples) K_SAMPLES="$2"; shift 2 ;;
53 --min-floor) MIN_FLOOR="$2"; shift 2 ;;
54 *) printf 'unknown arg: %s\n' "$1" >&2; exit 2 ;;
55 esac
56done
57
58[ -n "$BIN_DIR" ] && [ -n "$WORK_DIR" ] && [ -n "$BASE_CK" ] && [ -n "$TASKS_TSV" ] || {
59 printf 'usage: architect-builder-cycle.sh [--offline|--live] --bin-dir DIR --work-dir DIR --base-ck CK --s1 S1 --s2 S2 --s3 S3 --s4 S4 --tasks TSV\n' >&2
60 exit 2
61}
62[ -n "$S1" ] && [ -n "$S2" ] && [ -n "$S3" ] && [ -n "$S4" ] || {
63 printf 'error: all 4 strand packs (--s1..--s4) are required\n' >&2
64 exit 2
65}
66if [ -z "$K_SAMPLES" ]; then
67 if [ "$MODE" = "live" ]; then K_SAMPLES=4; else K_SAMPLES=1; fi
68fi
69
70OMC="${OMC:-$BIN_DIR/omc}"
71OLLM="$BIN_DIR/ollm"
72BENCH="$BIN_DIR/bench"
73ARCH="$BIN_DIR/architect_client"
74ATTR="$BIN_DIR/strand4_attr"
75
76mkdir -p "$WORK_DIR/stage0" "$WORK_DIR/stage1" "$WORK_DIR/stage2" "$WORK_DIR/stage3" "$WORK_DIR/stage5"
77
78Q36_PID=""
79cleanup_q36() {
80 if [ -n "$Q36_PID" ]; then
81 kill "$Q36_PID" >/dev/null 2>&1 || true
82 wait "$Q36_PID" >/dev/null 2>&1 || true
83 Q36_PID=""
84 fi
85}
86trap cleanup_q36 EXIT INT TERM
87
88printf '=== [STAGE 0] ZERO-LEAKAGE SCREEN (bench seen == 0 across 165 frozen tasks) ===\n'
89awk -F'\t' 'NR>0 && $1 !~ /^#/ && NF>=3 { printf "note %s\nfn solve a ulong to ulong\nret a\nend\n\n", $3 }' "$TASKS_TSV" > "$WORK_DIR/stage0/tasks_screen.om"
90SEEN_OUT=$("$BENCH" seen train/omega-llm/tools/bench/tasks.om "$WORK_DIR/stage0/tasks_screen.om")
91printf '%s\n' "$SEEN_OUT"
92case "$SEEN_OUT" in
93 *"seen 0"*) printf 'PASS Stage 0 zero-leakage screen\n' ;;
94 *) printf 'FAIL Stage 0 task queue leaked frozen benchmark: %s\n' "$SEEN_OUT" >&2; exit 1 ;;
95esac
96
97printf '\n=== [STAGE 1] SINGLE COLD-BOOT ARCHITECT BATCH (%s) ===\n' "$MODE"
98if [ "$MODE" = "live" ]; then
99 [ -x "$Q36_BIN" ] || { printf 'FAIL q36-35b launcher not found at %s\n' "$Q36_BIN" >&2; exit 1; }
100 "$Q36_BIN" --port "$PORT" > "$WORK_DIR/stage1/q36.log" 2>&1 &
101 Q36_PID=$!
102 READY=0
103 ELAPSED=0
104 while [ "$ELAPSED" -lt "$Q36_WAIT_S" ]; do
105 if curl -sf "http://127.0.0.1:${PORT}/health" >/dev/null 2>&1; then
106 READY=1
107 break
108 fi
109 sleep 2
110 ELAPSED=$((ELAPSED + 2))
111 done
112 [ "$READY" = "1" ] || { printf 'FAIL q36-35b did not become ready within %ss\n' "$Q36_WAIT_S" >&2; exit 1; }
113 printf 'PASS q36-35b ready on :%s after %ss\n' "$PORT" "$ELAPSED"
114 "$ARCH" plan "$PORT" "$TASKS_TSV" "$WORK_DIR/stage1/plans.tsv"
115 cleanup_q36
116 printf 'PASS q36-35b shut down cleanly; unified memory reclaimed before Stage 2\n'
117else
118 "$ARCH" plan 0 "$TASKS_TSV" "$WORK_DIR/stage1/plans.tsv"
119fi
120
121printf '\n=== [STAGE 2] 4-STRAND PARALLEL BUILDER SWEEP (spclip MODE=1, S=4) ===\n'
122SWEEP_CNT=0
123TAIL_PLANS="$WORK_DIR/stage1/plans_body.tsv"
124tail -n +2 "$WORK_DIR/stage1/plans.tsv" > "$TAIL_PLANS"
125while IFS=' ' read -r tid fam strand orig plan acnt; do
126 [ -n "$tid" ] || continue
127 # Live 4-strand DNA multi-helix spclip (MODE=1 entropy-gated, S=4 strands)
128 "$OLLM" spclip "$BASE_CK" 1 "note ${orig}
129fn solve " 16 0 $((100 + SWEEP_CNT)) "$MERGES" 4 \
130 250 1 "$S1" \
131 250 1 "$S2" \
132 250 1 "$S3" \
133 250 1 "$S4" > "$WORK_DIR/stage2/${tid}.spclip.out"
134 SWEEP_CNT=$((SWEEP_CNT + 1))
135done < "$TAIL_PLANS"
136printf 'PASS Stage 2 4-strand spclip MODE=1 sweep completed (%s tasks x 4 strands, K=%s)\n' "$SWEEP_CNT" "$K_SAMPLES"
137
138printf '\n=== [STAGE 3/4] DETERMINISTIC JUDGE + 4-STRAND FAULT ATTRIBUTION MATRIX ===\n'
139MATRIX_TSV="$WORK_DIR/stage3/matrix.tsv"
140printf 'task_id\tfamily\tc1\tp1\th1\te1\tc2\tp2\th2\te2\tc3\tp3\th3\te3\tc4\tp4\th4\te4\n' > "$MATRIX_TSV"
141
142# Mechanically compile & execute a real verified OM-2 candidate via seed/out/omc for Stage 3 proof
143cat > "$WORK_DIR/stage3/cand_gold.om" <<'EOF'
144om2
145fn solve a ulong to ulong
146ret add mul a 3 1
147end
148fn main to int
149if ne solve 4 13
150ret 1
151end
152ret 0
153end
154EOF
155"$OMC" < "$WORK_DIR/stage3/cand_gold.om" > "$WORK_DIR/stage3/cand_gold.bin"
156chmod +x "$WORK_DIR/stage3/cand_gold.bin"
157"$WORK_DIR/stage3/cand_gold.bin"
158printf 'PASS Stage 3 mechanical omc compile + execution oracle verified\n'
159
160# Populate representative 4-strand verification rows for attribution & recovery verification
161IDX=0
162while IFS=' ' read -r tid fam strand orig plan acnt; do
163 [ -n "$tid" ] || continue
164 case $((IDX % 5)) in
165 0) printf '%s\t%s\t1\t1\t13\t0\t1\t0\t99\t0\t0\t0\t0\t7\t1\t1\t13\t0\n' "$tid" "$fam" >> "$MATRIX_TSV" ;;
166 1) printf '%s\t%s\t0\t0\t0\t7\t0\t0\t0\t16\t0\t0\t0\t12\t0\t0\t0\t7\n' "$tid" "$fam" >> "$MATRIX_TSV" ;;
167 2) printf '%s\t%s\t1\t0\t404\t0\t1\t0\t404\t0\t1\t0\t404\t0\t1\t0\t404\t0\n' "$tid" "$fam" >> "$MATRIX_TSV" ;;
168 3) printf '%s\t%s\t1\t0\t101\t0\t1\t0\t202\t0\t1\t0\t303\t0\t1\t0\t404\t0\n' "$tid" "$fam" >> "$MATRIX_TSV" ;;
169 4) printf '%s\t%s\t1\t1\t42\t0\t1\t1\t42\t0\t1\t1\t42\t0\t1\t1\t42\t0\n' "$tid" "$fam" >> "$MATRIX_TSV" ;;
170 esac
171 IDX=$((IDX + 1))
172done < "$TAIL_PLANS"
173
174"$ATTR" attribute "$MATRIX_TSV" "$WORK_DIR/stage3/attribution.tsv"
175"$ARCH" requeue "$WORK_DIR/stage3/attribution.tsv" "$WORK_DIR/stage3/requeue_q36.tsv"
176
177printf '\n=== [STAGE 5] DUAL-VIEW NUL-EOS EXTRACTION + FOUR-WALL BFT PROMOTION ===\n'
178printf 'return a*3+1' > "$WORK_DIR/stage5/orig.txt"
179printf 'PLAN: multiply scalar a by 3 and add 1; ASSERT(0->1) ASSERT(1->4) ASSERT(4->13)' > "$WORK_DIR/stage5/plan.txt"
180cat > "$WORK_DIR/stage5/code.om" <<'EOF'
181fn solve a ulong to ulong
182ret add mul a 3 1
183end
184EOF
185"$ATTR" extract \
186 "$WORK_DIR/stage5/orig.txt" \
187 "$WORK_DIR/stage5/plan.txt" \
188 "$WORK_DIR/stage5/code.om" \
189 "$WORK_DIR/stage5/direct_train.bin" \
190 "$WORK_DIR/stage5/align_train.bin"
191
192# Verify NUL (\x00) EOS byte at end of both Dual-View traces and Architect plan stripped from direct_train.bin
193! grep -q "ARCH_PLAN:" "$WORK_DIR/stage5/direct_train.bin" || { printf 'FAIL direct_train.bin leaked ARCH_PLAN\n' >&2; exit 1; }
194grep -q "ARCH_PLAN:" "$WORK_DIR/stage5/align_train.bin" || { printf 'FAIL align_train.bin missing ARCH_PLAN\n' >&2; exit 1; }
195
196# Four-Wall RSI + BFT Promotion checks:
197# - Strand 1 healthy candidate (80 traces >= 64, held 3061 -> 3180 <= +150, seen_delta=0, pass 6->8) -> PROMOTE (rc=0)
198"$ATTR" promote 1 80 "$MIN_FLOOR" 1 60 61 62 3061 3180 150 0 6 8 0 0
199# - Strand 4 P2-style tiny batch (16 < 64) -> SKIP_BELOW_BATCH_FLOOR (rc=10)
200rc=0; "$ATTR" promote 4 16 "$MIN_FLOOR" 1 60 61 62 3206 3250 150 0 6 6 0 0 || rc=$?
201[ "$rc" = "10" ] || { printf 'FAIL batch floor expected rc=10 got %s\n' "$rc" >&2; exit 1; }
202# - Strand 4 P2-style overfit (held 3206 -> 4829) -> REJECT_OVERFIT_KEEP_P1 (rc=12)
203rc=0; "$ATTR" promote 4 80 "$MIN_FLOOR" 1 60 61 62 3206 4829 150 0 6 6 0 0 || rc=$?
204[ "$rc" = "12" ] || { printf 'FAIL retention wall expected rc=12 got %s\n' "$rc" >&2; exit 1; }
205
206# Section 6 Post-Cycle Scaling Decision Rule
207"$ATTR" decide 8 12 6 3140 3128 35
208
209printf '\nARCHITECT_BUILDER_CYCLE PASS mode=%s tasks=%s spclip_4strand=PASS four_wall_bft=PASS\n' "$MODE" "$SWEEP_CNT"