Download scripts/r5_rq2/rq2_startup_check.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_rq2/rq2_startup_check.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5_rq2/rq2_startup_check.py
-
curl -L -o rq2_startup_check.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_rq2/rq2_startup_check.py
2.67 kB
| """GPU start-up check (design 'smoke_must_pass', last item): about 3 minutes after the trainings of this segment start, log | |
| samples_per_s and the loss of each running arm; the loss must fall below its first logged value in every arm. Reads the | |
| train logs only (no interim analysis: throughput and loss only). Never stops a training; writes | |
| DATA/outputs/rq2/startup_check_<job>_<slurm job id>.json.""" | |
| import argparse | |
| import json | |
| import os | |
| import time | |
| DATA = "/path/to/TURKIC_OCR_DATA" | |
| def steps_since_last_start(p): | |
| ev = [] | |
| if not os.path.exists(p): | |
| return ev | |
| for line in open(p): | |
| try: | |
| e = json.loads(line) | |
| except Exception: | |
| continue | |
| if e.get("event") in ("start", "resumed"): | |
| ev = [] | |
| if e.get("event") == "step": | |
| ev.append(e) | |
| return ev | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--job", required=True) | |
| ap.add_argument("--runs", required=True) | |
| ap.add_argument("--wait_s", type=float, default=180) | |
| ap.add_argument("--timeout_s", type=float, default=1500) | |
| ap.add_argument("--log_root", default=DATA + "/outputs/rq2/train_logs") | |
| a = ap.parse_args() | |
| runs = a.runs.split(",") | |
| t0 = time.time() | |
| while True: | |
| evs = {r: steps_since_last_start(os.path.join(a.log_root, r, "A1.jsonl")) for r in runs} | |
| active = {r: e for r, e in evs.items() if e} | |
| ready = active and all(len(e) >= 3 for e in active.values()) and time.time() - t0 >= a.wait_s | |
| if ready or time.time() - t0 > a.timeout_s: | |
| break | |
| time.sleep(20) | |
| res = {} | |
| for r, e in evs.items(): | |
| if not e: | |
| res[r] = {"status": "no step events in this segment (finished earlier or not started)"} | |
| continue | |
| first, last = e[0]["loss"], e[-1]["loss"] | |
| tail = [x["loss"] for x in e[-2:]] | |
| res[r] = {"step_events": len(e), "first_loss": first, "last_loss": last, "mean_last_two": sum(tail) / len(tail), | |
| "loss_fell": last < first, "samples_per_s_last": e[-1].get("samples_per_s"), | |
| "gpu_gib_reserved": e[-1].get("gpu_gib_reserved"), "samples_seen": e[-1].get("samples_seen")} | |
| doc = {"job": a.job, "slurm_job": os.environ.get("SLURM_JOB_ID"), "waited_s": time.time() - t0, "runs": res, | |
| "all_active_losses_fell": all(v.get("loss_fell", True) for v in res.values())} | |
| p = os.path.join(DATA, "outputs/rq2", "startup_check_%s_%s.json" % (a.job, os.environ.get("SLURM_JOB_ID", "nojob"))) | |
| with open(p, "w") as f: | |
| json.dump(doc, f, indent=1) | |
| print(json.dumps(doc)) | |
| if __name__ == "__main__": | |
| main() | |