Maggio33 commited on
Commit
1a298ca
·
verified ·
1 Parent(s): eef1515

Upload ckpt_autopush.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. ckpt_autopush.py +57 -0
ckpt_autopush.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Auto-upload each new training checkpoint to HF so the maintainer can bench
3
+ the latest weights during training. Watches the trainer log for `ckpt @ <step>`
4
+ lines (emitted right after the save completes), copies ckpt.pt to a step-tagged
5
+ name, and uploads it to SlayerLab/gollem-v5-ckpts/<subdir>/.
6
+
7
+ Usage: python ckpt_autopush.py TRAIN_LOG CKPT_PATH HF_SUBDIR
8
+ e.g. python ckpt_autopush.py train_64m_v2.log run_64m_v2/ckpt.pt v2_muon
9
+ """
10
+ import os
11
+ import shutil
12
+ import sys
13
+ import time
14
+
15
+ from huggingface_hub import HfApi
16
+
17
+ logf = sys.argv[1]
18
+ ckpt_path = sys.argv[2]
19
+ subdir = sys.argv[3]
20
+ repo = "SlayerLab/gollem-v5-ckpts"
21
+ api = HfApi()
22
+
23
+ seen = set()
24
+ # Seed already-uploaded tags so a restart does not re-push existing ckpts.
25
+ try:
26
+ existing = {f.split("/")[-1] for f in api.list_repo_files(repo) if f.startswith(subdir + "/")}
27
+ except Exception:
28
+ existing = set()
29
+
30
+ print(f"[ckpt_autopush] watching {logf} -> {repo}/{subdir}/ (existing={len(existing)})", flush=True)
31
+ while True:
32
+ try:
33
+ steps = [ln.split("@", 1)[1].strip() for ln in open(logf, encoding="utf-8", errors="ignore")
34
+ if "ckpt @" in ln]
35
+ except FileNotFoundError:
36
+ time.sleep(30)
37
+ continue
38
+ for s in steps:
39
+ if not s.isdigit() or s in seen:
40
+ continue
41
+ seen.add(s)
42
+ tag = f"ckpt_{int(s) // 1000}k.pt"
43
+ if tag in existing:
44
+ continue
45
+ if not os.path.exists(ckpt_path):
46
+ continue
47
+ local = os.path.join(os.path.dirname(ckpt_path) or ".", tag)
48
+ try:
49
+ shutil.copyfile(ckpt_path, local)
50
+ api.upload_file(path_or_fileobj=local, path_in_repo=f"{subdir}/{tag}",
51
+ repo_id=repo, commit_message=f"auto ckpt {s}")
52
+ existing.add(tag)
53
+ print(f"[ckpt_autopush] uploaded {subdir}/{tag} (step {s})", flush=True)
54
+ except Exception as e:
55
+ print(f"[ckpt_autopush] upload {tag} failed: {e!r}", flush=True)
56
+ seen.discard(s) # retry next cycle
57
+ time.sleep(60)