mattbitzesty commited on
Commit
c93892a
·
unverified ·
1 Parent(s): 0972f6a

hf_train_job: use snapshot_download (v1/v3 working pattern)

Browse files
Files changed (1) hide show
  1. scripts/hf_train_job.py +57 -13
scripts/hf_train_job.py CHANGED
@@ -8,19 +8,18 @@ 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
  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
 
22
- REPO_ROOT = Path("/workspace/pino")
23
- SRC_DIR = REPO_ROOT / "src"
24
 
25
 
26
  def _log(msg: str) -> None:
@@ -54,15 +53,43 @@ def _upload_log() -> None:
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"
@@ -76,6 +103,23 @@ else:
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")
@@ -92,7 +136,7 @@ except Exception as exc:
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)
@@ -138,7 +182,7 @@ if TOKEN and checkpoint_path and Path(checkpoint_path).exists():
138
  repo_type="model",
139
  )
140
  _log(f"🤗 Checkpoint uploaded to https://huggingface.co/{repo_id}")
141
- except Exception as exc: # noqa: BLE001
142
  _log(f"[HF-JOB] Upload failed: {exc}")
143
  traceback.print_exc()
144
  else:
 
8
  from pathlib import Path
9
 
10
  # HF Job entrypoint for the v4 training run.
11
+ # Uses snapshot_download to pull fresh source and dataset into a writable
12
+ # workspace, avoiding stale/cached model-volume mounts.
 
 
13
 
14
  TOKEN = os.environ.get("HF_TOKEN")
15
  WORKSPACE = Path("/workspace")
16
+ SOURCE_DIR = WORKSPACE / "pino-fresh"
17
+ DATASET_DIR = WORKSPACE / "pino-dataset"
18
  OUTPUT_DIR = WORKSPACE / "models"
19
+ LOG_DIR = WORKSPACE / "runs" / "hf_job_v4"
20
  DIAG_LOG = WORKSPACE / "hf_train.log"
21
 
22
+ SRC_DIR = SOURCE_DIR / "src"
 
23
 
24
 
25
  def _log(msg: str) -> None:
 
53
 
54
 
55
  _log("[HF-JOB] hf_train_job.py started")
 
56
 
57
+ # Download fresh source and dataset into writable workspace.
58
+ try:
59
+ from huggingface_hub import snapshot_download
60
+
61
+ _log("[HF-JOB] Downloading fresh source from mattbitzesty/pino-source-code")
62
+ SOURCE_DIR.mkdir(parents=True, exist_ok=True)
63
+ snapshot_download(
64
+ repo_id="mattbitzesty/pino-source-code",
65
+ repo_type="model",
66
+ local_dir=str(SOURCE_DIR),
67
+ token=TOKEN,
68
+ )
69
+ _log(f"[HF-JOB] Source downloaded to {SOURCE_DIR}")
70
+
71
+ _log("[HF-JOB] Downloading fresh dataset from mattbitzesty/pino-synthetic-dataset-v3")
72
+ DATASET_DIR.mkdir(parents=True, exist_ok=True)
73
+ snapshot_download(
74
+ repo_id="mattbitzesty/pino-synthetic-dataset-v3",
75
+ repo_type="dataset",
76
+ local_dir=str(DATASET_DIR),
77
+ token=TOKEN,
78
+ )
79
+ _log(f"[HF-JOB] Dataset downloaded to {DATASET_DIR}")
80
+ except Exception as exc:
81
+ _log(f"[HF-JOB] Download failed: {exc}")
82
+ traceback.print_exc()
83
+ _upload_log()
84
+ sys.exit(1)
85
+
86
+ if not SRC_DIR.exists():
87
+ _log("[HF-JOB] FATAL: source directory not found after download")
88
  _upload_log()
89
  sys.exit(1)
90
 
91
  # Ensure the registry is writable before any pino imports.
92
+ registry_path = DATASET_DIR / "registry.db"
93
  _log(f"[HF-JOB] Registry input: {registry_path} (exists={registry_path.exists()})")
94
  if registry_path.exists():
95
  writable_registry = WORKSPACE / "registry.db"
 
103
 
104
  _log(f"[HF-JOB] PINO_REGISTRY_PATH={os.environ['PINO_REGISTRY_PATH']}")
105
 
106
+ # Install the freshly downloaded source.
107
+ _log("[HF-JOB] Installing pino from fresh source")
108
+ try:
109
+ import subprocess
110
+
111
+ subprocess.check_call(
112
+ [sys.executable, "-m", "pip", "install", "-e", str(SOURCE_DIR)],
113
+ stdout=sys.stdout,
114
+ stderr=sys.stderr,
115
+ )
116
+ _log("[HF-JOB] pip install completed")
117
+ except Exception as exc:
118
+ _log(f"[HF-JOB] pip install failed: {exc}")
119
+ traceback.print_exc()
120
+ _upload_log()
121
+ sys.exit(1)
122
+
123
  sys.path.insert(0, str(SRC_DIR))
124
 
125
  _log("[HF-JOB] About to import torch/pino.train")
 
136
  _log("[HF-JOB] Imports completed")
137
 
138
  # Resolve data path.
139
+ data_path = DATASET_DIR / "empirical_dataset_v3.jsonl"
140
  _log(f"[HF-JOB] Final data path: {data_path} (exists={data_path.exists()})")
141
 
142
  OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
 
182
  repo_type="model",
183
  )
184
  _log(f"🤗 Checkpoint uploaded to https://huggingface.co/{repo_id}")
185
+ except Exception as exc:
186
  _log(f"[HF-JOB] Upload failed: {exc}")
187
  traceback.print_exc()
188
  else: