interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / tests / omegallm / core-receipts.sh

217 lines · 10310 bytes Raw Blame History
1#!/bin/sh
2# Produce the .om lane receipts for aien-train#52 under evidence/OMEGALLM/core/.
3# Usage: sh tests/omegallm/core-receipts.sh
4# Env: BUILD (output dir for ollm, ollm-mut-a|b|c, ollm-var-h5|h7 and their .om; default build beside
5# this clone), DATA (TinyStoriesV2-GPT4-valid.txt; default data/ beside it), WORK (scratch for
6# checkpoints), CORE (taskset core, default 6). Derived .bin files go beside DATA and are never
7# committed.
8# TARGET (aarch64, the default, or x86linux; passed to build.sh) and EV (receipt directory,
9# default evidence/OMEGALLM/core in this clone). An x86linux run executes the x86-64 ELFs through
10# the host's qemu-x86_64 binfmt handler; each receipt then names the emulator (EMULATED, not a
11# physical x86 run). The pinned value lines are the same for both targets.
12# The script runs from the clone's parent directory and every path is relative to it, so the
13# committed receipts name no absolute (private) paths. Give BUILD/DATA/WORK relative to that parent.
14# Step 0 builds every binary from this tree with tests/omegallm/build.sh, so the receipts always
15# describe the committed source. Each receipt holds the exact command, stdout+stderr, exit code, wall
16# time, and the sha256 of the binary and of its concatenated source. Exit codes are checked for every
17# command; the deterministic value lines the oracle also checks (P, B, I, T 50, E) are pinned with
18# `want`. The script exits 1 if any check disagrees with its expectation.
19set -u
20here=$(cd "$(dirname "$0")/../.." && pwd)
21cd "$here/.." || exit 70
22r=$(basename "$here")
23BUILD=${BUILD:-build}
24DATA=${DATA:-data/TinyStoriesV2-GPT4-valid.txt}
25WORK=${WORK:-scratch-core/work}
26CORE=${CORE:-6}
27TARGET=${TARGET:-aarch64}
28E=${EV:-$r/evidence/OMEGALLM/core}
29EMUL=
30if [ "$TARGET" = x86linux ]; then
31 EMUL="x86linux EMULATED: $(qemu-x86_64 --version | head -n 1), binfmt $(sed -n 's/^flags: /flags /p' /proc/sys/fs/binfmt_misc/qemu-x86_64)"
32fi
33DD=$(dirname "$DATA")
34TR=$DD/train.bin
35HE=$DD/held.bin
36RUN="taskset -c $CORE nice -n 19"
37mkdir -p "$E" "$WORK"
38
39# 0. build from this tree (build.sh refuses an omc that is not the pinned one)
40: > "$E/build.txt"
41for a in "" "--mutant a" "--mutant b" "--mutant c" "--variant h5" "--variant h7"; do
42 # shellcheck disable=SC2086
43 OUT=$BUILD CORE=$CORE TARGET=$TARGET sh "$r/tests/omegallm/build.sh" $a >> "$E/build.txt" 2>&1 || {
44 echo "BUILD_FAIL $a" | tee -a "$E/build.txt"
45 exit 1
46 }
47done
48cat "$E/build.txt"
49fail=0
50SUM=$E/summary.tsv
51printf 'receipt\trc\texpect\tverdict\n' > "$SUM"
52
53# rec NAME EXPECT_RC BIN ARGS... : run one command and write $E/NAME.txt
54rec() {
55 name=$1 want=$2 bin=$3
56 shift 3
57 f=$E/$name.txt
58 {
59 echo "receipt: $name"
60 echo "host_cpu: core $CORE ($(lscpu -e=CPU,MODELNAME 2>/dev/null | awk -v c="$CORE" '$1==c {$1=""; print substr($0,2)}'))"
61 [ -z "$EMUL" ] || echo "target: $EMUL"
62 echo "binary: $bin sha256 $(sha256sum "$BUILD/$bin" | cut -d' ' -f1)"
63 echo "source: $bin.om sha256 $(sha256sum "$BUILD/$bin.om" | cut -d' ' -f1)"
64 echo "\$ $RUN $BUILD/$bin $*"
65 echo "--- output"
66 } > "$f"
67 t0=$(date +%s%N)
68 $RUN "$BUILD/$bin" "$@" >> "$f" 2>&1
69 rc=$?
70 t1=$(date +%s%N)
71 {
72 echo "--- end"
73 echo "rc=$rc expect=$want"
74 echo "wall_ns=$((t1 - t0))"
75 } >> "$f"
76 v=PASS
77 [ "$rc" = "$want" ] || { v=FAIL; fail=1; }
78 printf '%s\t%s\t%s\t%s\n' "$name" "$rc" "$want" "$v" >> "$SUM"
79 echo "$name rc=$rc expect=$want $v"
80}
81
82# want NAME LINE : the receipt NAME.txt must contain LINE exactly (a pinned deterministic value)
83want() {
84 v=PASS
85 grep -qxF "$2" "$E/$1.txt" || { v=FAIL; fail=1; }
86 printf '%s\t%s\t%s\t%s\n' "$1:value" "-" "$2" "$v" >> "$SUM"
87 echo "$1 value '$2' $v"
88}
89
90sha256sum "$DATA" > "$E/data-sha256.txt"
91# the core's identification register (0x410fd851: Arm, part 0xd85 Cortex-X925) and its maximum clock
92{
93 echo "core $CORE midr_el1 $(cat /sys/devices/system/cpu/cpu$CORE/regs/identification/midr_el1)"
94 echo "core $CORE cpuinfo_max_freq_khz $(cat /sys/devices/system/cpu/cpu$CORE/cpufreq/cpuinfo_max_freq)"
95 lscpu -e=CPU,MODELNAME,MAXMHZ 2>/dev/null | awk -v c="$CORE" 'NR==1 || $1==c'
96 [ -z "$EMUL" ] || echo "target: $EMUL"
97} > "$E/host.txt"
98
99# 1. prep on the real data, then the derived file hashes
100rec prep 0 ollm prep "$DATA" "$TR" "$HE"
101sha256sum "$TR" "$HE" >> "$E/prep.txt"
102want prep "P 27630 24867 2763 19883834 2220914"
103
104# 2. baselines
105rec base 0 ollm base "$TR" "$HE"
106want base "B 4415645 3295113"
107
108# 3. v0 init + 50 train steps (shapes of CONTRACT section 1)
109rm -f "$WORK/v0.ck"
110rec init-v0 0 ollm init "$WORK/v0.ck" 256 64 64 4 256 2 16 52 20000 3000
111want init-v0 "I 119104"
112rec train-v0-50 0 ollm train "$WORK/v0.ck" "$TR" 50 5
113want train-v0-50 "T 50 3110411"
114
115# 4. resume equality: 0->40 straight vs 0->20 then ->40, compared with cmp
116rm -f "$WORK/ra.ck" "$WORK/rb.ck"
117rec resume-init-a 0 ollm init "$WORK/ra.ck" 256 64 64 4 256 2 16 52 20000 3000
118rec resume-init-b 0 ollm init "$WORK/rb.ck" 256 64 64 4 256 2 16 52 20000 3000
119rec resume-a-0-40 0 ollm train "$WORK/ra.ck" "$TR" 40 40
120rec resume-b-0-20 0 ollm train "$WORK/rb.ck" "$TR" 20 20
121rec resume-b-20-40 0 ollm train "$WORK/rb.ck" "$TR" 40 20
122{
123 echo "\$ cmp $WORK/ra.ck $WORK/rb.ck"
124 cmp "$WORK/ra.ck" "$WORK/rb.ck"
125 c=$?
126 echo "rc=$c expect=0"
127 sha256sum "$WORK/ra.ck" "$WORK/rb.ck"
128} > "$E/resume-cmp.txt" 2>&1
129grep -q '^rc=0 ' "$E/resume-cmp.txt" && v=PASS || { v=FAIL; fail=1; }
130printf 'resume-cmp\t%s\t0\t%s\n' "$(sed -n 's/^rc=\([0-9]*\) .*/\1/p' "$E/resume-cmp.txt")" "$v" >> "$SUM"
131
132# 5. checkpoint refusals (exit codes of CONTRACT section 7)
133cp "$WORK/ra.ck" "$WORK/flip.ck"
134printf '\377' | dd of="$WORK/flip.ck" bs=1 seek=5000 conv=notrunc 2>/dev/null
135cmp -l "$WORK/ra.ck" "$WORK/flip.ck" > "$E/refuse-flip-diff.txt" 2>&1
136rec refuse-flip-payload 14 ollm eval "$WORK/flip.ck" "$HE" 4
137cp "$WORK/ra.ck" "$WORK/magic.ck"
138printf 'X' | dd of="$WORK/magic.ck" bs=1 seek=0 conv=notrunc 2>/dev/null
139rec refuse-flip-magic 11 ollm eval "$WORK/magic.ck" "$HE" 4
140head -c $(($(stat -c %s "$WORK/ra.ck") - 1)) "$WORK/ra.ck" > "$WORK/trunc.ck"
141rec refuse-truncated 10 ollm eval "$WORK/trunc.ck" "$HE" 4
142# D (header offset 24, low byte 0x40) set to 0: a zero shape
143cp "$WORK/ra.ck" "$WORK/shape.ck"
144printf '\000' | dd of="$WORK/shape.ck" bs=1 seek=24 conv=notrunc 2>/dev/null
145rec refuse-shape 12 ollm eval "$WORK/shape.ck" "$HE" 4
146# P (header offset 96, 119104 = 0x1D140, low byte 0x40) set to 0x41: P disagrees with the shapes
147cp "$WORK/ra.ck" "$WORK/count.ck"
148printf '\101' | dd of="$WORK/count.ck" bs=1 seek=96 conv=notrunc 2>/dev/null
149rec refuse-count 13 ollm eval "$WORK/count.ck" "$HE" 4
150# one byte appended: longer than 112 + 24 P
151cp "$WORK/ra.ck" "$WORK/long.ck"
152printf '\000' >> "$WORK/long.ck"
153rec refuse-long 15 ollm eval "$WORK/long.ck" "$HE" 4
154
155# 5b. the largest shape (CONTRACT section 1 maxima) round-trips: file 112 + 24 P_max bytes
156rm -f "$WORK/max.ck"
157rec init-max 0 ollm init "$WORK/max.ck" 256 64 64 8 256 4 16 1 100 3000
158want init-max "I 217664"
159stat -c '%s %n' "$WORK/max.ck" >> "$E/init-max.txt"
160rec eval-max 0 ollm eval "$WORK/max.ck" "$HE" 2
161
162# 5c. data-range refusals that a wrapping u64 sum would let through: W = 2^58 windows (W T wraps to
163# 0 at T 64) and 16 offsets of 2^64 - 1 (o + T wraps)
164rec refuse-eval-hugew 23 ollm eval "$WORK/ra.ck" "$HE" 288230376151711744
165head -c 128 /dev/zero | tr '\000' '\377' > "$WORK/offs-huge.bin"
166rec refuse-grad-hugeoff 22 ollm grad "$WORK/ra.ck" "$TR" "$WORK/offs-huge.bin" "$WORK/huge.gr"
167
168# 5d. the exact boundaries of the same two checks, on 193-byte slices (T = 64):
169# eval accepts W = floor((193 - 1) / 64) = 3 and refuses W = 4 with 23;
170# grad accepts o = 193 - 64 - 1 = 128 (window o..o+T ends on the last byte) and refuses 129 with
171# 22. The refusing offset file holds fifteen offsets 128 and one 129, so the last row decides.
172head -c 193 "$HE" > "$WORK/held-193.bin"
173head -c 193 "$TR" > "$WORK/train-193.bin"
174rec eval-edge-w3 0 ollm eval "$WORK/ra.ck" "$WORK/held-193.bin" 3
175rec refuse-eval-edge-w4 23 ollm eval "$WORK/ra.ck" "$WORK/held-193.bin" 4
176: > "$WORK/offs-128.bin"
177for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do printf '\200\0\0\0\0\0\0\0' >> "$WORK/offs-128.bin"; done
178head -c 120 "$WORK/offs-128.bin" > "$WORK/offs-129.bin"
179printf '\201\0\0\0\0\0\0\0' >> "$WORK/offs-129.bin"
180rec grad-edge-o128 0 ollm grad "$WORK/ra.ck" "$WORK/train-193.bin" "$WORK/offs-128.bin" "$WORK/e128.gr"
181rec refuse-grad-edge-o129 22 ollm grad "$WORK/ra.ck" "$WORK/train-193.bin" "$WORK/offs-129.bin" "$WORK/e129.gr"
182
183# 6. eval and sample on the 50-step v0 checkpoint
184rec eval-v0 0 ollm eval "$WORK/v0.ck" "$HE" 256
185want eval-v0 "E 50 256 3049318 4399237"
186rec sample-v0-argmax 0 ollm sample "$WORK/v0.ck" 7 200 0 "Once upon a time"
187rec sample-v0-t800 0 ollm sample "$WORK/v0.ck" 7 200 800 "Once upon a time"
188
189# 7. self-checks: gradient check (small shape, fresh v0 init with seed 1, 50-step v0 checkpoint),
190# Adam check, exp/log check
191rm -f "$WORK/s.ck"
192rec init-small 0 ollm init "$WORK/s.ck" 256 8 16 2 32 2 2 52 200 1000
193rec gcheck 0 ollm gcheck "$WORK/s.ck" "$TR"
194rm -f "$WORK/g0.ck"
195rec init-v0-g0 0 ollm init "$WORK/g0.ck" 256 64 64 4 256 2 16 1 20000 3000
196rec gcheck-v0-init 0 ollm gcheck "$WORK/g0.ck" "$TR"
197rec gcheck-v0-step50 0 ollm gcheck "$WORK/v0.ck" "$TR"
198rec adamck 0 ollm adamck
199rec mathck 0 ollm mathck "$r/tests/omegallm/mathref.txt"
200
201# 8. mutants: a (dK sign) must fail gcheck; c (no bias correction) must fail adamck;
202# b (targets shifted) passes self-checks by construction and is killed by the oracle (xgrad).
203rec mut-a-gcheck 40 ollm-mut-a gcheck "$WORK/s.ck" "$TR"
204rec mut-a-gcheck-v0 40 ollm-mut-a gcheck "$WORK/g0.ck" "$TR"
205rec mut-c-adamck 41 ollm-mut-c adamck
206rec mut-b-gcheck 0 ollm-mut-b gcheck "$WORK/s.ck" "$TR"
207
208# 9. gcheck step-size variants (README, "Self-check constants"): with the correct gradient, h = 1e-5
209# (ReLU kinks) and h = 1e-7 (roundoff) both exceed GCTOL at v0, which is why GCH is 1e-6 with
210# the 2.5e-7 retry. Each `c index g_e12 num_e12` line gives the hand gradient and the difference.
211rec var-h5-gcheck-v0-init 40 ollm-var-h5 gcheck "$WORK/g0.ck" "$TR"
212rec var-h5-gcheck-v0-step50 40 ollm-var-h5 gcheck "$WORK/v0.ck" "$TR"
213rec var-h7-gcheck-v0-init 40 ollm-var-h7 gcheck "$WORK/g0.ck" "$TR"
214rec var-h7-gcheck-v0-step50 40 ollm-var-h7 gcheck "$WORK/v0.ck" "$TR"
215
216echo "summary: $SUM"
217exit $fail