#!/bin/bash #SBATCH --job-name=r5_freeze_prep #SBATCH --partition=ZEN4 #SBATCH --qos=nu-zen4 #SBATCH --gres=none #SBATCH --cpus-per-task=8 #SBATCH --mem=32G #SBATCH --time=01:00:00 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out # R5 stage FREEZE, job 1 of 2 (part A plus the checks of part B step 3). It never creates mix_v1.yaml (the file that starts # the GPU jobs). Reads manifests/ only in step 1 (the copy), and refuses to copy while a GEN finalize job (r5_gen_final) runs, # because that job rewrites manifests/synth_* in place. Steps: # 1 copies of the 8 train manifests + 3 GEN sidecars into DATA/data/processed/r5/frozen_mix_v1/, files chmod a-w # 2 gen_mix_v1.py -> DATA/data/processed/r5/mix_v1.yaml.tmp (+ gen_report.json); fails closed on any sha256 or row problem; # only then the folder itself is made read-only # 3 VLMA's check_mix.sbatch, run with bash inside this job (build_sequence.py, 200,000 rows, every train image checked) # 4 LINEDET's make_codec on the tmp yaml (--out DATA/tmp/codec_check/codec_union.json) # 5 compare_parsers.py: LINEDET, REF, EVALCODE and VLMA parsers read the same leaves and shares # Outputs in DATA/outputs/r5/freeze/. set -u unset HF_TOKEN HUGGING_FACE_HUB_TOKEN C=/path/to/TURKIC_OCR_CODE D=/path/to/TURKIC_OCR_DATA R5=$D/data/processed/r5 M=$R5/manifests FZ=$R5/frozen_mix_v1 W=$D/outputs/r5/freeze F=$C/scripts/r5_freeze TMPY=$R5/mix_v1.yaml.tmp PYK=$C/.venv_kraken/bin/python mkdir -p $W $D/tmp/codec_check echo "start $(date -u +%FT%TZ) on $(hostname), job $SLURM_JOB_ID, cpus $SLURM_CPUS_PER_TASK" if [ -e $R5/mix_v1.yaml ]; then echo "STOP: mix_v1.yaml exists already"; exit 9; fi echo "== step 1 frozen copies $(date -u +%T)" RUNNING=$(squeue -h -u $USER -n r5_gen_final -t R -o %i) echo "GEN finalize jobs running now: [$RUNNING]" if [ -w $FZ ] || [ ! -e $FZ ]; then if [ -n "$RUNNING" ]; then echo "STOP: a GEN finalize job is rewriting manifests/synth_* now; resubmit later"; exit 4; fi mkdir -p $FZ for f in kohtd_train hkr_train chd_train school_train synth_hand_train synth_typed_train print_real_train synth_clutter_train; do [ -e $FZ/$f.tsv ] || cp -p $M/$f.tsv $FZ/$f.tsv done for f in synth_hand_train synth_typed_train synth_clutter_train; do [ -e $FZ/$f.meta.tsv ] || cp -p $M/$f.meta.tsv $FZ/$f.meta.tsv done chmod a-w $FZ/*.tsv fi echo "GEN finalize jobs running after the copy: [$(squeue -h -u $USER -n r5_gen_final -t R -o %i)]" ls -la $FZ (cd $FZ && sha256sum *.tsv) > $W/frozen_mix_v1.sha256 cat $W/frozen_mix_v1.sha256 echo "== step 2 generator $(date -u +%T)" $PYK -I $F/gen_mix_v1.py --frozen-dir $FZ --source-dir $M --out $TMPY --report $W/gen_report.json RC2=$? echo "step2 exit $RC2" if [ $RC2 -ne 0 ]; then echo "STOP: generator failed; the frozen folder stays writable so a bad copy can be replaced"; exit 2; fi chmod a-w $FZ cp $W/frozen_mix_v1.sha256 $D/checksums/r5_frozen_mix_v1.sha256 sha256sum $TMPY echo "== step 3 check_mix (VLMA build_sequence, 200,000 rows) $(date -u +%T)" bash $C/scripts/r5_vlma/check_mix.sbatch $TMPY > $W/check_mix.log 2>&1 O=$D/outputs/r5/vlma/check_mix if [ -e $O/trial_seq.tsv.done ]; then RC3=0; else RC3=1; fi cp $O/trial_seq.tsv.summary.json $W/check_mix_summary.json tail -c 1500 $W/check_mix.log echo "step3 done-file present: $RC3 (0 = yes)" echo "== step 4 make_codec (LINEDET) $(date -u +%T)" $PYK -I -m linedet.make_codec --mix $TMPY --out $D/tmp/codec_check/codec_union.json > $W/make_codec.log 2>&1 RC4=$? head -c 3000 $W/make_codec.log echo "step4 exit $RC4" echo "== step 5 parser comparison $(date -u +%T)" $PYK -I $F/compare_parsers.py $TMPY $W/check_mix_summary.json $W/gen_report.json $W/compare_parsers.json RC5=$? echo "step5 exit $RC5" sha256sum $TMPY echo "{\"job\": $SLURM_JOB_ID, \"end_utc\": \"$(date -u +%FT%TZ)\", \"rc\": {\"gen\": $RC2, \"check_mix_done_missing\": $RC3, \"make_codec\": $RC4, \"compare\": $RC5}}" > $W/freeze_prep_rc.json cat $W/freeze_prep_rc.json echo "end $(date -u +%FT%TZ)"