File size: 5,085 Bytes
24aaa76 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #!/bin/bash
# RQ2 GPU segment (records/R5/RQ2/design.json; frozen sha256 2609388c19d54c80e9387d559ed7003949d26e0d22f836f3a1d4ad9df7dd7a66).
# Runs INSIDE the one-H100 allocation of rq2_gate_a.sbatch (job name rq2_a, RQ2_JOB=A) or rq2_gate_b.sbatch (rq2_b, RQ2_JOB=B),
# which checked the reviewed sha256 list DATA/outputs/rq2/READY and then exec'd this file. No #SBATCH lines here.
# Job A: seed-1 block (rq2_h32_typ_s1, rq2_h32_safe_s1, rq2_h64_typ_s1, rq2_h64_safe_s1, four at once), then rq2_h32_typ_s3 and
# rq2_h32_safe_s3, and the validation predictions of each run after its training.
# Job B: seed-2 block, then rq2_h64_typ_s3 and rq2_h64_safe_s3, predictions, probe P2 (after the seed-2 block).
# The task driver (linedet.driver, unchanged) runs CODE/scripts/r5_rq2/tasks_<JOB>.json; trainings resume from resume.pt, a
# finished training exits at once ('already_done'), finished predictions and P2 conditions are skipped. Validation sets only.
# When the job's runs are not all finished at the end of the allocation, THE GATE is resubmitted (sbatch --test-only first, then
# sbatch, same --job-name; the gate has --dependency=singleton), at most 3 times, so every segment passes the same review check.
# DATA/outputs/rq2/STOP stops the chain. Guard: DATA/outputs/rq2/RUNNING_<JOB> holds the job id of the running segment.
# RQ2_DRYRUN=1 (CPU smoke job only): checks the state and the resubmission with sbatch --test-only, starts nothing.
set -uo pipefail
C=/path/to/TURKIC_OCR_CODE
D=/path/to/TURKIC_OCR_DATA
S=$C/scripts/r5_rq2
O=$D/outputs/rq2
CK=$D/checkpoints/rq2
PY=$C/.venv_kraken/bin/python
JOB=${RQ2_JOB:-none}
case "$JOB" in
A) GATE=$S/rq2_gate_a.sbatch; JOBNAME=rq2_a
RUNS="rq2_h32_typ_s1 rq2_h32_safe_s1 rq2_h64_typ_s1 rq2_h64_safe_s1 rq2_h32_typ_s3 rq2_h32_safe_s3" ;;
B) GATE=$S/rq2_gate_b.sbatch; JOBNAME=rq2_b
RUNS="rq2_h32_typ_s2 rq2_h32_safe_s2 rq2_h64_typ_s2 rq2_h64_safe_s2 rq2_h64_typ_s3 rq2_h64_safe_s3" ;;
*) echo "REFUSED: RQ2_JOB must be A or B (got $JOB)"; exit 3 ;;
esac
N=${RQ2_RESUBMIT:-0}
MAXRESUB=3
unset HF_TOKEN HUGGING_FACE_HUB_TOKEN
export OMP_NUM_THREADS=2 MKL_NUM_THREADS=2 PYTHONUNBUFFERED=1
mkdir -p $O/driver_logs_$JOB $O/logs $CK
[ -n "${SLURM_JOB_ID:-}" ] || { echo "REFUSED: not inside a Slurm allocation"; exit 3; }
if [ "${RQ2_DRYRUN:-0}" != 1 ] && ! nvidia-smi -L >/dev/null 2>&1; then echo "REFUSED: no GPU in this allocation"; exit 3; fi
GUARD=$O/RUNNING_$JOB
if [ -f $GUARD ]; then
OTHER=$(head -n 1 $GUARD)
if [ -n "$OTHER" ] && [ "$OTHER" != "$SLURM_JOB_ID" ] && [ -n "$(squeue -h -j $OTHER -t R -o %i 2>/dev/null)" ]; then
echo "REFUSED: segment $OTHER of RQ2 job $JOB is still running ($GUARD); exit 3"
exit 3
fi
fi
[ "${RQ2_DRYRUN:-0}" = 1 ] || echo $SLURM_JOB_ID > $GUARD
complete() {
for R in $RUNS; do
[ -f $CK/$R/A1/short.pt ] || return 1
[ -f $O/preds/$R/short/meta.json ] || return 1
done
if [ "$JOB" = B ]; then [ -f $O/probe_p2/DONE ] || return 1; fi
return 0
}
status_line() {
for R in $RUNS; do
if [ -f $CK/$R/A1/short.pt ]; then T=trained; elif [ -f $CK/$R/A1/resume.pt ]; then T=partial; else T=not_started; fi
if [ -f $O/preds/$R/short/meta.json ]; then P=predicted; else P=no_preds; fi
echo " $R: $T, $P"
done
}
resubmit() {
[ "${RQ2_DRYRUN:-0}" = 1 ] || rm -f $GUARD
if [ -f $O/STOP ]; then echo "STOP file present: no resubmission"; exit 1; fi
if [ "$N" -ge "$MAXRESUB" ]; then echo "resubmission limit reached ($N of $MAXRESUB); the chain stops here"; exit 1; fi
sbatch --test-only --job-name=$JOBNAME --export=ALL,RQ2_JOB=$JOB,RQ2_RESUBMIT=$((N + 1)) $GATE \
|| { echo "RESUBMISSION FAILED (test-only refused); the chain stops here"; exit 1; }
if [ "${RQ2_DRYRUN:-0}" = 1 ]; then echo "DRYRUN: test-only passed; the real sbatch is skipped"; exit 0; fi
sbatch --job-name=$JOBNAME --export=ALL,RQ2_JOB=$JOB,RQ2_RESUBMIT=$((N + 1)) $GATE \
|| { echo "RESUBMISSION FAILED (sbatch refused); the chain stops here"; exit 1; }
exit 0
}
hostname; nvidia-smi --query-gpu=name,memory.total,memory.used --format=csv,noheader 2>/dev/null; date -u +%FT%TZ
echo "RQ2 job $JOB, slurm job $SLURM_JOB_ID, resubmission $N"
status_line
if complete; then
echo "job $JOB: every run is trained and predicted$([ "$JOB" = B ] && echo ', probe P2 done'); nothing to do"
[ "${RQ2_DRYRUN:-0}" = 1 ] || { date -u +%FT%TZ > $O/DONE_$JOB; rm -f $GUARD; }
exit 0
fi
if [ "${RQ2_DRYRUN:-0}" = 1 ]; then
echo "DRYRUN: would run: $PY -I -m linedet.driver --tasks $S/tasks_$JOB.json --status $O/driver_status_$JOB.json --logdir $O/driver_logs_$JOB --max_seconds 13800 --grace 300"
[ -f $S/tasks_$JOB.json ] && echo "DRYRUN: task file present" || echo "DRYRUN: task file MISSING"
resubmit
fi
$PY -I -m linedet.driver --tasks $S/tasks_$JOB.json --status $O/driver_status_$JOB.json --logdir $O/driver_logs_$JOB \
--max_seconds 13800 --grace 300
echo "driver ended $(date -u +%FT%TZ)"
status_line
if complete; then
date -u +%FT%TZ > $O/DONE_$JOB
rm -f $GUARD
echo "=== job $JOB complete $(date -u +%FT%TZ)"
exit 0
fi
resubmit
|