turkic-ocr-code / scripts /r5_linedet /test_pass_commands.sh
treoa's picture
Release 1
24aaa76
Raw History Blame Contribute Delete
3.03 kB
#!/bin/bash
# R5 LINEDET: test-set predictions of the line arms, to be run on a compute node ONLY in the scoring pass. NO CAP of any kind (clarification H10):
# every crop of every locked set, greedy and then the character-LM beam search (alpha and beta taken from each checkpoint's validation tuning) and its gated copy.
#
# Order of use:
# 1. copy records/R5/RULE/test_pass_started.txt to the cluster as /path/to/TURKIC_OCR_DATA/outputs/r5/linedet/test_pass_started.txt
# (predict.py and lm_decode.py REFUSE the test pass while that file does not exist, and refuse --limit and --max_lines).
# 2. run this script in a job, for example (GPU for the predictions; the LM decoding uses CPU workers):
# sbatch --partition=H100 --qos=nu-h100 --gres=gpu:h100:1 --cpus-per-task=32 --mem=96G --time=03:00:00 --job-name=r5_ld_testpass \
# --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out --wrap "bash /path/to/TURKIC_OCR_CODE/scripts/r5_linedet/test_pass_commands.sh"
# (LINEDET_DEVICE=cpu runs it on CPU.)
# Writes DATA/outputs/r5/preds/<label>/<checkpoint>/<test set>.tsv, <checkpoint>_lm/<test set>.tsv and <checkpoint>_lm_gated/<test set>.tsv, and
# meta_test_pass.json beside them (meta.json of the validation pass is never overwritten). Test sets = every set of evalsets.json with locked = true
# (page sets have no line rows and are skipped).
set -u
unset HF_TOKEN HUGGING_FACE_HUB_TOKEN
C=/path/to/TURKIC_OCR_CODE
D=/path/to/TURKIC_OCR_DATA
PY=$C/.venv_kraken/bin/python
GATE=$D/outputs/r5/linedet/test_pass_started.txt
if [ ! -f $GATE ]; then echo "REFUSED: $GATE does not exist (the scoring pass has not started)"; exit 1; fi
DEV=${LINEDET_DEVICE:-cuda}
CK=$D/checkpoints/r5/linedet
CK2=$D/checkpoints/r5/linedet_s2
CKE=$D/checkpoints/r5/linedet_ext # A1 and A2 seed 1 extended to 2 x P_long (amendment 3.4 E5), checkpoint long2x
run() { # label arm ckpt_dir checkpoint
LAB=$1; ARM=$2; CD=$3; CKPT=$4
if [ ! -f $CD/$ARM/$CKPT.pt ]; then echo "skip $LAB $CKPT (no checkpoint)"; return; fi
echo "=== $LAB $CKPT $(date)"
$PY -I -m linedet.predict --arm $ARM --arm_label $LAB --ckpt $CKPT --ckpt_dir $CD --test_pass --device $DEV --workers 8
if [ -f $D/outputs/r5/preds/$LAB/${CKPT}_lm/meta.json ]; then
$PY -I -m linedet.lm_decode --arm $LAB --ckpt $CKPT --test_pass --workers 16 # no --max_lines: every crop
else
echo "no validation-tuned LM for $LAB $CKPT: LM decoding skipped"
fi
}
for ARM in A1 A2 A3 A1s; do run $ARM $ARM $CK short; run $ARM $ARM $CK long; done
for ARM in A1 A2; do run $ARM $ARM $CKE long2x; run $ARM $ARM $CKE partial; done # long2x (and its partial, if the extension was stopped early)
run A4 A4 $CK short; run A4 A4 $CK partial # A4 is the BROKEN RUN of clarification H8: its P_short and partial figures are reported as they are
for ARM in A1 A2; do run ${ARM}_s2 $ARM $CK2 short; run ${ARM}_s2 $ARM $CK2 long; run ${ARM}_s2 $ARM $CK2 partial; done
$PY -I -m linedet.lm_gate
echo "line-arm test predictions written"