Upload run_all.py with huggingface_hub
Browse files- run_all.py +30 -11
run_all.py
CHANGED
|
@@ -1,25 +1,41 @@
|
|
| 1 |
-
"""
|
| 2 |
-
|
| 3 |
-
Runs on the TPU runtime's host, which has many vCPUs (~24) AND the TPU chip.
|
| 4 |
-
So we do BOTH stages here, using the machine fully:
|
| 5 |
|
|
|
|
| 6 |
1. prepare: if train.bin/val.bin are missing from the HF data repo, tokenize the
|
| 7 |
-
corpus in parallel across all host cores and upload them. Skipped if already
|
| 8 |
-
present
|
| 9 |
-
2. train:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
the
|
| 13 |
"""
|
| 14 |
import os
|
| 15 |
-
import sys
|
| 16 |
import time
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def _log(m: str) -> None:
|
| 20 |
print(f"[run_all {time.strftime('%H:%M:%S')}] {m}", flush=True)
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def data_ready() -> bool:
|
| 24 |
from huggingface_hub import list_repo_files
|
| 25 |
from config import DATA_REPO
|
|
@@ -32,17 +48,20 @@ def data_ready() -> bool:
|
|
| 32 |
|
| 33 |
|
| 34 |
def main() -> None:
|
|
|
|
| 35 |
if data_ready():
|
| 36 |
_log("data already on HF; skipping prepare")
|
| 37 |
else:
|
| 38 |
_log("data missing; running prepare (parallel tokenization on host cores)")
|
|
|
|
| 39 |
import prepare_data
|
| 40 |
prepare_data.main()
|
| 41 |
_log("prepare done")
|
| 42 |
|
| 43 |
_log("starting TPU training")
|
|
|
|
| 44 |
import train_tpu
|
| 45 |
-
train_tpu.main()
|
| 46 |
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
"""Runs INSIDE the TPU session, launched DETACHED by bootstrap.py.
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
Does both stages on the TPU runtime host (24 vCPU + 1 TPU chip):
|
| 4 |
1. prepare: if train.bin/val.bin are missing from the HF data repo, tokenize the
|
| 5 |
+
hy corpus in parallel across all host cores and upload them. Skipped if already
|
| 6 |
+
present, so a relaunch after a dead session goes straight to training.
|
| 7 |
+
2. train: JAX/Flax loop on the TPU chip, checkpointing to HF every save_every
|
| 8 |
+
steps and resuming from the latest HF checkpoint on start.
|
| 9 |
+
|
| 10 |
+
Durability model (see memory colab-cli-headless-10min-exec-wall): the Colab
|
| 11 |
+
runtime is ephemeral and gets reclaimed ~10 min after the driving `colab exec`
|
| 12 |
+
websocket drops. So this process is DETACHED and the local supervisor (launch.py)
|
| 13 |
+
keeps the session alive with short pings; if the session dies anyway, the
|
| 14 |
+
supervisor starts a fresh one and this resumes from the last HF checkpoint.
|
| 15 |
|
| 16 |
+
We write a heartbeat line to HEARTBEAT_PATH each loop so a supervisor ping can
|
| 17 |
+
confirm the trainer is actually progressing (not just that the kernel is up).
|
| 18 |
"""
|
| 19 |
import os
|
|
|
|
| 20 |
import time
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
HEARTBEAT_PATH = Path("/content/train_logs/heartbeat.txt")
|
| 24 |
|
| 25 |
|
| 26 |
def _log(m: str) -> None:
|
| 27 |
print(f"[run_all {time.strftime('%H:%M:%S')}] {m}", flush=True)
|
| 28 |
|
| 29 |
|
| 30 |
+
def beat(msg: str) -> None:
|
| 31 |
+
"""Progress marker the supervisor reads to confirm forward progress."""
|
| 32 |
+
try:
|
| 33 |
+
HEARTBEAT_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 34 |
+
HEARTBEAT_PATH.write_text(f"{time.time():.0f} {msg}\n", encoding="utf-8")
|
| 35 |
+
except Exception:
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
+
|
| 39 |
def data_ready() -> bool:
|
| 40 |
from huggingface_hub import list_repo_files
|
| 41 |
from config import DATA_REPO
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
def main() -> None:
|
| 51 |
+
beat("startup")
|
| 52 |
if data_ready():
|
| 53 |
_log("data already on HF; skipping prepare")
|
| 54 |
else:
|
| 55 |
_log("data missing; running prepare (parallel tokenization on host cores)")
|
| 56 |
+
beat("prepare")
|
| 57 |
import prepare_data
|
| 58 |
prepare_data.main()
|
| 59 |
_log("prepare done")
|
| 60 |
|
| 61 |
_log("starting TPU training")
|
| 62 |
+
beat("train-start")
|
| 63 |
import train_tpu
|
| 64 |
+
train_tpu.main(beat=beat)
|
| 65 |
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|