amer224 commited on
Commit
9e8f55c
·
verified ·
1 Parent(s): ea693bf

Add brains/sovereign-v3/upload_to_hf.py

Browse files
Files changed (1) hide show
  1. brains/sovereign-v3/upload_to_hf.py +98 -0
brains/sovereign-v3/upload_to_hf.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ upload_to_hf.py — one-shot upload of SOVEREIGN v3 deliverables to:
4
+
5
+ https://huggingface.co/amer224/botfromdeep (MODEL repo, public)
6
+
7
+ brains/sovereign-v3/
8
+ model.py
9
+ data_adapters.py
10
+ ARCHITECTURE.md
11
+ train_notes.md
12
+ README.md
13
+ sovereign_v3_init.pt (random-init weights; optional)
14
+
15
+ Usage:
16
+ pip install huggingface_hub # and torch, to export init weights
17
+ HF_TOKEN="hf_..." python upload_to_hf.py --with-weights
18
+
19
+ (No Python at hand? The SOVEREIGN website ships a one-click browser
20
+ uploader that pushes the same five code/doc files to this repo with the
21
+ official Hugging Face JS SDK — paste the token, click once.)
22
+
23
+ Security: the token is read ONLY from the environment and is never written
24
+ to disk, logged, or embedded in any file. The owner rotates it after the
25
+ project ends — do not paste it anywhere except your shell environment.
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import os
31
+ import sys
32
+ from pathlib import Path
33
+
34
+ HERE = Path(__file__).resolve().parent
35
+ REPO = "amer224/botfromdeep" # MODEL repo (not dataset)
36
+ REPO_TYPE = "model"
37
+ FOLDER = "brains/sovereign-v3"
38
+
39
+ FILES = ["model.py", "data_adapters.py", "ARCHITECTURE.md", "train_notes.md",
40
+ "README.md"]
41
+
42
+
43
+ def export_init_weights(path: Path) -> bool:
44
+ """Random-init weights are acceptable per the brief; training happens
45
+ in the shared pipeline. NOTE: exporting the ~272M net is ~1.1 GB on
46
+ disk. Run without --with-weights if you only need the code."""
47
+ try:
48
+ import torch
49
+ sys.path.insert(0, str(HERE))
50
+ from model import make_model, count_params # noqa: E402
51
+ torch.manual_seed(0)
52
+ m = make_model()
53
+ torch.save({"config": m.cfg, "state_dict": m.state_dict()}, path)
54
+ print(f"[weights] exported {path.name} "
55
+ f"({count_params(m)/1e6:.1f}M params, random init, seed 0)")
56
+ return True
57
+ except ImportError as e:
58
+ print(f"[weights] skipped (torch unavailable): {e}")
59
+ return False
60
+
61
+
62
+ def main() -> int:
63
+ token = os.environ.get("HF_TOKEN")
64
+ if not token:
65
+ print("ERROR: set HF_TOKEN in the environment first.")
66
+ print(" export HF_TOKEN=\"hf_...\" # rotating key, never commit it")
67
+ return 1
68
+
69
+ try:
70
+ from huggingface_hub import HfApi
71
+ except ImportError:
72
+ print("ERROR: pip install huggingface_hub first")
73
+ return 1
74
+
75
+ # optional: regenerate/export random-init checkpoint
76
+ weights = HERE / "sovereign_v3_init.pt"
77
+ if "--with-weights" in sys.argv and not weights.exists():
78
+ export_init_weights(weights)
79
+
80
+ api = HfApi(token=token)
81
+ uploads = FILES
82
+ if weights.exists():
83
+ uploads.append(weights.name)
84
+ for name in uploads:
85
+ api.upload_file(
86
+ path_or_fileobj=str(HERE / name),
87
+ path_in_repo=f"{FOLDER}/{name}",
88
+ repo_id=REPO,
89
+ repo_type=REPO_TYPE,
90
+ commit_message=f"sovereign-v3: add {name}",
91
+ )
92
+ print(f"[uploaded] {FOLDER}/{name}")
93
+ print(f"\nDone. Folder: https://huggingface.co/{REPO}/tree/main/{FOLDER}")
94
+ return 0
95
+
96
+
97
+ if __name__ == "__main__":
98
+ raise SystemExit(main())