turkic-ocr-code / scripts /r5_freeze /freeze_prep.sbatch
treoa's picture
Clean up comments and file headers; point to the model repositories
0d02ed4 verified
Raw History Blame Contribute Delete
3.04 kB
#!/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
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)"