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 / tune-check.sh

60 lines · 4163 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: AGPL-3.0-only
3# Checks for `ollm tune` (fine-tune entry, cli.om). Host CPU only.
4# Usage: OLLM=path/to/ollm OMC=path/to/pinned/omc sh tests/omegallm/tune-check.sh (build with tests/omegallm/build.sh)
5# Data: the repository LICENSE as V 256 byte data (public, fixed bytes). Scratch in a temp dir.
6# Prints one line per check and TUNE_PASS, or TUNE_FAIL and exit 1.
7set -u
8ROOT=$(cd "$(dirname "$0")/../.." && pwd)
9OLLM=${OLLM:?set OLLM to the built ollm}
10OMC=${OMC:?set OMC to the pinned omc (builds the negative control)}
11W=$(mktemp -d "${TMPDIR:-/tmp}/tune.XXXXXX")
12D=$ROOT/LICENSE
13bad=0
14ok() { echo "PASS $*"; }
15no() { echo "FAIL $*"; bad=1; }
16want() { [ "$2" = "$3" ] && ok "$1: $2" || no "$1: got [$2] want [$3]"; }
17echo "ollm_sha256=$(sha256sum "$OLLM" | cut -d" " -f1)"
18echo "data_sha256=$(sha256sum "$D" | cut -d" " -f1)"
19"$OLLM" init "$W/a.ck" 256 64 64 4 256 2 16 1 30 1000 > "$W/i.txt"; want init "$(cat "$W/i.txt")" "I 119104"
20"$OLLM" train "$W/a.ck" "$D" 30 10 > "$W/t.txt"; want "train base 0..30 rc" $? 0
21cp "$W/a.ck" "$W/b.ck"
22"$OLLM" train "$W/b.ck" "$D" 40 10 > "$W/t2.txt"; want "train past TOTAL makes no step (why tune exists)" "$(wc -c < "$W/t2.txt" | tr -d " ")" 0
23cmp -s "$W/a.ck" "$W/b.ck"; want "checkpoint unchanged past TOTAL" $? 0
24"$OLLM" tune "$W/a.ck" "$W/u.ck" 20 500 > "$W/u.txt"; want tune "$(cat "$W/u.txt")" "U 119104"
25e1=$("$OLLM" eval "$W/a.ck" "$D" 4 | cut -d" " -f3-)
26e2=$("$OLLM" eval "$W/u.ck" "$D" 4 | cut -d" " -f3-)
27want "weights kept (eval loss and bpb equal)" "$e2" "$e1"
28s2=$("$OLLM" eval "$W/u.ck" "$D" 4 | cut -d" " -f2); want "step reset" "$s2" 0
29P=119104; H=112
30z=$(tail -c +$((H + 8 * P + 1)) "$W/u.ck" | head -c $((16 * P)) | tr -d "\000" | wc -c | tr -d " ")
31want "Adam m and v zeroed" "$z" 0
32z0=$(tail -c +$((H + 8 * P + 1)) "$W/a.ck" | head -c $((16 * P)) | tr -d "\000" | wc -c | tr -d " ")
33[ "$z0" -gt 0 ] && ok "control: base checkpoint moments nonzero ($z0 bytes)" || no "control: base moments zero"
34cp "$W/u.ck" "$W/u1.ck"; cp "$W/u.ck" "$W/u2.ck"
35"$OLLM" train "$W/u1.ck" "$D" 20 10 > "$W/f.txt"; want "fine-tune 0..20 rc" $? 0
36want "fine-tune saves" "$(cut -d" " -f1-2 "$W/f.txt" | tr "\n" ,)" "T 10,T 20,"
37"$OLLM" train "$W/u2.ck" "$D" 10 10 > /dev/null; "$OLLM" train "$W/u2.ck" "$D" 20 10 > /dev/null
38cmp -s "$W/u1.ck" "$W/u2.ck"; want "fine-tune resume 0..10..20 bit-identical to 0..20" $? 0
39cmp -s "$W/u1.ck" "$W/u.ck"; [ $? -ne 0 ] && ok "fine-tune changed the weights" || no "fine-tune changed nothing"
40l0=$("$OLLM" eval "$W/u.ck" "$D" 4 | cut -d" " -f4); l1=$("$OLLM" eval "$W/u1.ck" "$D" 4 | cut -d" " -f4)
41[ "$l1" -lt "$l0" ] && ok "fine-tune lowered eval loss (micro-nats $l0 to $l1)" || no "fine-tune loss $l0 to $l1"
42"$OLLM" tune "$W/a.ck" "$W/v.ck" 20 500 > /dev/null; cmp -s "$W/u.ck" "$W/v.ck"; want "tune deterministic" $? 0
43"$OLLM" tune "$W/a.ck" "$W/x.ck" 0 500 > /dev/null 2>&1; want "TOTAL 0 refused" $? 12
44"$OLLM" tune "$W/a.ck" "$W/x.ck" 1000000 500 > /dev/null 2>&1; want "TOTAL 1000000 refused" $? 12
45"$OLLM" tune "$W/a.ck" "$W/x.ck" 20 > /dev/null 2>&1; want "argument count refused" $? 2
46head -c 1000 "$W/a.ck" > "$W/short.ck"; "$OLLM" tune "$W/short.ck" "$W/x.ck" 20 500 > /dev/null 2>&1; want "truncated checkpoint refused" $? 10
47[ -e "$W/x.ck" ] && no "refused tune left an output file" || ok "refused tune wrote no output"
48# Negative control: the same source with the moment reset removed must fail the zero check.
49[ -f "$OLLM.om" ] || no "negative control: $OLLM.om (build.sh concatenated source) missing"
50if [ -f "$OLLM.om" ]; then
51 n=$(grep -c "^ozerom mul 2 get og 8\$" "$OLLM.om")
52 want "negative control: one moment-reset line to remove" "$n" 1
53 grep -v "^ozerom mul 2 get og 8\$" "$OLLM.om" > "$W/mut.om"
54 "$OMC" < "$W/mut.om" > "$W/mut" && chmod +x "$W/mut"
55 "$W/mut" tune "$W/a.ck" "$W/m.ck" 20 500 > /dev/null
56 zm=$(tail -c +$((H + 8 * P + 1)) "$W/m.ck" | head -c $((16 * P)) | tr -d "\000" | wc -c | tr -d " ")
57 [ "$zm" -gt 0 ] && ok "negative control caught: moments not reset ($zm nonzero bytes)" || no "negative control not caught"
58fi
59rm -rf "$W"
60[ $bad = 0 ] && echo TUNE_PASS || { echo TUNE_FAIL; exit 1; }