hf_train_job: persistent diagnostic log + registry path tracing
Browse files- scripts/hf_train_job.py +57 -17
scripts/hf_train_job.py
CHANGED
|
@@ -6,11 +6,9 @@ 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
|
| 14 |
|
| 15 |
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 16 |
SRC_DIR = REPO_ROOT / "src"
|
|
@@ -20,6 +18,23 @@ sys.path.insert(0, str(SRC_DIR))
|
|
| 20 |
WORKSPACE = Path("/workspace")
|
| 21 |
OUTPUT_DIR = WORKSPACE / "models"
|
| 22 |
LOG_DIR = WORKSPACE / "runs" / "hf_job_5epoch"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def _copy_registry_to_writable(registry_path: Path) -> Path:
|
|
@@ -31,7 +46,7 @@ def _copy_registry_to_writable(registry_path: Path) -> Path:
|
|
| 31 |
return writable_registry
|
| 32 |
import shutil
|
| 33 |
|
| 34 |
-
|
| 35 |
shutil.copy2(registry_path, writable_registry)
|
| 36 |
return writable_registry
|
| 37 |
|
|
@@ -41,28 +56,48 @@ def _prepare_registry() -> None:
|
|
| 41 |
registry_path = Path(
|
| 42 |
os.environ.get("HF_REGISTRY_PATH", REPO_ROOT / "src" / "pino" / "registry.db")
|
| 43 |
)
|
|
|
|
| 44 |
if not registry_path.exists():
|
| 45 |
# Try the mounted dataset location as a fallback.
|
| 46 |
registry_path = Path("/data/registry.db")
|
|
|
|
| 47 |
if registry_path.exists():
|
| 48 |
registry_path = _copy_registry_to_writable(registry_path)
|
| 49 |
os.environ["PINO_REGISTRY_PATH"] = str(registry_path)
|
| 50 |
-
|
| 51 |
|
| 52 |
|
| 53 |
_prepare_registry()
|
| 54 |
|
| 55 |
-
|
| 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 |
-
|
| 62 |
traceback.print_exc()
|
| 63 |
sys.exit(1)
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def hf_train_5epoch() -> None:
|
|
@@ -76,7 +111,7 @@ def hf_train_5epoch() -> None:
|
|
| 76 |
# Download the dataset from the canonical dataset repository.
|
| 77 |
from huggingface_hub import hf_hub_download
|
| 78 |
|
| 79 |
-
|
| 80 |
data_path.parent.mkdir(parents=True, exist_ok=True)
|
| 81 |
downloaded = hf_hub_download(
|
| 82 |
repo_id="mattbitzesty/pino-synthetic-dataset-v3",
|
|
@@ -86,11 +121,13 @@ def hf_train_5epoch() -> None:
|
|
| 86 |
local_dir=str(data_path.parent),
|
| 87 |
)
|
| 88 |
data_path = Path(downloaded)
|
| 89 |
-
|
| 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")
|
| 93 |
|
|
|
|
|
|
|
| 94 |
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 95 |
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 96 |
|
|
@@ -106,18 +143,19 @@ def hf_train_5epoch() -> None:
|
|
| 106 |
"--log-dir", str(LOG_DIR),
|
| 107 |
]
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
try:
|
| 114 |
checkpoint_path = train_main()
|
| 115 |
except Exception as exc:
|
| 116 |
-
|
| 117 |
traceback.print_exc()
|
|
|
|
| 118 |
sys.exit(1)
|
| 119 |
|
| 120 |
-
|
| 121 |
|
| 122 |
# Push checkpoint to the model hub if token is present.
|
| 123 |
if token and checkpoint_path and Path(checkpoint_path).exists():
|
|
@@ -127,7 +165,7 @@ def hf_train_5epoch() -> None:
|
|
| 127 |
try:
|
| 128 |
create_repo(repo_id, private=True, token=token, exist_ok=True)
|
| 129 |
except Exception as exc: # noqa: BLE001
|
| 130 |
-
|
| 131 |
|
| 132 |
api = HfApi(token=token)
|
| 133 |
api.upload_file(
|
|
@@ -136,7 +174,9 @@ def hf_train_5epoch() -> None:
|
|
| 136 |
repo_id=repo_id,
|
| 137 |
repo_type="model",
|
| 138 |
)
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
|
| 141 |
# Sleep briefly so logs flush.
|
| 142 |
time.sleep(5)
|
|
|
|
| 6 |
import traceback
|
| 7 |
from pathlib import Path
|
| 8 |
|
|
|
|
|
|
|
| 9 |
# HF Job entrypoint for the Milestone 4.16 5-epoch convergence run.
|
| 10 |
# This script is executed inside the HF Jobs container. It assumes the
|
| 11 |
+
# pino source tree has been mounted into /workspace/pino.
|
| 12 |
|
| 13 |
REPO_ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
SRC_DIR = REPO_ROOT / "src"
|
|
|
|
| 18 |
WORKSPACE = Path("/workspace")
|
| 19 |
OUTPUT_DIR = WORKSPACE / "models"
|
| 20 |
LOG_DIR = WORKSPACE / "runs" / "hf_job_5epoch"
|
| 21 |
+
DIAG_LOG = WORKSPACE / "hf_train.log"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _log(msg: str) -> None:
|
| 25 |
+
"""Write to both stdout and a persistent diagnostic log file."""
|
| 26 |
+
line = f"{time.strftime('%Y-%m-%dT%H:%M:%SZ')} {msg}"
|
| 27 |
+
print(line, flush=True)
|
| 28 |
+
try:
|
| 29 |
+
WORKSPACE.mkdir(parents=True, exist_ok=True)
|
| 30 |
+
with open(DIAG_LOG, "a", encoding="utf-8") as f:
|
| 31 |
+
f.write(line + "\n")
|
| 32 |
+
f.flush()
|
| 33 |
+
except Exception as exc: # noqa: BLE001
|
| 34 |
+
print(f"[LOG-FAIL] {exc}", flush=True)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
_log("[HF-JOB] hf_train_job.py top-level started")
|
| 38 |
|
| 39 |
|
| 40 |
def _copy_registry_to_writable(registry_path: Path) -> Path:
|
|
|
|
| 46 |
return writable_registry
|
| 47 |
import shutil
|
| 48 |
|
| 49 |
+
_log(f"π¦ Copying registry from {registry_path} to writable {writable_registry}")
|
| 50 |
shutil.copy2(registry_path, writable_registry)
|
| 51 |
return writable_registry
|
| 52 |
|
|
|
|
| 56 |
registry_path = Path(
|
| 57 |
os.environ.get("HF_REGISTRY_PATH", REPO_ROOT / "src" / "pino" / "registry.db")
|
| 58 |
)
|
| 59 |
+
_log(f"[REGISTRY] initial path: {registry_path} (exists={registry_path.exists()})")
|
| 60 |
if not registry_path.exists():
|
| 61 |
# Try the mounted dataset location as a fallback.
|
| 62 |
registry_path = Path("/data/registry.db")
|
| 63 |
+
_log(f"[REGISTRY] fallback path: {registry_path} (exists={registry_path.exists()})")
|
| 64 |
if registry_path.exists():
|
| 65 |
registry_path = _copy_registry_to_writable(registry_path)
|
| 66 |
os.environ["PINO_REGISTRY_PATH"] = str(registry_path)
|
| 67 |
+
_log(f"π PINO_REGISTRY_PATH set to {registry_path}")
|
| 68 |
|
| 69 |
|
| 70 |
_prepare_registry()
|
| 71 |
|
| 72 |
+
_log("[HF-JOB] About to import torch/pino.train")
|
| 73 |
|
| 74 |
try:
|
| 75 |
import torch # noqa: E402
|
| 76 |
from pino.train import main as train_main # noqa: E402
|
| 77 |
except Exception as exc:
|
| 78 |
+
_log(f"[HF-JOB] Import failed: {exc}")
|
| 79 |
traceback.print_exc()
|
| 80 |
sys.exit(1)
|
| 81 |
|
| 82 |
+
_log("[HF-JOB] Imports completed")
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _upload_log(token: str | None) -> None:
|
| 86 |
+
"""Upload the diagnostic log to the dataset repo so it survives container exit."""
|
| 87 |
+
if not token or not DIAG_LOG.exists():
|
| 88 |
+
return
|
| 89 |
+
try:
|
| 90 |
+
from huggingface_hub import HfApi
|
| 91 |
+
|
| 92 |
+
HfApi(token=token).upload_file(
|
| 93 |
+
path_or_fileobj=str(DIAG_LOG),
|
| 94 |
+
path_in_repo="hf_train.log",
|
| 95 |
+
repo_id="mattbitzesty/pino-synthetic-dataset-v3",
|
| 96 |
+
repo_type="dataset",
|
| 97 |
+
)
|
| 98 |
+
_log("[HF-JOB] Diagnostic log uploaded")
|
| 99 |
+
except Exception as exc: # noqa: BLE001
|
| 100 |
+
_log(f"[HF-JOB] Log upload failed: {exc}")
|
| 101 |
|
| 102 |
|
| 103 |
def hf_train_5epoch() -> None:
|
|
|
|
| 111 |
# Download the dataset from the canonical dataset repository.
|
| 112 |
from huggingface_hub import hf_hub_download
|
| 113 |
|
| 114 |
+
_log("π₯ Downloading empirical v3 dataset from Hugging Face Hub...")
|
| 115 |
data_path.parent.mkdir(parents=True, exist_ok=True)
|
| 116 |
downloaded = hf_hub_download(
|
| 117 |
repo_id="mattbitzesty/pino-synthetic-dataset-v3",
|
|
|
|
| 121 |
local_dir=str(data_path.parent),
|
| 122 |
)
|
| 123 |
data_path = Path(downloaded)
|
| 124 |
+
_log(f" Dataset downloaded to {data_path}")
|
| 125 |
elif not data_path.exists():
|
| 126 |
# Allow the dataset to be mounted elsewhere in the container.
|
| 127 |
data_path = Path("/data/empirical_dataset_v3.jsonl")
|
| 128 |
|
| 129 |
+
_log(f"[HF-JOB] Final data path: {data_path} (exists={data_path.exists()})")
|
| 130 |
+
|
| 131 |
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 132 |
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 133 |
|
|
|
|
| 143 |
"--log-dir", str(LOG_DIR),
|
| 144 |
]
|
| 145 |
|
| 146 |
+
_log("π HF Job: starting PINO 5-epoch convergence pass")
|
| 147 |
+
_log(f" Device: {'cuda' if torch.cuda.is_available() else 'cpu'}")
|
| 148 |
+
_log(f" Args: {' '.join(sys.argv[1:])}")
|
| 149 |
|
| 150 |
try:
|
| 151 |
checkpoint_path = train_main()
|
| 152 |
except Exception as exc:
|
| 153 |
+
_log(f"β Training failed: {exc}")
|
| 154 |
traceback.print_exc()
|
| 155 |
+
_upload_log(token)
|
| 156 |
sys.exit(1)
|
| 157 |
|
| 158 |
+
_log(f"β
Training complete. Checkpoint: {checkpoint_path}")
|
| 159 |
|
| 160 |
# Push checkpoint to the model hub if token is present.
|
| 161 |
if token and checkpoint_path and Path(checkpoint_path).exists():
|
|
|
|
| 165 |
try:
|
| 166 |
create_repo(repo_id, private=True, token=token, exist_ok=True)
|
| 167 |
except Exception as exc: # noqa: BLE001
|
| 168 |
+
_log(f"Repo create/exists check: {exc}")
|
| 169 |
|
| 170 |
api = HfApi(token=token)
|
| 171 |
api.upload_file(
|
|
|
|
| 174 |
repo_id=repo_id,
|
| 175 |
repo_type="model",
|
| 176 |
)
|
| 177 |
+
_log(f"π€ Checkpoint uploaded to https://huggingface.co/{repo_id}")
|
| 178 |
+
|
| 179 |
+
_upload_log(token)
|
| 180 |
|
| 181 |
# Sleep briefly so logs flush.
|
| 182 |
time.sleep(5)
|