hf_train_job: flush logs, trap import errors for HF debugging
Browse files- scripts/hf_train_job.py +24 -14
scripts/hf_train_job.py
CHANGED
|
@@ -3,8 +3,11 @@ from __future__ import annotations
|
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
import time
|
|
|
|
| 6 |
from pathlib import Path
|
| 7 |
|
|
|
|
|
|
|
| 8 |
# HF Job entrypoint for the Milestone 4.16 5-epoch convergence run.
|
| 9 |
# This script is executed inside the HF Jobs container. It assumes the
|
| 10 |
# pino source tree has been cloned into /workspace/pino.
|
|
@@ -44,13 +47,22 @@ def _prepare_registry() -> None:
|
|
| 44 |
if registry_path.exists():
|
| 45 |
registry_path = _copy_registry_to_writable(registry_path)
|
| 46 |
os.environ["PINO_REGISTRY_PATH"] = str(registry_path)
|
| 47 |
-
print(f"π PINO_REGISTRY_PATH set to {registry_path}")
|
| 48 |
|
| 49 |
|
| 50 |
_prepare_registry()
|
| 51 |
|
| 52 |
-
import torch
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
|
| 56 |
def hf_train_5epoch() -> None:
|
|
@@ -64,7 +76,7 @@ def hf_train_5epoch() -> None:
|
|
| 64 |
# Download the dataset from the canonical dataset repository.
|
| 65 |
from huggingface_hub import hf_hub_download
|
| 66 |
|
| 67 |
-
print("π₯ Downloading empirical v3 dataset from Hugging Face Hub...")
|
| 68 |
data_path.parent.mkdir(parents=True, exist_ok=True)
|
| 69 |
downloaded = hf_hub_download(
|
| 70 |
repo_id="mattbitzesty/pino-synthetic-dataset-v3",
|
|
@@ -74,7 +86,7 @@ def hf_train_5epoch() -> None:
|
|
| 74 |
local_dir=str(data_path.parent),
|
| 75 |
)
|
| 76 |
data_path = Path(downloaded)
|
| 77 |
-
print(f" Dataset downloaded to {data_path}")
|
| 78 |
elif not data_path.exists():
|
| 79 |
# Allow the dataset to be mounted elsewhere in the container.
|
| 80 |
data_path = Path("/data/empirical_dataset_v3.jsonl")
|
|
@@ -94,20 +106,18 @@ def hf_train_5epoch() -> None:
|
|
| 94 |
"--log-dir", str(LOG_DIR),
|
| 95 |
]
|
| 96 |
|
| 97 |
-
print("π HF Job: starting PINO 5-epoch convergence pass")
|
| 98 |
-
print(f" Device: {'cuda' if torch.cuda.is_available() else 'cpu'}")
|
| 99 |
-
print(f" Args: {' '.join(sys.argv[1:])}")
|
| 100 |
|
| 101 |
try:
|
| 102 |
checkpoint_path = train_main()
|
| 103 |
except Exception as exc:
|
| 104 |
-
print(f"β Training failed: {exc}")
|
| 105 |
-
import traceback
|
| 106 |
-
|
| 107 |
traceback.print_exc()
|
| 108 |
sys.exit(1)
|
| 109 |
|
| 110 |
-
print(f"β
Training complete. Checkpoint: {checkpoint_path}")
|
| 111 |
|
| 112 |
# Push checkpoint to the model hub if token is present.
|
| 113 |
if token and checkpoint_path and Path(checkpoint_path).exists():
|
|
@@ -117,7 +127,7 @@ def hf_train_5epoch() -> None:
|
|
| 117 |
try:
|
| 118 |
create_repo(repo_id, private=True, token=token, exist_ok=True)
|
| 119 |
except Exception as exc: # noqa: BLE001
|
| 120 |
-
print(f"Repo create/exists check: {exc}")
|
| 121 |
|
| 122 |
api = HfApi(token=token)
|
| 123 |
api.upload_file(
|
|
@@ -126,7 +136,7 @@ def hf_train_5epoch() -> None:
|
|
| 126 |
repo_id=repo_id,
|
| 127 |
repo_type="model",
|
| 128 |
)
|
| 129 |
-
print(f"π€ Checkpoint uploaded to https://huggingface.co/{repo_id}")
|
| 130 |
|
| 131 |
# Sleep briefly so logs flush.
|
| 132 |
time.sleep(5)
|
|
|
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
import time
|
| 6 |
+
import traceback
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
+
print("[HF-JOB] hf_train_job.py top-level started", flush=True)
|
| 10 |
+
|
| 11 |
# HF Job entrypoint for the Milestone 4.16 5-epoch convergence run.
|
| 12 |
# This script is executed inside the HF Jobs container. It assumes the
|
| 13 |
# pino source tree has been cloned into /workspace/pino.
|
|
|
|
| 47 |
if registry_path.exists():
|
| 48 |
registry_path = _copy_registry_to_writable(registry_path)
|
| 49 |
os.environ["PINO_REGISTRY_PATH"] = str(registry_path)
|
| 50 |
+
print(f"π PINO_REGISTRY_PATH set to {registry_path}", flush=True)
|
| 51 |
|
| 52 |
|
| 53 |
_prepare_registry()
|
| 54 |
|
| 55 |
+
print("[HF-JOB] About to import torch/pino.train", flush=True)
|
| 56 |
+
|
| 57 |
+
try:
|
| 58 |
+
import torch # noqa: E402
|
| 59 |
+
from pino.train import main as train_main # noqa: E402
|
| 60 |
+
except Exception as exc:
|
| 61 |
+
print(f"[HF-JOB] Import failed: {exc}", flush=True)
|
| 62 |
+
traceback.print_exc()
|
| 63 |
+
sys.exit(1)
|
| 64 |
+
|
| 65 |
+
print("[HF-JOB] Imports completed", flush=True)
|
| 66 |
|
| 67 |
|
| 68 |
def hf_train_5epoch() -> None:
|
|
|
|
| 76 |
# Download the dataset from the canonical dataset repository.
|
| 77 |
from huggingface_hub import hf_hub_download
|
| 78 |
|
| 79 |
+
print("π₯ Downloading empirical v3 dataset from Hugging Face Hub...", flush=True)
|
| 80 |
data_path.parent.mkdir(parents=True, exist_ok=True)
|
| 81 |
downloaded = hf_hub_download(
|
| 82 |
repo_id="mattbitzesty/pino-synthetic-dataset-v3",
|
|
|
|
| 86 |
local_dir=str(data_path.parent),
|
| 87 |
)
|
| 88 |
data_path = Path(downloaded)
|
| 89 |
+
print(f" Dataset downloaded to {data_path}", flush=True)
|
| 90 |
elif not data_path.exists():
|
| 91 |
# Allow the dataset to be mounted elsewhere in the container.
|
| 92 |
data_path = Path("/data/empirical_dataset_v3.jsonl")
|
|
|
|
| 106 |
"--log-dir", str(LOG_DIR),
|
| 107 |
]
|
| 108 |
|
| 109 |
+
print("π HF Job: starting PINO 5-epoch convergence pass", flush=True)
|
| 110 |
+
print(f" Device: {'cuda' if torch.cuda.is_available() else 'cpu'}", flush=True)
|
| 111 |
+
print(f" Args: {' '.join(sys.argv[1:])}", flush=True)
|
| 112 |
|
| 113 |
try:
|
| 114 |
checkpoint_path = train_main()
|
| 115 |
except Exception as exc:
|
| 116 |
+
print(f"β Training failed: {exc}", flush=True)
|
|
|
|
|
|
|
| 117 |
traceback.print_exc()
|
| 118 |
sys.exit(1)
|
| 119 |
|
| 120 |
+
print(f"β
Training complete. Checkpoint: {checkpoint_path}", flush=True)
|
| 121 |
|
| 122 |
# Push checkpoint to the model hub if token is present.
|
| 123 |
if token and checkpoint_path and Path(checkpoint_path).exists():
|
|
|
|
| 127 |
try:
|
| 128 |
create_repo(repo_id, private=True, token=token, exist_ok=True)
|
| 129 |
except Exception as exc: # noqa: BLE001
|
| 130 |
+
print(f"Repo create/exists check: {exc}", flush=True)
|
| 131 |
|
| 132 |
api = HfApi(token=token)
|
| 133 |
api.upload_file(
|
|
|
|
| 136 |
repo_id=repo_id,
|
| 137 |
repo_type="model",
|
| 138 |
)
|
| 139 |
+
print(f"π€ Checkpoint uploaded to https://huggingface.co/{repo_id}", flush=True)
|
| 140 |
|
| 141 |
# Sleep briefly so logs flush.
|
| 142 |
time.sleep(5)
|