File size: 4,636 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 | """Appends amendment 3 (A1 batch-padding finding: label-free re-run of M2) to records/R5/TESTPASS2/plan.json, before those predictions.
usage: tp2_amend3.py TESTPASS2_DIR
"""
import hashlib
import json
import os
import sys
import time
TP = sys.argv[1]
p = os.path.join(TP, "plan.json")
plan = json.load(open(p, encoding="utf-8"))
prev = hashlib.sha256(open(p, "rb").read()).hexdigest()
code = {f: hashlib.sha256(open(os.path.join(TP, "code", f), "rb").read()).hexdigest()
for f in ("tp2_a1_labelfree.py", "tp2_a1lf.sbatch", "tp2_results.py", "tp2_finalize.py")}
code["release infer.py (DATA/release/rc1/turkic-ocr-ppocrv6-medium, SHA256SUMS)"] = "8910dc991db5452ae9063bbc736b3464ca088553813b3bf147b1f507bc4bbee5"
code["release model/model.safetensors"] = "2dda8e465ecde4a98b8630f3ac98173341420bc9ab45bb59a83de2832746469f"
code["release model/codec.json"] = "49832a6c3630f0b6ef908d5d02e88bdf32fcd18fa2622fbe91a50dbe6a2afabf"
code["release lm/char6.klm (equal to the R5 LM)"] = "e5b596f9463c78250f5b8dcf58a75cdc1a90f29d20bd7ab0b2187a5c357902fb"
amend = {
"n": 3, "utc": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "previous_plan_sha256": prev,
"before_the_label_free_predictions": True,
"why": ("message of 25 Nov 2026 relaying the release packager's finding (records/R5/RELEASE/rc1_report.json, "
"headline_finding_for_the_owner): A1's output depends on batch padding (kraken PP-OCRv6 squeeze-excite layers average over the "
"padded width). The R5 evaluation batched A1 rows by REFERENCE LABEL LENGTH (CODE/src/linedet/predict.py run_set uses "
"data.eval_order, sorted by len(text), batch 32), which leaks reference information into the predictions. V1 greedy CER: 6.2% "
"label-length batches, 14.1% width-sorted, 6.48% width-sorted + 256 zero columns (label-free, chosen on V1)."),
"which_A1_tasks_already_ran": ("all M2 figures of this pass so far: greedy and gated-LM predictions of the 8 crop sets were made on 24 Nov "
"in the sealed pass (step 8) with label-length batching and are reused here. The gated LM decoded the top-6 "
"log-probabilities stored by that same predict.py pass (predict.py lines 87-103, lm_decode.py load_npz), so it "
"inherits the label-length batching. No A1 run is part of the page pipeline (pages use M1)."),
"change": ("those predictions are KEPT and reported, marked 'label-length batching (leaks reference length)'; M2 is re-run ONCE on each of "
"the 8 crop sets with the label-free setting of the release package (infer.py imported unchanged by tp2_a1_labelfree.py: "
"--sort width --batch-pad 256, batch 32, CPU float32, one forward pass giving greedy CTC and the gated character LM, alpha 0.40, "
"beta 1.00, beam 16, top-6, prune -10, empty greedy -> empty). The label-free figures are THE M2 RESULT; the paired M1-M2 "
"difference uses them (the label-length version is kept as a secondary row)."),
"caveats": ["batch-pad 256 was chosen on V1 word crops; for line crops (az_localdoc, RUKOPYS, synthetic lines) the value is untested "
"(infer.py docstring); it is NOT tuned on any test set",
"the release weights are the A1 long2x checkpoint exported to safetensors (rc1 prep job 55104; the rc1 check reproduced the "
"recorded V1 figures, 6.19% vs 6.20% greedy)"],
"smoke": ("first on the validation set V1 (3,678 crops): the run stops unless greedy CER is within 0.001 of 0.0648 and gated-LM CER within "
"0.001 of 0.0482 (the release report's V1 figures). Then the 8 locked crop sets once each, prediction roots "
"DATA/outputs/r5/testpass2/preds/m2lf_<set>/A1/{long2x_labelfree, long2x_labelfree_lm_gated}; scored by the same R5 scorer."),
"running": "one ZEN4 job (16 CPUs, 64 GB), at most 6 test-pass-2 jobs at once",
"vlms": "unchanged (the release check found M1 and Qwen identical with different batch companions; our smoke found CPU = GPU on 80 of 80 rows)",
"code_sha256": code,
}
plan["amendments"].append(amend)
plan["models"]["M2"]["run"] += (" AMENDMENT 3: these reused predictions used label-length batching (leaks reference length) and are kept as a "
"secondary row; M2 is re-run once label-free and that is the M2 result.")
plan["version"] = "1.3"
json.dump(plan, open(p, "w", encoding="utf-8"), indent=1, ensure_ascii=False)
print("amended", p, hashlib.sha256(open(p, "rb").read()).hexdigest())
|