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

hf_train_job: lazy-import huggingface_hub to match v3 pattern

Browse files
Files changed (1) hide show
  1. scripts/hf_train_job.py +14 -11
scripts/hf_train_job.py CHANGED
@@ -13,8 +13,6 @@ from pathlib import Path
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"
@@ -42,6 +40,8 @@ def _upload_log() -> None:
42
  if not TOKEN or not DIAG_LOG.exists():
43
  return
44
  try:
 
 
45
  HfApi(token=TOKEN).upload_file(
46
  path_or_fileobj=str(DIAG_LOG),
47
  path_in_repo="hf_train.log",
@@ -126,18 +126,21 @@ _log(f"✅ Training complete. Checkpoint: {checkpoint_path}")
126
 
127
  if TOKEN and checkpoint_path and Path(checkpoint_path).exists():
128
  repo_id = "mattbitzesty/pino-pimt-checkpoint"
 
129
  try:
 
 
130
  create_repo(repo_id, private=True, token=TOKEN, exist_ok=True)
 
 
 
 
 
 
 
131
  except Exception as exc: # noqa: BLE001
132
- _log(f"Repo create/exists check: {exc}")
133
- _log(f"[HF-JOB] Uploading {checkpoint_path} to {repo_id} as pimt_v4.pt")
134
- HfApi(token=TOKEN).upload_file(
135
- path_or_fileobj=str(checkpoint_path),
136
- path_in_repo="pimt_v4.pt",
137
- repo_id=repo_id,
138
- repo_type="model",
139
- )
140
- _log(f"🤗 Checkpoint uploaded to https://huggingface.co/{repo_id}")
141
  else:
142
  _log(f"[HF-JOB] Skipping upload: token={bool(TOKEN)} checkpoint_path={checkpoint_path} exists={Path(checkpoint_path).exists() if checkpoint_path else None}")
143
 
 
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"
 
40
  if not TOKEN or not DIAG_LOG.exists():
41
  return
42
  try:
43
+ from huggingface_hub import HfApi
44
+
45
  HfApi(token=TOKEN).upload_file(
46
  path_or_fileobj=str(DIAG_LOG),
47
  path_in_repo="hf_train.log",
 
126
 
127
  if TOKEN and checkpoint_path and Path(checkpoint_path).exists():
128
  repo_id = "mattbitzesty/pino-pimt-checkpoint"
129
+ _log(f"[HF-JOB] Uploading {checkpoint_path} to {repo_id} as pimt_v4.pt")
130
  try:
131
+ from huggingface_hub import HfApi, create_repo
132
+
133
  create_repo(repo_id, private=True, token=TOKEN, exist_ok=True)
134
+ HfApi(token=TOKEN).upload_file(
135
+ path_or_fileobj=str(checkpoint_path),
136
+ path_in_repo="pimt_v4.pt",
137
+ repo_id=repo_id,
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:
145
  _log(f"[HF-JOB] Skipping upload: token={bool(TOKEN)} checkpoint_path={checkpoint_path} exists={Path(checkpoint_path).exists() if checkpoint_path else None}")
146