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
aien-train / tests / omegallm / efi-receipts.sh
| 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. |
| 24 | set -u |
| 25 | here=$(cd "$(dirname "$0")/../.." && pwd) |
| 26 | cd "$here/.." || exit 70 |
| 27 | r=$(basename "$here") |
| 28 | t=$r/tests/omegallm |
| 29 | E=${EV:-} |
| 30 | [ -n "$E" ] || { echo "EV must name a new or empty receipt dir" >&2; exit 2; } |
| 31 | if [ -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 |
| 34 | fi |
| 35 | [ -n "${IMAC_IMAGE:-}" ] && [ -x "$IMAC_IMAGE" ] || { echo "IMAC_IMAGE must name the imac-image tool" >&2; exit 2; } |
| 36 | ABUILD=${ABUILD:-build} |
| 37 | EBUILD=${EBUILD:-build-efi} |
| 38 | DATA=${DATA:-data/TinyStoriesV2-GPT4-valid.txt} |
| 39 | CK=${CK:-run/v0/ck-20000.bin} |
| 40 | WORK=${WORK:-scratch-efi} |
| 41 | CORE=${CORE:-6} |
| 42 | MCORE=${MCORE:-$CORE} |
| 43 | rm -rf "$WORK" |
| 44 | mkdir -p "$WORK" "$E" || exit 70 |
| 45 | fail=0 |
| 46 | row() { # 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 | } |
| 50 | body() { 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"; } |
| 51 | printf '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; } |
| 67 | sed "s|$here/\.\./||g" "$WORK/build.log" > "$E/build.txt" |
| 68 | sha256sum "$DATA" "$CK" "$t/mathref.txt" "$t/efi-job.txt" > "$E/inputs.txt" |
| 69 | |
| 70 | # 1. Linux reference for efi-job.txt |
| 71 | mkdir "$WORK/ref" |
| 72 | cp "$CK" "$WORK/ref/CK.BIN" |
| 73 | cp "$DATA" "$WORK/ref/STORIES.TXT" |
| 74 | cp "$t/mathref.txt" "$WORK/ref/MATHREF.TXT" |
| 75 | CORE=$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" |
| 77 | jobs=$(tr -d '\r' < "$t/efi-job.txt" | grep -cvE '^(#|[[:blank:]]*$)') |
| 78 | bytes=$(wc -c < "$t/efi-job.txt" | tr -d ' ') |
| 79 | |
| 80 | # 2. images |
| 81 | img() { # 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 | } |
| 86 | img "$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" |
| 88 | img "$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 |
| 92 | boot() { # 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 | } |
| 98 | boot "$WORK/ollm.img" main 2700 "$CORE" & |
| 99 | p1=$! |
| 100 | boot "$WORK/mutb.img" mut-b 900 "$MCORE" & |
| 101 | p2=$! |
| 102 | wait "$p1" |
| 103 | wait "$p2" |
| 104 | sh "$t/efi-check.sh" "$E/main/OUT.TXT" "$E/ref.out" "$jobs" "$bytes" > "$E/main/check.txt" 2>&1 |
| 105 | row main EQUAL "$(tail -n 1 "$E/main/check.txt")" |
| 106 | for 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}" |
| 110 | done |
| 111 | body "$E/mut-b/OUT.TXT" > "$WORK/mutb.body" 2> /dev/null |
| 112 | cmp "$WORK/mutb.body" "$E/ref.out" > "$E/mut-b/check.txt" 2>&1 |
| 113 | grep -q ' differ: ' "$E/mut-b/check.txt" && got=differs || got=same-or-prefix |
| 114 | row 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) |
| 118 | cp "$CK" "$WORK/ckbad.bin" |
| 119 | printf '\000' | dd of="$WORK/ckbad.bin" bs=1 seek=200000 conv=notrunc 2> /dev/null |
| 120 | cmp -s "$CK" "$WORK/ckbad.bin" && printf '\001' | dd of="$WORK/ckbad.bin" bs=1 seek=200000 conv=notrunc 2> /dev/null |
| 121 | printf 'eval \\OLLM\\CK.BIN \\OLLM\\MATHREF.TXT 4\n' > "$WORK/ckbad-job.txt" |
| 122 | mkdir "$WORK/ckbad" |
| 123 | cp "$WORK/ckbad.bin" "$WORK/ckbad/CK.BIN" |
| 124 | cp "$t/mathref.txt" "$WORK/ckbad/MATHREF.TXT" |
| 125 | CORE=$CORE sh "$t/efi-ref.sh" "$ABUILD/ollm" "$WORK/ckbad-job.txt" "$WORK/ckbad" > "$WORK/ckbad.ref" |
| 126 | img "$EBUILD/ollm.efi" "$WORK/ckbad.img" "$WORK/ckbad-job.txt" "$WORK/ckbad.bin:CK.BIN" \ |
| 127 | "$t/mathref.txt:MATHREF.TXT" > /dev/null |
| 128 | boot "$WORK/ckbad.img" ckbad 300 "$CORE" |
| 129 | cp "$WORK/ckbad.ref" "$E/ckbad/ref.out" |
| 130 | grep -v '^rc=' "$WORK/ckbad.ref" > "$WORK/ckbad.want" |
| 131 | got=$(body "$E/ckbad/OUT.TXT" 2> /dev/null | cmp -s - "$WORK/ckbad.want" && echo body-equal || echo body-differs) |
| 132 | grep -q '^rc=1[0-5]$' "$WORK/ckbad.ref" && got="$got,ref-refused" || got="$got,ref-ran" |
| 133 | grep -aqE '^(J [0-9]+|OLLM DONE .*)$' "$E/ckbad/OUT.TXT" 2> /dev/null && got="$got,ran-on" |
| 134 | row ckbad body-equal,ref-refused "$got" |
| 135 | |
| 136 | # job65535 / job65536: comment lines padding JOB.TXT to exactly that size, adamck last |
| 137 | pad() { # 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 | } |
| 146 | pad 65535 "$WORK/job65535.txt" |
| 147 | pad 65536 "$WORK/job65536.txt" |
| 148 | mkdir "$WORK/j" |
| 149 | CORE=$CORE sh "$t/efi-ref.sh" "$ABUILD/ollm" "$WORK/job65535.txt" "$WORK/j" > "$WORK/job65535.ref" |
| 150 | for s in 65535 65536; do |
| 151 | img "$EBUILD/ollm.efi" "$WORK/job$s.img" "$WORK/job$s.txt" > /dev/null |
| 152 | done |
| 153 | boot "$WORK/job65535.img" job65535 300 "$CORE" |
| 154 | sh "$t/efi-check.sh" "$E/job65535/OUT.TXT" "$WORK/job65535.ref" 1 65535 > "$E/job65535/check.txt" 2>&1 |
| 155 | row job65535 EQUAL "$(tail -n 1 "$E/job65535/check.txt")" |
| 156 | boot "$WORK/job65536.img" job65536 300 "$CORE" |
| 157 | grep -aq 'OLLM efi JOB.TXT?' "$E/job65536/serial.log" && got=refused || got=no-message |
| 158 | [ ! -f "$E/job65536/OUT.TXT" ] || got="$got,OUT.TXT" |
| 159 | row job65536 refused "$got" |
| 160 | |
| 161 | cat "$E/summary.tsv" |
| 162 | exit "$fail" |