tern-tc-9m / scripts /verify.sh
playra's picture
tern_tc TC02 checkpoint, C engine, verification harness, 8K tokenizer, model card from model_card.t27
ba9e1c8 verified
Raw History Blame Contribute Delete
2.01 kB
#!/bin/sh
# verify.sh -- end-to-end check of the tern_tc release, as published.
#
# 1. sha256 of model.bin and the tokenizer against the values the model card states
# 2. the C engine builds and reproduces the board-verified greedy ids
# 3. (if python3 + torch are present) the PyTorch harness passes
#
# Needs only a C99 compiler and libm for steps 1-2. Run from the repo root:
# sh scripts/verify.sh
set -e
cd "$(dirname "$0")/.."
# macOS spells the tool shasum, Linux sha256sum; both print "hash name"
SHA256=sha256sum
command -v "$SHA256" >/dev/null 2>&1 || SHA256="shasum -a 256"
echo "== 1. hashes =="
MODEL_SHA=3102abdf35057924e077a86db4fdac726e4fe1f6574df47f39a638ba99a3ce9c
TOK_SHA=81355717cd63d2d92f2d1553eee8e072c05cf49b41990d03b20e7898df0ed9d8
[ "$(shasum -a 256 c_infer/model.bin | cut -d' ' -f1)" = "$MODEL_SHA" ] \
&& echo "model.bin sha256 OK" || { echo "model.bin sha256 MISMATCH"; exit 1; }
[ "$(shasum -a 256 results/data8k/tokenizer.json | cut -d' ' -f1)" = "$TOK_SHA" ] \
&& echo "tokenizer.json sha256 OK" || { echo "tokenizer.json sha256 MISMATCH"; exit 1; }
[ "$(shasum -a 256 c_infer/model.bin | cut -d' ' -f1)" = "$(grep 'c_infer/model.bin$' sha256sums.txt | cut -d' ' -f1)" ] \
&& echo "sha256sums.txt agrees" || { echo "sha256sums.txt disagrees"; exit 1; }
echo "== 2. C engine =="
make -C c_infer >/dev/null
# the engine prints info lines, then the generated ids on a digits-only line,
# then a timing line; take the ids line, never the last line
OUT=$(./c_infer/tc_infer c_infer/model.bin --greedy --max 8 | awk '/^[0-9][0-9 ]*$/ {print $1,$2,$3,$4,$5,$6,$7,$8; exit}')
echo "ids: $OUT"
[ "$OUT" = "1 3 204 276 405 659 85 1516" ] && echo "C ids == board ids: PASS" \
|| { echo "C ids != board ids: FAIL"; exit 1; }
echo "== 3. PyTorch harness =="
if python3 -c "import torch" 2>/dev/null; then
python3 scripts/infer_check.py --skip-c | tail -1
else
echo "torch not installed -- skipped (C engine check above is self-sufficient)"
fi
echo "ALL CHECKS DONE"