capotej commited on
Commit
db7b60b
·
verified ·
1 Parent(s): bc02ff2

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. WRITETEST +1 -0
  2. hf_backup.py +33 -0
WRITETEST ADDED
@@ -0,0 +1 @@
 
 
1
+ hf write ok
hf_backup.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Background watcher: push the latest training checkpoint + log to the HF Hub
2
+ whenever the checkpoint changes (throttled). Run in tmux alongside training so
3
+ checkpoints survive pre-emption without SCP/laptop. Resume anywhere via hf_hub_download.
4
+
5
+ HF_TOKEN=... HF_CKPT_REPO=capotej/WikipediaGutenberg-0.5B \
6
+ HF_CKPT_PATH=/root/nanoGPT/out-wiki-gutenberg-530m-1ep/ckpt.pt \
7
+ HF_CKPT_LOG=/root/nanoGPT/train.log python hf_backup.py
8
+ """
9
+ import os, time
10
+ from huggingface_hub import HfApi
11
+
12
+ REPO = os.environ["HF_CKPT_REPO"]
13
+ CKPT = os.environ.get("HF_CKPT_PATH", "out-wiki-gutenberg-530m-1ep/ckpt.pt")
14
+ LOG = os.environ.get("HF_CKPT_LOG", "train.log")
15
+ MIN_INT = int(os.environ.get("HF_MIN_INTERVAL", "1800")) # throttle: >=30 min between pushes
16
+
17
+ api = HfApi(token=os.environ["HF_TOKEN"])
18
+ api.create_repo(REPO, private=False, exist_ok=True) # public repo
19
+ last_m, last_up = 0, 0
20
+ while True:
21
+ try:
22
+ if not os.path.exists(CKPT):
23
+ time.sleep(60); continue
24
+ m = os.path.getmtime(CKPT); now = time.time()
25
+ if m != last_m and now - last_up >= MIN_INT:
26
+ api.upload_file(path_or_fileobj=CKPT, path_in_repo="ckpt.pt", repo_id=REPO)
27
+ try: api.upload_file(path_or_fileobj=LOG, path_in_repo="train.log", repo_id=REPO)
28
+ except Exception: pass
29
+ last_m, last_up = m, now
30
+ print(f"[{time.ctime()}] pushed ckpt.pt + train.log -> {REPO}", flush=True)
31
+ except Exception as e:
32
+ print(f"[{time.ctime()}] upload error: {e}", flush=True)
33
+ time.sleep(60)