Upload train/train_ounce100m.py with huggingface_hub
Browse files- train/train_ounce100m.py +23 -4
train/train_ounce100m.py
CHANGED
|
@@ -322,8 +322,21 @@ def main():
|
|
| 322 |
tk = os.environ.get("HF_TOKEN")
|
| 323 |
ptr = hubckpt.latest_pointer(args.hub_repo, repo_type=args.hub_repo_type, token=tk)
|
| 324 |
if ptr.get("not_found"):
|
| 325 |
-
# A 404 is a fact
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
args.resume = ""
|
| 328 |
elif "error" in ptr:
|
| 329 |
# Anything else (401, timeout, DNS) means the lookup failed, not that there is nothing there.
|
|
@@ -331,7 +344,13 @@ def main():
|
|
| 331 |
# exactly the §3.1 violation this whole branch exists to prevent (E-018's shape).
|
| 332 |
raise SystemExit(f"--resume auto could not read the hub pointer: {ptr['error']}")
|
| 333 |
else:
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
say(f"auto-resume: hub says step {ptr.get('step')} at {ptr['path_in_repo']}")
|
| 336 |
got = hubckpt.download_checkpoint(args.hub_repo, ptr["path_in_repo"], dest, HfApi(),
|
| 337 |
repo_type=args.hub_repo_type, token=tk)
|
|
@@ -374,7 +393,7 @@ def main():
|
|
| 374 |
vstore = SD.PackedTokenStore(args.root, man, files=vs)
|
| 375 |
n_val = min(max(1, args.val_tokens // args.seq_len), vstore.total_tokens // args.seq_len)
|
| 376 |
val_ds = SD.make_dataset(vstore, args.seq_len, args.data_seed, shuffle=False, count=n_val)
|
| 377 |
-
need = steps_planned * seqs_per_step
|
| 378 |
if len(train_ds) < need:
|
| 379 |
# Reading past the end of the stream makes the Trainer begin epoch 2 at the top of the same
|
| 380 |
# permutation: the run would then report the full token target while quietly re-training on the
|
|
|
|
| 322 |
tk = os.environ.get("HF_TOKEN")
|
| 323 |
ptr = hubckpt.latest_pointer(args.hub_repo, repo_type=args.hub_repo_type, token=tk)
|
| 324 |
if ptr.get("not_found"):
|
| 325 |
+
# A 404 is normally a fact -- "this run has never checkpointed" -- and step 0 is then right.
|
| 326 |
+
# But a missing pointer beside existing checkpoints means the pointer upload failed after a
|
| 327 |
+
# good checkpoint, and starting from zero would silently retrain the corpus from the top,
|
| 328 |
+
# which §3.1 forbids and E-018 is about. So list the repo before believing the 404.
|
| 329 |
+
try:
|
| 330 |
+
listed = sorted(k for k in hubckpt.hub_listing(args.hub_repo, args.hub_repo_type,
|
| 331 |
+
token=tk)
|
| 332 |
+
if k.startswith("ckpt/checkpoint-"))
|
| 333 |
+
except Exception as e:
|
| 334 |
+
listed = [f"<listing failed: {type(e).__name__}>"]
|
| 335 |
+
if listed:
|
| 336 |
+
raise SystemExit(f"--resume auto found no latest.json on {args.hub_repo}, but the repo "
|
| 337 |
+
f"holds {len(listed)} checkpoint path(s) ({listed[:3]}). The pointer is "
|
| 338 |
+
"missing, not the run -- refusing to start from step 0.")
|
| 339 |
+
say(f"no latest.json and no checkpoints on {args.hub_repo} -> starting from step 0")
|
| 340 |
args.resume = ""
|
| 341 |
elif "error" in ptr:
|
| 342 |
# Anything else (401, timeout, DNS) means the lookup failed, not that there is nothing there.
|
|
|
|
| 344 |
# exactly the §3.1 violation this whole branch exists to prevent (E-018's shape).
|
| 345 |
raise SystemExit(f"--resume auto could not read the hub pointer: {ptr['error']}")
|
| 346 |
else:
|
| 347 |
+
# Both ranks need the checkpoint on disk, and this block runs before TrainingArguments has
|
| 348 |
+
# created a process group -- so there is no barrier to synchronise on. Downloading into a
|
| 349 |
+
# per-rank directory instead removes the race entirely (two writers, one path), at the cost of
|
| 350 |
+
# a second 1.7 GB pull that happens in parallel. Each rank then reads its own verified copy and
|
| 351 |
+
# derives the same start_sample/start_step from the same cursor.json bytes.
|
| 352 |
+
dest = os.path.join(args.out, f"resume_r{rank}",
|
| 353 |
+
os.path.basename(ptr["path_in_repo"]))
|
| 354 |
say(f"auto-resume: hub says step {ptr.get('step')} at {ptr['path_in_repo']}")
|
| 355 |
got = hubckpt.download_checkpoint(args.hub_repo, ptr["path_in_repo"], dest, HfApi(),
|
| 356 |
repo_type=args.hub_repo_type, token=tk)
|
|
|
|
| 393 |
vstore = SD.PackedTokenStore(args.root, man, files=vs)
|
| 394 |
n_val = min(max(1, args.val_tokens // args.seq_len), vstore.total_tokens // args.seq_len)
|
| 395 |
val_ds = SD.make_dataset(vstore, args.seq_len, args.data_seed, shuffle=False, count=n_val)
|
| 396 |
+
need = (steps_planned - start_step) * seqs_per_step
|
| 397 |
if len(train_ds) < need:
|
| 398 |
# Reading past the end of the stream makes the Trainer begin epoch 2 at the top of the same
|
| 399 |
# permutation: the run would then report the full token target while quietly re-training on the
|