mattbitzesty commited on
Commit
9673bb8
·
unverified ·
1 Parent(s): f0a181f

hf_train_job: revert to mount-based writable registry pattern from v3

Browse files
Files changed (1) hide show
  1. scripts/hf_train_job.py +31 -53
scripts/hf_train_job.py CHANGED
@@ -1,25 +1,28 @@
1
  from __future__ import annotations
2
 
3
  import os
 
4
  import sys
5
  import time
6
  import traceback
7
  from pathlib import Path
8
 
9
  # HF Job entrypoint for the v4 training run.
10
- # This script is executed inside the HF Jobs container. It pulls fresh source
11
- # and a fresh dataset into a writable workspace, then trains and uploads.
 
 
12
 
13
- import shutil
14
- from huggingface_hub import snapshot_download, HfApi, create_repo
15
 
16
  TOKEN = os.environ.get("HF_TOKEN")
17
  WORKSPACE = Path("/workspace")
18
  OUTPUT_DIR = WORKSPACE / "models"
19
  LOG_DIR = WORKSPACE / "runs" / "hf_job_5epoch"
20
  DIAG_LOG = WORKSPACE / "hf_train.log"
21
- PINOSRC = WORKSPACE / "pino"
22
- DATA_DIR = WORKSPACE / "data"
 
23
 
24
 
25
  def _log(msg: str) -> None:
@@ -50,58 +53,29 @@ def _upload_log() -> None:
50
  _log(f"[HF-JOB] Log upload failed: {exc}")
51
 
52
 
53
- def _pull_source() -> None:
54
- if PINOSRC.exists():
55
- shutil.rmtree(PINOSRC)
56
- PINOSRC.parent.mkdir(parents=True, exist_ok=True)
57
- _log("[HF-JOB] Downloading fresh source code...")
58
- snapshot_download(
59
- repo_id="mattbitzesty/pino-source-code",
60
- local_dir=str(PINOSRC),
61
- repo_type="model",
62
- token=TOKEN,
63
- )
64
- _log(f"[HF-JOB] Source downloaded to {PINOSRC}")
65
-
66
-
67
- def _pull_data() -> Path:
68
- DATA_DIR.mkdir(parents=True, exist_ok=True)
69
- data_path = DATA_DIR / "empirical_dataset_v3.jsonl"
70
- if not data_path.exists():
71
- _log("[HF-JOB] Downloading v3 dataset...")
72
- snapshot_download(
73
- repo_id="mattbitzesty/pino-synthetic-dataset-v3",
74
- local_dir=str(DATA_DIR),
75
- repo_type="dataset",
76
- token=TOKEN,
77
- allow_patterns=["empirical_dataset_v3.jsonl", "registry.db"],
78
- )
79
- _log(f"[HF-JOB] Dataset downloaded to {data_path}")
80
- return data_path
81
-
82
-
83
  _log("[HF-JOB] hf_train_job.py started")
 
84
 
85
- try:
86
- _pull_source()
87
- data_path = _pull_data()
88
- except Exception as exc:
89
- _log(f"[HF-JOB] Download failed: {exc}")
90
- traceback.print_exc()
91
  _upload_log()
92
  sys.exit(1)
93
 
94
- # Set registry path to writable copy before any pino imports.
95
- registry_src = DATA_DIR / "registry.db"
96
- registry_dst = WORKSPACE / "registry.db"
97
- if registry_src.exists() and not registry_dst.exists():
98
- shutil.copy2(registry_src, registry_dst)
99
- if not registry_dst.exists():
100
- _log(f"[HF-JOB] WARNING: no writable registry at {registry_dst}")
101
- os.environ["PINO_REGISTRY_PATH"] = str(registry_dst)
102
- _log(f"[HF-JOB] PINO_REGISTRY_PATH={registry_dst}")
103
-
104
- SRC_DIR = PINOSRC / "src"
 
 
 
 
105
  sys.path.insert(0, str(SRC_DIR))
106
 
107
  _log("[HF-JOB] About to import torch/pino.train")
@@ -117,6 +91,10 @@ except Exception as exc:
117
 
118
  _log("[HF-JOB] Imports completed")
119
 
 
 
 
 
120
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
121
  LOG_DIR.mkdir(parents=True, exist_ok=True)
122
 
 
1
  from __future__ import annotations
2
 
3
  import os
4
+ import shutil
5
  import sys
6
  import time
7
  import traceback
8
  from pathlib import Path
9
 
10
  # HF Job entrypoint for the v4 training run.
11
+ # This script is executed inside the HF Jobs container. It expects the source
12
+ # code to be mounted at /workspace/pino and the dataset+registry to be
13
+ # available at /data (via an HF dataset volume mount). The source mount is
14
+ # read-only, so all outputs go to /workspace.
15
 
16
+ from huggingface_hub import HfApi, create_repo
 
17
 
18
  TOKEN = os.environ.get("HF_TOKEN")
19
  WORKSPACE = Path("/workspace")
20
  OUTPUT_DIR = WORKSPACE / "models"
21
  LOG_DIR = WORKSPACE / "runs" / "hf_job_5epoch"
22
  DIAG_LOG = WORKSPACE / "hf_train.log"
23
+
24
+ REPO_ROOT = Path("/workspace/pino")
25
+ SRC_DIR = REPO_ROOT / "src"
26
 
27
 
28
  def _log(msg: str) -> None:
 
53
  _log(f"[HF-JOB] Log upload failed: {exc}")
54
 
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  _log("[HF-JOB] hf_train_job.py started")
57
+ _log(f"[HF-JOB] Source mount: {REPO_ROOT} (exists={REPO_ROOT.exists()})")
58
 
59
+ if not REPO_ROOT.exists():
60
+ _log("[HF-JOB] FATAL: source mount /workspace/pino not found")
 
 
 
 
61
  _upload_log()
62
  sys.exit(1)
63
 
64
+ # Ensure the registry is writable before any pino imports.
65
+ registry_path = Path(os.environ.get("HF_REGISTRY_PATH", "/data/registry.db"))
66
+ _log(f"[HF-JOB] Registry input: {registry_path} (exists={registry_path.exists()})")
67
+ if registry_path.exists():
68
+ writable_registry = WORKSPACE / "registry.db"
69
+ if not writable_registry.exists():
70
+ shutil.copy2(registry_path, writable_registry)
71
+ _log(f"[HF-JOB] Copied registry to writable {writable_registry}")
72
+ os.environ["PINO_REGISTRY_PATH"] = str(writable_registry)
73
+ else:
74
+ _log("[HF-JOB] WARNING: registry input not found; using default")
75
+ os.environ.setdefault("PINO_REGISTRY_PATH", "/workspace/registry.db")
76
+
77
+ _log(f"[HF-JOB] PINO_REGISTRY_PATH={os.environ['PINO_REGISTRY_PATH']}")
78
+
79
  sys.path.insert(0, str(SRC_DIR))
80
 
81
  _log("[HF-JOB] About to import torch/pino.train")
 
91
 
92
  _log("[HF-JOB] Imports completed")
93
 
94
+ # Resolve data path.
95
+ data_path = Path(os.environ.get("HF_DATA_PATH", "/data/empirical_dataset_v3.jsonl"))
96
+ _log(f"[HF-JOB] Final data path: {data_path} (exists={data_path.exists()})")
97
+
98
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
99
  LOG_DIR.mkdir(parents=True, exist_ok=True)
100