File size: 9,609 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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | #!/bin/bash
#SBATCH --job-name=rel2_d5_install
#SBATCH --partition=ZEN4
#SBATCH --qos=nu-zen4
#SBATCH --gres=none
#SBATCH --cpus-per-task=16
#SBATCH --mem=64G
#SBATCH --time=01:00:00
#SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out
# RELEASE2 D5 finish, step 3: put the retrained detector (yolo_s2_d5 best.pt) into release candidate 1 and check the installed packages.
# 0 preconditions (abort with nothing changed): package best.pt, cards and NOTICE are the rc1 files; the new best.pt has the checked sha256;
# the staged card and NOTICE files have the sha256 written below; no earlier superseded copy or backup folder exists.
# 1 backups of the detector card, NOTICE and SHA256SUMS and of the page-pipeline card and SHA256SUMS: DATA/release/rc1_cards_before_d5/
# 2 the rc1 best.pt is MOVED (never deleted) to DATA/release/rc1_superseded/turkic-line-detector-yolo11s/best.pt and hashed there
# 3 the new best.pt is copied in, the new detector card and NOTICE and the new page-pipeline card are installed
# 4 SHA256SUMS rewritten as the rc1_sums / rel2_decide jobs did (sha256 of every other file, ./relative paths, sorted) and verified
# 5 the three reader packages: sha256sum -c (unchanged)
# 6 the installed page pipeline (default detector folder) on the 5 validation pages of the check job 55752, same arguments;
# its three TSVs must be byte-identical to that job's
# 7 no file newer than its package's SHA256SUMS, no __pycache__, no cluster path or user name in a text file of the two packages
# Validation data only. Nothing is uploaded.
set -u
CODE=/path/to/TURKIC_OCR_CODE
D=/path/to/TURKIC_OCR_DATA
R=$D/release/rc1
P=$R/turkic-line-detector-yolo11s
PP=$R/page-pipeline
S=$D/tmp/release2/d5_finish
B=$D/release/rc1_cards_before_d5
SUP=$D/release/rc1_superseded/turkic-line-detector-yolo11s
NEW=$D/checkpoints/r5/linedet/detectors/yolo_s2_d5/weights/best.pt
OLD_SHA=2ef12b4a1d4b4f28b3285251a35ea30032fc2c7b53f03aa5db5f0510ae8ffc00
NEW_SHA=55633d707319b0c9e0c1a2c1f116357493992e58efc192c679401d31ea14acc4
DET_CARD_OLD=b7f1dc62b5fa7bc68d800fc3b2492399b27abf9dcded14e4b79dc5181e9fab32
DET_NOTICE_OLD=947df3ab8fae87afb29a70cfe93d4318ffdc74a352450b4dab5b8b8bdfe65e80
PAGE_CARD_OLD=fffccd8a405e0cf3b227ec0d6bf2a0ca5c864dfcb178f6eca0ca31e86d3af44b
PAGE_NOTICE_OLD=0e15228baec93adb0025b836439e6ceace7500473584646d2cbba2f81acf588c
DET_CARD_NEW=9ecf37d4a58109b2e6bcb429a38f3e78b5ae98721ed2ce902e4b1e5192cec941
DET_NOTICE_NEW=caf16e2af310d547db071f73340c1f1967b419fdc9d4c2a4f64d404aabfa0d44
PAGE_CARD_NEW=7d5925abe3a49cf41882daa17253d15a5f23cc88c603cc0843bfa11d69055bd1
PAGE_NOTICE_NEW=b63f6c1e1acff94629747a9bf6672c0721e47165fa625c8d7b3eb7fec5f66538
# cluster user names and paths that must not be in a shipped text file (the licensor names of D8 are allowed)
SCRUB='/datahub|/shared/home|CLUSTER_GROUP|CLUSTER_USER|LOCAL_USER|/Users/|/private/'
die() { echo "ABORT: $*"; exit 1; }
h() { sha256sum "$1" | cut -d' ' -f1; }
echo "job $SLURM_JOB_ID host $(hostname) start $(date -u +%FT%TZ)"
echo "== 0 preconditions"
test "$(h $P/best.pt)" = "$OLD_SHA" || die "package best.pt is not the rc1 weights; nothing changed"
test "$(h $NEW)" = "$NEW_SHA" || die "new best.pt sha256 differs from the checked one; nothing changed"
test "$(h $P/model_card.json)" = "$DET_CARD_OLD" || die "detector card on disk differs; nothing changed"
test "$(h $P/NOTICE)" = "$DET_NOTICE_OLD" || die "detector NOTICE on disk differs; nothing changed"
test "$(h $PP/model_card.json)" = "$PAGE_CARD_OLD" || die "page-pipeline card on disk differs; nothing changed"
test "$(h $S/stage/turkic-line-detector-yolo11s/model_card.json)" = "$DET_CARD_NEW" || die "staged detector card differs; nothing changed"
test "$(h $S/stage/turkic-line-detector-yolo11s/NOTICE)" = "$DET_NOTICE_NEW" || die "staged detector NOTICE differs; nothing changed"
test "$(h $S/stage/page-pipeline/model_card.json)" = "$PAGE_CARD_NEW" || die "staged page-pipeline card differs; nothing changed"
test "$(h $PP/NOTICE)" = "$PAGE_NOTICE_OLD" || die "page-pipeline NOTICE on disk differs; nothing changed"
test "$(h $S/stage/page-pipeline/NOTICE)" = "$PAGE_NOTICE_NEW" || die "staged page-pipeline NOTICE differs; nothing changed"
grep -l -i -E "$SCRUB" $S/stage/turkic-line-detector-yolo11s/model_card.json $S/stage/turkic-line-detector-yolo11s/NOTICE $S/stage/page-pipeline/model_card.json $S/stage/page-pipeline/NOTICE && die "a staged file names a cluster path or user; nothing changed"
test ! -e $SUP/best.pt || die "$SUP/best.pt exists; nothing changed"
test ! -e $B || die "$B exists; nothing changed"
(cd $P && sha256sum -c --quiet SHA256SUMS) || die "detector SHA256SUMS fails before the change; nothing changed"
(cd $PP && sha256sum -c --quiet SHA256SUMS) || die "page-pipeline SHA256SUMS fails before the change; nothing changed"
echo "preconditions ok"
echo "== 1 backups"
mkdir -p $B/turkic-line-detector-yolo11s $B/page-pipeline
cp -p $P/model_card.json $P/NOTICE $P/SHA256SUMS $B/turkic-line-detector-yolo11s/
cp -p $PP/model_card.json $PP/NOTICE $PP/SHA256SUMS $B/page-pipeline/
ls -l $B/turkic-line-detector-yolo11s $B/page-pipeline
echo "== 2 move the rc1 best.pt out of the package"
mkdir -p $SUP
mv -n $P/best.pt $SUP/best.pt
test ! -e $P/best.pt || die "mv did not move best.pt"
test "$(h $SUP/best.pt)" = "$OLD_SHA" || die "superseded copy sha256 differs"
echo "superseded $SUP/best.pt $(h $SUP/best.pt) $(stat -c %s $SUP/best.pt) bytes"
echo "== 3 install"
cp $NEW $P/best.pt
test "$(h $P/best.pt)" = "$NEW_SHA" || die "installed best.pt sha256 differs"
cp $S/stage/turkic-line-detector-yolo11s/model_card.json $P/model_card.json
cp $S/stage/turkic-line-detector-yolo11s/NOTICE $P/NOTICE
cp $S/stage/page-pipeline/model_card.json $PP/model_card.json
cp $S/stage/page-pipeline/NOTICE $PP/NOTICE
chmod a+r $P/* $PP/* $SUP/best.pt
echo "installed best.pt $(h $P/best.pt) $(stat -c %s $P/best.pt) bytes"
echo "card_sha256 turkic-line-detector-yolo11s $(h $P/model_card.json)"
echo "notice_sha256 turkic-line-detector-yolo11s $(h $P/NOTICE)"
echo "card_sha256 page-pipeline $(h $PP/model_card.json)"
echo "notice_sha256 page-pipeline $(h $PP/NOTICE)"
echo "== 4 SHA256SUMS"
cd $P
rm -f SHA256SUMS
find . -type f | sort | xargs sha256sum > $S/sums_det.tmp
cp $S/sums_det.tmp SHA256SUMS
sha256sum -c --quiet SHA256SUMS && echo "sha256sums_ok turkic-line-detector-yolo11s files $(wc -l < SHA256SUMS)"
echo "changed_or_new turkic-line-detector-yolo11s: $(diff <(sort -k2 $B/turkic-line-detector-yolo11s/SHA256SUMS) <(sort -k2 SHA256SUMS) | grep '^>' | cut -c69- | tr '\n' ' ')"
cat SHA256SUMS
cd $PP
rm -f SHA256SUMS
find . -type f | sort | xargs sha256sum > $S/sums_page.tmp
cp $S/sums_page.tmp SHA256SUMS
sha256sum -c --quiet SHA256SUMS && echo "sha256sums_ok page-pipeline files $(wc -l < SHA256SUMS)"
echo "changed_or_new page-pipeline: $(diff <(sort -k2 $B/page-pipeline/SHA256SUMS) <(sort -k2 SHA256SUMS) | grep '^>' | cut -c69- | tr '\n' ' ')"
cat SHA256SUMS
chmod a+r $P/SHA256SUMS $PP/SHA256SUMS
echo "== 5 reader packages unchanged"
(cd $R/turkic-ocr-paddleocr-vl-1.6 && sha256sum -c --quiet SHA256SUMS && echo "sha256sums_ok turkic-ocr-paddleocr-vl-1.6")
(cd $R/turkic-ocr-qwen3-vl-2b && sha256sum -c --quiet SHA256SUMS && echo "sha256sums_ok turkic-ocr-qwen3-vl-2b")
(cd $R/turkic-ocr-ppocrv6-medium && sha256sum -c --quiet SHA256SUMS && echo "sha256sums_ok turkic-ocr-ppocrv6-medium")
echo "== 6 installed page pipeline on the 5 validation pages"
mkdir -p $S/run_installed
unset HF_TOKEN HUGGING_FACE_HUB_TOKEN
export PYTHONDONTWRITEBYTECODE=1 HF_HOME=$S/hf_home HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 YOLO_OFFLINE=1 YOLO_CONFIG_DIR=$S/yolo_cfg OMP_NUM_THREADS=16 MKL_NUM_THREADS=16 TOKENIZERS_PARALLELISM=false
cd $S/run_installed
$CODE/.venv_vlm/bin/python -B -I $PP/infer.py --manifest $S/pages5.tsv --out $S/inst_page_pages.tsv --lines-out $S/inst_page_lines.tsv --hires-tsv $S/pages5_hires.tsv --detector-python $CODE/.venv_kraken/bin/python --device cpu --threads 16 --keep-boxes $S/inst_page_boxes.tsv
echo "installed pipeline exit $?"
cmp $S/inst_page_boxes.tsv $S/page_boxes.tsv && echo "boxes_identical_to_check_job"
cmp $S/inst_page_lines.tsv $S/page_lines.tsv && echo "lines_identical_to_check_job"
cmp $S/inst_page_pages.tsv $S/page_pages.tsv && echo "pages_identical_to_check_job"
echo "== 7 package state after the run"
(cd $P && sha256sum -c --quiet SHA256SUMS && echo "sha256sums_ok_after turkic-line-detector-yolo11s")
(cd $PP && sha256sum -c --quiet SHA256SUMS && echo "sha256sums_ok_after page-pipeline")
echo "files newer than their package's SHA256SUMS (must be none):"
find $R/turkic-line-detector-yolo11s -type f -newer $R/turkic-line-detector-yolo11s/SHA256SUMS ! -name SHA256SUMS
find $R/page-pipeline -type f -newer $R/page-pipeline/SHA256SUMS ! -name SHA256SUMS
find $R/turkic-ocr-paddleocr-vl-1.6 -type f -newer $R/turkic-ocr-paddleocr-vl-1.6/SHA256SUMS ! -name SHA256SUMS
find $R/turkic-ocr-qwen3-vl-2b -type f -newer $R/turkic-ocr-qwen3-vl-2b/SHA256SUMS ! -name SHA256SUMS
find $R/turkic-ocr-ppocrv6-medium -type f -newer $R/turkic-ocr-ppocrv6-medium/SHA256SUMS ! -name SHA256SUMS
echo "__pycache__ in rc1 (must be none):"
find $R -name __pycache__
echo "text files of the two packages naming a cluster path or the user (must be none):"
grep -l -I -i -E "$SCRUB" $P/* $PP/*
echo "licensor placeholders left in the two packages (must be none):"
grep -l -I -E "LICENSOR:|authors of this release" $P/* $PP/*
echo "best.pt train_args cluster paths are expected (pickle limit on the card)"
ls -l $P $PP $SUP
chmod -R a+rX $R $D/release/rc1_superseded $B
echo "end $(date -u +%FT%TZ)"
|