Akahsizrr commited on
Commit
fef9a51
·
verified ·
1 Parent(s): 9d3ce14

Delete code/upload_watch.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. code/upload_watch.py +0 -73
code/upload_watch.py DELETED
@@ -1,73 +0,0 @@
1
- """Run on pod-1: watch checkpoint dirs and push the current-best head ckpt
2
- to HF so the dev pod can pull + eval it.
3
- Pushes:
4
- - newest spec_v8/c*/best.pt -> spec_v8/best.pt (curriculum champion)
5
- - spec_v7b/best.pt -> spec_v7b/best.pt (legacy run)
6
- Usage: nohup python3 upload_watch.py > /root/upload_watch.log 2>&1 &
7
- """
8
- import os, time, subprocess, glob
9
-
10
- HF = "/root/spec100m/hf_io.py"
11
- LOG = "/root/upload_watch.log"
12
- sigs = {}
13
-
14
-
15
- def log(m):
16
- line = f"[{time.strftime('%H:%M:%S')}] {m}"
17
- print(line, flush=True)
18
- open(LOG, "a").write(line + "\n")
19
-
20
-
21
- def newest(pattern):
22
- fs = glob.glob(pattern)
23
- return max(fs, key=os.path.getmtime) if fs else None
24
-
25
-
26
- def push_if_changed(src, repo_path):
27
- if not src or not os.path.exists(src):
28
- return
29
- sig = str(os.path.getsize(src)) + str(int(os.path.getmtime(src)))
30
- if sigs.get(repo_path) == sig:
31
- return
32
- time.sleep(10) # let any write finish
33
- if "base_" in src:
34
- # base checkpoints carry the full model — upload whole (the base
35
- # weights ARE the update; spec-stripping would drop them)
36
- pass
37
- else:
38
- # upload spec_* params only (~250MB vs 924MB) — the base weights are
39
- # already on HF as base_500m/final.pt; the watcher merges them.
40
- import torch
41
- try:
42
- sd = torch.load(src, map_location="cpu")
43
- spec_sd = {k: v for k, v in sd["model"].items()
44
- if k.startswith("spec_")}
45
- tmp = f"/tmp/_spec_only_{os.path.basename(repo_path)}"
46
- torch.save({"model": spec_sd, "cfg": sd.get("cfg"),
47
- "step": sd.get("step"), "spec_only": True}, tmp)
48
- src = tmp
49
- except Exception as e:
50
- log(f"spec-strip failed {src}: {e}")
51
- return
52
- r = subprocess.run(
53
- ["python3", HF, "push", src, repo_path],
54
- capture_output=True, text=True, timeout=1200)
55
- ok = "uploaded" in r.stdout
56
- log(f"{repo_path}: {'uploaded' if ok else 'fail ' + (r.stdout+r.stderr)[-200:]}")
57
- if ok:
58
- sigs[repo_path] = sig
59
-
60
-
61
- while True:
62
- try:
63
- push_if_changed(newest("/root/checkpoints/spec_v8/c*/best.pt"),
64
- "spec_v8/best.pt")
65
- push_if_changed(newest("/root/checkpoints/spec_seq*/best.pt"),
66
- "spec_seq/best.pt")
67
- push_if_changed(newest("/root/checkpoints/base_1b/best.pt"),
68
- "base_1b/best.pt")
69
- push_if_changed("/root/checkpoints/spec_v7b/best.pt",
70
- "spec_v7b/best.pt")
71
- except Exception as e:
72
- log(f"err: {e}")
73
- time.sleep(120)