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 / efi-receipts.sh

162 lines · 8286 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: AGPL-3.0-only
3# Receipts for the ollm UEFI rung (aien-train#52, CONTRACT section 9): build ollm.efi, compose the boot
4# image, boot it under QEMU/OVMF and compare its \OLLM\OUT.TXT and written files with a Linux build
5# running the same job, plus three controls. EMULATED evidence only: this is not the iMac.
6# Usage: EV=<new receipt dir> sh tests/omegallm/efi-receipts.sh
7# Env: IMAC_IMAGE (required; see efi-image.sh), EOMC (x86efi omc; build.sh's default when unset),
8# ABUILD (aarch64 reference build dir, default build), EBUILD (x86efi build dir, default
9# build-efi), DATA (TinyStoriesV2-GPT4-valid.txt, default data/...), CK (the v0 checkpoint,
10# default run/v0/ck-20000.bin), WORK (scratch, default scratch-efi), CORE (taskset core for the
11# reference and the main boot, default 6), MCORE (core for the mutant boot, run in parallel,
12# default CORE), EV (required: the receipt dir, new or empty; the script refuses a dir that
13# already holds files, so it can never delete committed receipts such as evidence/OMEGALLM/efi).
14# Runs from the clone's parent directory; give every path relative to it, so the receipts name no
15# absolute (private) path. Checks, each a line in summary.tsv (name, want, got, verdict):
16# main efi-job.txt: efi-check EQUAL and TR.BIN, HE.BIN, S.CK equal to the reference's files
17# mut-b the same job on ollm-mut-b.efi: the body differs from the reference at a byte (not only
18# a shorter run cut off by the deadline)
19# ckbad `eval` on a CK.BIN with one byte changed: OUT.TXT stops after the job line (no J, no
20# OLLM DONE) and its body equals the Linux build's stdout for the same file
21# job65535 a 65535-byte JOB.TXT (comment lines + adamck) runs: EQUAL with the Linux reference
22# job65536 a 65536-byte JOB.TXT is refused: the console shows `OLLM efi JOB.TXT?`, no OUT.TXT
23# Exits 1 if any check disagrees.
24set -u
25here=$(cd "$(dirname "$0")/../.." && pwd)
26cd "$here/.." || exit 70
27r=$(basename "$here")
28t=$r/tests/omegallm
29E=${EV:-}
30[ -n "$E" ] || { echo "EV must name a new or empty receipt dir" >&2; exit 2; }
31if [ -e "$E" ] && { [ ! -d "$E" ] || [ -n "$(ls -A "$E")" ]; }; then
32 echo "EV $E exists and is not an empty dir; refusing to overwrite receipts" >&2
33 exit 2
34fi
35[ -n "${IMAC_IMAGE:-}" ] && [ -x "$IMAC_IMAGE" ] || { echo "IMAC_IMAGE must name the imac-image tool" >&2; exit 2; }
36ABUILD=${ABUILD:-build}
37EBUILD=${EBUILD:-build-efi}
38DATA=${DATA:-data/TinyStoriesV2-GPT4-valid.txt}
39CK=${CK:-run/v0/ck-20000.bin}
40WORK=${WORK:-scratch-efi}
41CORE=${CORE:-6}
42MCORE=${MCORE:-$CORE}
43rm -rf "$WORK"
44mkdir -p "$WORK" "$E" || exit 70
45fail=0
46row() { # name want got
47 if [ "$2" = "$3" ]; then v=PASS; else v=FAIL; fail=1; fi
48 printf '%s\t%s\t%s\t%s\n' "$1" "$2" "$3" "$v" >> "$E/summary.tsv"
49}
50body() { grep -avEx 'OLLM efi [0-9]+|ID cpu=.* fw=.* fwrev=([0-9a-f]{8}|-) smbios=.*|J [0-9]+|OLLM DONE [0-9]+ [0-9]+' "$1"; }
51printf 'name\twant\tgot\tverdict\n' > "$E/summary.tsv"
52
53# 0. tools and builds (the reference is the aarch64 build; build.sh checks each omc against its pin)
54{
55 echo "qemu: $(qemu-system-x86_64 --version | head -n 1)"
56 echo "ovmf: $(sha256sum /usr/share/OVMF/OVMF_CODE_4M.fd | cut -d' ' -f1) OVMF_CODE_4M.fd ($(dpkg-query -W -f '${Package} ${Version}' ovmf 2> /dev/null))"
57 echo "mtools: $(mtools --version | head -n 1)"
58 echo "sgdisk: $(sgdisk --version | head -n 1)"
59 echo "imac-image: $(sha256sum "$IMAC_IMAGE" | cut -d' ' -f1)"
60 echo "core $CORE midr_el1 $(cat /sys/devices/system/cpu/cpu$CORE/regs/identification/midr_el1)"
61} > "$E/tools.txt"
62{
63 OMC= TARGET=aarch64 OUT=$here/../$ABUILD CORE=$CORE sh "$t/build.sh"
64 OMC=${EOMC:-} TARGET=x86efi OUT=$here/../$EBUILD CORE=$CORE sh "$t/build.sh"
65 OMC=${EOMC:-} TARGET=x86efi OUT=$here/../$EBUILD CORE=$CORE sh "$t/build.sh" --mutant b
66} > "$WORK/build.log" 2>&1 || { cat "$WORK/build.log" >&2; exit 1; }
67sed "s|$here/\.\./||g" "$WORK/build.log" > "$E/build.txt"
68sha256sum "$DATA" "$CK" "$t/mathref.txt" "$t/efi-job.txt" > "$E/inputs.txt"
69
70# 1. Linux reference for efi-job.txt
71mkdir "$WORK/ref"
72cp "$CK" "$WORK/ref/CK.BIN"
73cp "$DATA" "$WORK/ref/STORIES.TXT"
74cp "$t/mathref.txt" "$WORK/ref/MATHREF.TXT"
75CORE=$CORE sh "$t/efi-ref.sh" "$ABUILD/ollm" "$t/efi-job.txt" "$WORK/ref" > "$E/ref.out"
76(cd "$WORK/ref" && sha256sum TR.BIN HE.BIN S.CK) > "$E/ref-files.txt"
77jobs=$(tr -d '\r' < "$t/efi-job.txt" | grep -cvE '^(#|[[:blank:]]*$)')
78bytes=$(wc -c < "$t/efi-job.txt" | tr -d ' ')
79
80# 2. images
81img() { # efi img job [extra SRC:NAME...]
82 e=$1 i=$2 j=$3
83 shift 3
84 IMAC_IMAGE=$IMAC_IMAGE sh "$t/efi-image.sh" "$e" "$i" "$j:JOB.TXT" "$@"
85}
86img "$EBUILD/ollm.efi" "$WORK/ollm.img" "$t/efi-job.txt" "$CK:CK.BIN" "$DATA:STORIES.TXT" \
87 "$t/mathref.txt:MATHREF.TXT" > "$E/image.txt"
88img "$EBUILD/ollm-mut-b.efi" "$WORK/mutb.img" "$t/efi-job.txt" "$CK:CK.BIN" "$DATA:STORIES.TXT" \
89 "$t/mathref.txt:MATHREF.TXT" > "$E/image-mut-b.txt"
90
91# 3. main boot and mutant boot, in parallel
92boot() { # img name seconds core
93 mkdir -p "$E/$2"
94 CORES=$4 sh "$t/efi-qemu.sh" "$1" "$WORK/q-$2" "$3" > "$E/$2/qemu.txt" 2>&1
95 cp "$WORK/q-$2/serial.log" "$E/$2/serial.log"
96 [ ! -f "$WORK/q-$2/vol/OUT.TXT" ] || cp "$WORK/q-$2/vol/OUT.TXT" "$E/$2/OUT.TXT"
97}
98boot "$WORK/ollm.img" main 2700 "$CORE" &
99p1=$!
100boot "$WORK/mutb.img" mut-b 900 "$MCORE" &
101p2=$!
102wait "$p1"
103wait "$p2"
104sh "$t/efi-check.sh" "$E/main/OUT.TXT" "$E/ref.out" "$jobs" "$bytes" > "$E/main/check.txt" 2>&1
105row main EQUAL "$(tail -n 1 "$E/main/check.txt")"
106for f in TR.BIN HE.BIN S.CK; do
107 want=$(grep " $f\$" "$E/ref-files.txt" | cut -d' ' -f1)
108 got=$(sha256sum "$WORK/q-main/vol/$f" 2> /dev/null | cut -d' ' -f1 || true)
109 row "main-$f" "$want" "${got:-missing}"
110done
111body "$E/mut-b/OUT.TXT" > "$WORK/mutb.body" 2> /dev/null
112cmp "$WORK/mutb.body" "$E/ref.out" > "$E/mut-b/check.txt" 2>&1
113grep -q ' differ: ' "$E/mut-b/check.txt" && got=differs || got=same-or-prefix
114row mut-b differs "$got"
115
116# 4. controls (each boot ends in a refusal, so a short deadline)
117# ckbad: one byte of CK.BIN changed (0x00, or 0x01 where it already was 0x00)
118cp "$CK" "$WORK/ckbad.bin"
119printf '\000' | dd of="$WORK/ckbad.bin" bs=1 seek=200000 conv=notrunc 2> /dev/null
120cmp -s "$CK" "$WORK/ckbad.bin" && printf '\001' | dd of="$WORK/ckbad.bin" bs=1 seek=200000 conv=notrunc 2> /dev/null
121printf 'eval \\OLLM\\CK.BIN \\OLLM\\MATHREF.TXT 4\n' > "$WORK/ckbad-job.txt"
122mkdir "$WORK/ckbad"
123cp "$WORK/ckbad.bin" "$WORK/ckbad/CK.BIN"
124cp "$t/mathref.txt" "$WORK/ckbad/MATHREF.TXT"
125CORE=$CORE sh "$t/efi-ref.sh" "$ABUILD/ollm" "$WORK/ckbad-job.txt" "$WORK/ckbad" > "$WORK/ckbad.ref"
126img "$EBUILD/ollm.efi" "$WORK/ckbad.img" "$WORK/ckbad-job.txt" "$WORK/ckbad.bin:CK.BIN" \
127 "$t/mathref.txt:MATHREF.TXT" > /dev/null
128boot "$WORK/ckbad.img" ckbad 300 "$CORE"
129cp "$WORK/ckbad.ref" "$E/ckbad/ref.out"
130grep -v '^rc=' "$WORK/ckbad.ref" > "$WORK/ckbad.want"
131got=$(body "$E/ckbad/OUT.TXT" 2> /dev/null | cmp -s - "$WORK/ckbad.want" && echo body-equal || echo body-differs)
132grep -q '^rc=1[0-5]$' "$WORK/ckbad.ref" && got="$got,ref-refused" || got="$got,ref-ran"
133grep -aqE '^(J [0-9]+|OLLM DONE .*)$' "$E/ckbad/OUT.TXT" 2> /dev/null && got="$got,ran-on"
134row ckbad body-equal,ref-refused "$got"
135
136# job65535 / job65536: comment lines padding JOB.TXT to exactly that size, adamck last
137pad() { # size file
138 {
139 n=$(($1 - 7))
140 while [ "$n" -gt 64 ]; do printf '#%062d\n' 0; n=$((n - 64)); done
141 printf '#%0*d\n' $((n - 2)) 0
142 printf 'adamck\n'
143 } > "$2"
144 [ "$(wc -c < "$2")" = "$1" ] || { echo "pad $1 gave $(wc -c < "$2") bytes" >&2; exit 1; }
145}
146pad 65535 "$WORK/job65535.txt"
147pad 65536 "$WORK/job65536.txt"
148mkdir "$WORK/j"
149CORE=$CORE sh "$t/efi-ref.sh" "$ABUILD/ollm" "$WORK/job65535.txt" "$WORK/j" > "$WORK/job65535.ref"
150for s in 65535 65536; do
151 img "$EBUILD/ollm.efi" "$WORK/job$s.img" "$WORK/job$s.txt" > /dev/null
152done
153boot "$WORK/job65535.img" job65535 300 "$CORE"
154sh "$t/efi-check.sh" "$E/job65535/OUT.TXT" "$WORK/job65535.ref" 1 65535 > "$E/job65535/check.txt" 2>&1
155row job65535 EQUAL "$(tail -n 1 "$E/job65535/check.txt")"
156boot "$WORK/job65536.img" job65536 300 "$CORE"
157grep -aq 'OLLM efi JOB.TXT?' "$E/job65536/serial.log" && got=refused || got=no-message
158[ ! -f "$E/job65536/OUT.TXT" ] || got="$got,OUT.TXT"
159row job65536 refused "$got"
160
161cat "$E/summary.tsv"
162exit "$fail"