thefinalboss commited on
Commit
bac0aaf
·
verified ·
1 Parent(s): 7cd8261

Upload scripts/hf_push_x8.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/hf_push_x8.py +51 -0
scripts/hf_push_x8.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import os, time, json
3
+ from pathlib import Path
4
+ from huggingface_hub import HfApi
5
+
6
+ TOKEN = os.environ["HF_TOKEN"]
7
+ REPO = 'thefinalboss/fractus-cte'
8
+ CKPT_DIR = Path('/workspace/fractus-p0/checkpoints')
9
+ STATE = Path('/workspace/hf_push_state.json')
10
+ api = HfApi(token=TOKEN)
11
+
12
+ def load_state():
13
+ if STATE.exists():
14
+ return json.loads(STATE.read_text())
15
+ return {}
16
+
17
+ def save_state(s):
18
+ STATE.write_text(json.dumps(s))
19
+
20
+ def once():
21
+ st = load_state()
22
+ uploaded = []
23
+ for i in range(8):
24
+ p = CKPT_DIR / f'fractus_1b_gpu{i}_live.pt'
25
+ if not p.exists() or p.stat().st_size < 1_000_000_000:
26
+ continue
27
+ key = f'gpu{i}'
28
+ mtime = p.stat().st_mtime
29
+ size = p.stat().st_size
30
+ prev = st.get(key) or {}
31
+ if prev.get('mtime') == mtime and prev.get('size') == size:
32
+ continue
33
+ dest = f'checkpoints/x8run/fractus_1b_gpu{i}.pt'
34
+ print(f'UPLOAD {p} -> {REPO}/{dest} {size/1e9:.2f}G', flush=True)
35
+ api.upload_file(path_or_fileobj=str(p), path_in_repo=dest, repo_id=REPO, repo_type='model')
36
+ man = CKPT_DIR / f'RESUME_gpu{i}.json'
37
+ if man.exists():
38
+ api.upload_file(path_or_fileobj=str(man), path_in_repo=f'checkpoints/x8run/RESUME_gpu{i}.json', repo_id=REPO, repo_type='model')
39
+ st[key] = {'mtime': mtime, 'size': size, 't': time.time()}
40
+ save_state(st)
41
+ uploaded.append(i)
42
+ print('uploaded', uploaded, flush=True)
43
+ return uploaded
44
+
45
+ if __name__ == '__main__':
46
+ while True:
47
+ try:
48
+ once()
49
+ except Exception as e:
50
+ print('PUSH_ERR', e, flush=True)
51
+ time.sleep(3600)