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

113 lines · 7547 bytes Raw Blame History
1#!/bin/sh
2# AArch64 UEFI receipts for ollm: build the a64efi image (ollm-aa64.efi), boot it as
3# \EFI\BOOT\BOOTAA64.EFI on a FAT disk under QEMU virt + EDK2 and compare its \OLLM\OUT.TXT and the
4# files it wrote with a Linux build's run of the same job (tests/omegallm/efi-job.txt). Mutant b
5# (OMUTB, a wrong gradient factor) must give a different body. A third boot runs the typed conversation
6# (`ask`, eio.om) with two lines typed on the console and requires each answer to equal what the Linux
7# build's `sample` prints for the same line and seed. On an AArch64 host with /dev/kvm the
8# CPU is the host's (KVM); elsewhere QEMU emulates one. Virtualized evidence, not hardware.
9# Usage: sh tests/omegallm/a64efi-receipts.sh (from the directory that holds the aien-train clone
10# as ./aien-train, with data/TinyStoriesV2-GPT4-valid.txt and run/v0/ck-20000.bin beside it)
11# Env: EV (output directory, default ev-a64efi), AOMC / EOMC (the aarch64 and a64efi compilers;
12# build.sh's defaults when unset), CORE (default 6), A64EFI_CODE (firmware, default
13# /usr/share/qemu-efi-aarch64/QEMU_EFI.fd), WAIT (seconds per boot, default 900).
14# Exit 0 only when every row of EV/summary.tsv has status ok.
15set -u
16here=$(pwd); t=$here/aien-train/tests/omegallm
17EV=${EV:-ev-a64efi}; CORE=${CORE:-6}; WAIT=${WAIT:-900}
18CODE=${A64EFI_CODE:-/usr/share/qemu-efi-aarch64/QEMU_EFI.fd}
19DATA=$here/data/TinyStoriesV2-GPT4-valid.txt; CK=$here/run/v0/ck-20000.bin
20for f in "$DATA" "$CK" "$CODE"; do [ -f "$f" ] || { echo "missing $f" >&2; exit 2; }; done
21for c in qemu-system-aarch64 mformat mcopy mmd timeout; do command -v $c > /dev/null 2>&1 || { echo "missing tool $c" >&2; exit 2; }; done
22E=$here/$EV; W=$here/scratch-a64efi; rm -rf "$E" "$W"; mkdir -p "$E" "$W/ref"
23accel="-cpu max"; [ "$(uname -m)" = aarch64 ] && [ -w /dev/kvm ] && accel="-cpu host -enable-kvm"
24{
25 echo "date $(date -u +%FT%TZ) machine $(uname -m) accel $accel"
26 echo "qemu: $(qemu-system-aarch64 --version | head -n 1)"
27 echo "firmware: $(sha256sum "$CODE" | cut -d' ' -f1) $(basename "$CODE")"
28 echo "aien-train: $(git -C "$here/aien-train" rev-parse HEAD) status $(git -C "$here/aien-train" status --porcelain | wc -l)"
29} > "$E/tools.txt"
30{
31 OMC=${AOMC:-} TARGET=aarch64 OUT=$W/ba CORE=$CORE sh "$t/build.sh"
32 OMC=${EOMC:-} TARGET=a64efi OUT=$W/be CORE=$CORE sh "$t/build.sh"
33 OMC=${EOMC:-} TARGET=a64efi OUT=$W/be CORE=$CORE sh "$t/build.sh" --mutant b
34} > "$W/build.log" 2>&1 || { cat "$W/build.log" >&2; exit 1; }
35sed "s|$here/||g" "$W/build.log" > "$E/build.txt"
36sha256sum "$DATA" "$CK" "$t/mathref.txt" "$t/efi-job.txt" | sed "s|$here/||" > "$E/inputs.txt"
37cp "$CK" "$W/ref/CK.BIN"; cp "$DATA" "$W/ref/STORIES.TXT"; cp "$t/mathref.txt" "$W/ref/MATHREF.TXT"
38CORE=$CORE sh "$t/efi-ref.sh" "$W/ba/ollm" "$t/efi-job.txt" "$W/ref" > "$E/ref.out"
39(cd "$W/ref" && sha256sum TR.BIN HE.BIN S.CK) > "$E/ref-files.txt"
40jobs=$(tr -d '\r' < "$t/efi-job.txt" | grep -cvE '^(#|[[:blank:]]*$)')
41bytes=$(wc -c < "$t/efi-job.txt" | tr -d ' ')
42
43# boot NAME EFI: a fresh 160 MiB FAT disk with the image, the job and its inputs; REBOOT.TXT makes
44# the image restart the machine when it is done, which ends QEMU (-no-reboot).
45boot() {
46 d=$W/$1; mkdir -p "$d" "$E/$1"
47 dd if=/dev/zero of="$d/disk.img" bs=1048576 count=160 2> /dev/null
48 mformat -i "$d/disk.img" -F -v ALLEN :: && mmd -i "$d/disk.img" ::/EFI ::/EFI/BOOT ::/OLLM
49 mcopy -i "$d/disk.img" "$2" ::/EFI/BOOT/BOOTAA64.EFI
50 mcopy -i "$d/disk.img" "$t/efi-job.txt" ::/OLLM/JOB.TXT
51 mcopy -i "$d/disk.img" "$CK" ::/OLLM/CK.BIN
52 mcopy -i "$d/disk.img" "$DATA" ::/OLLM/STORIES.TXT
53 mcopy -i "$d/disk.img" "$t/mathref.txt" ::/OLLM/MATHREF.TXT
54 printf 'restart when done\n' > "$d/REBOOT.TXT"; mcopy -i "$d/disk.img" "$d/REBOOT.TXT" ::/OLLM/REBOOT.TXT
55 t0=$(date +%s)
56 # a key on the console after 20 s ends the image's 300 s wait; the job itself is done by then or the
57 # key is read when it finishes
58 # shellcheck disable=SC2086
59 (sleep 20; printf 'k') | timeout -k 5 "$WAIT" taskset -c "$CORE" nice -n 19 qemu-system-aarch64 -M virt $accel -m 3072 -smp 1 \
60 -display none -no-reboot -bios "$CODE" -drive if=none,id=d0,format=raw,file="$d/disk.img" \
61 -device virtio-blk-device,drive=d0 -net none -serial stdio -monitor none > "$E/$1/serial.log" 2>&1
62 echo "qemu exit $? after $(( $(date +%s) - t0 )) s" > "$E/$1/qemu.txt"
63 for f in OUT.TXT TR.BIN HE.BIN S.CK; do mcopy -n -i "$d/disk.img" "::/OLLM/$f" "$d/$f" 2> /dev/null; done
64 [ ! -f "$d/OUT.TXT" ] || cp "$d/OUT.TXT" "$E/$1/OUT.TXT"
65 fsck.vfat -n "$d/disk.img" > "$d/fsck.txt" 2>&1; r=$?
66 sed "s|$here/||g" "$d/fsck.txt" > "$E/$1/fsck.txt"; echo "fsck exit $r" >> "$E/$1/fsck.txt"
67}
68printf 'check\twant\tgot\tstatus\n' > "$E/summary.tsv"
69row() { [ "$2" = "$3" ] && s=ok || s=FAIL; printf '%s\t%s\t%s\t%s\n' "$1" "$2" "$3" "$s" >> "$E/summary.tsv"; }
70boot main "$W/be/ollm-aa64.efi"
71boot mut-b "$W/be/ollm-mut-b-aa64.efi"
72sh "$t/efi-check.sh" "$E/main/OUT.TXT" "$E/ref.out" "$jobs" "$bytes" > "$E/main/check.txt" 2>&1
73row main EQUAL "$(tail -n 1 "$E/main/check.txt")"
74for f in TR.BIN HE.BIN S.CK; do
75 want=$(grep " $f\$" "$E/ref-files.txt" | cut -d' ' -f1)
76 got=$(sha256sum "$W/main/$f" 2> /dev/null | cut -d' ' -f1)
77 row "main-$f" "$want" "${got:-missing}"
78done
79row main-fsck "fsck exit 0" "$(tail -n 1 "$E/main/fsck.txt")"
80sh "$t/efi-check.sh" "$E/mut-b/OUT.TXT" "$E/ref.out" "$jobs" "$bytes" > "$E/mut-b/check.txt" 2>&1
81[ "$(tail -n 1 "$E/mut-b/check.txt")" = EQUAL ] && got=same || got=differs
82row mut-b differs "$got"
83
84# ask: `ask \\OLLM\\CK.BIN 7 60 700`, then the keys: a line with a mistyped character removed by Backspace,
85# a second line, and an empty line that ends the conversation. Turn t uses seed 7 + t.
86d=$W/ask; mkdir -p "$d" "$E/ask"
87dd if=/dev/zero of="$d/disk.img" bs=1048576 count=64 2> /dev/null
88mformat -i "$d/disk.img" -F -v ALLEN :: && mmd -i "$d/disk.img" ::/EFI ::/EFI/BOOT ::/OLLM
89mcopy -i "$d/disk.img" "$W/be/ollm-aa64.efi" ::/EFI/BOOT/BOOTAA64.EFI
90printf 'ask \\OLLM\\CK.BIN 7 60 700\n' > "$d/JOB.TXT"; mcopy -i "$d/disk.img" "$d/JOB.TXT" ::/OLLM/JOB.TXT
91mcopy -i "$d/disk.img" "$CK" ::/OLLM/CK.BIN
92printf 'restart when done\n' > "$d/REBOOT.TXT"; mcopy -i "$d/disk.img" "$d/REBOOT.TXT" ::/OLLM/REBOOT.TXT
93# shellcheck disable=SC2086
94(sleep 12; printf 'Once upon a tix\010me\r'; sleep 12; printf 'The dog\r'; sleep 12; printf '\r'; sleep 4; printf 'k') |
95 timeout -k 5 "$WAIT" taskset -c "$CORE" nice -n 19 qemu-system-aarch64 -M virt $accel -m 3072 -smp 1 \
96 -display none -no-reboot -bios "$CODE" -drive if=none,id=d0,format=raw,file="$d/disk.img" \
97 -device virtio-blk-device,drive=d0 -net none -serial stdio -monitor none > "$E/ask/serial.log" 2>&1
98mcopy -n -i "$d/disk.img" ::/OLLM/OUT.TXT "$d/OUT.TXT" 2> /dev/null && cp "$d/OUT.TXT" "$E/ask/OUT.TXT"
99# want LINE SEED: the typed line and the Linux build's answer, with a line feed added only when the
100# answer does not end in one (the image's rule, eio.om oask)
101want() {
102 printf 'You: %s\n' "$1"
103 taskset -c "$CORE" "$W/ba/ollm" sample "$CK" "$2" 60 700 "$1" > "$d/ans"
104 cat "$d/ans"
105 # no line feed after an empty answer either: the typed line already ended in one (eio.om olc)
106 [ ! -s "$d/ans" ] || [ "$(tail -c 1 "$d/ans" | od -An -tu1 | tr -d ' ')" = 10 ] || echo
107}
108{ want 'Once upon a time' 7; want 'The dog' 8; } > "$E/ask/want.txt"
109tr -d '\r' < "$E/ask/OUT.TXT" 2> /dev/null | sed -n '/^You: /,/^J /p' | grep -v '^J ' > "$E/ask/got.txt"
110cmp -s "$E/ask/got.txt" "$E/ask/want.txt" && got=equal || got=differs
111row ask equal "$got"
112cat "$E/summary.tsv"
113! grep -q 'FAIL$' "$E/summary.tsv"