BHARGAV REDDY commited on
Commit
9cc94a1
Β·
verified Β·
1 Parent(s): da28a11

Upload push_model_to_hf.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. push_model_to_hf.py +145 -0
push_model_to_hf.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Push trained LUNA model to HuggingFace model repo.
4
+
5
+ Target: https://huggingface.co/ASTERIZER/LUNA-100M
6
+
7
+ Uploads:
8
+ - Model weights (lit_model.pth, latest.pt)
9
+ - Tokenizer files
10
+ - Training config
11
+ - Quantized GGUF files (if present)
12
+
13
+ Usage:
14
+ HF_TOKEN=hf_xxx python push_model_to_hf.py
15
+ HF_TOKEN=hf_xxx python push_model_to_hf.py --model_dir out/pretrain/luna-100m-english-1b
16
+ HF_TOKEN=hf_xxx python push_model_to_hf.py --include_gguf
17
+ """
18
+
19
+ import argparse
20
+ import os
21
+ from pathlib import Path
22
+
23
+ from huggingface_hub import HfApi
24
+
25
+
26
+ MODEL_REPO = "ASTERIZER/LUNA-100M"
27
+
28
+
29
+ def parse_args():
30
+ parser = argparse.ArgumentParser(description="Push LUNA model to HuggingFace")
31
+ parser.add_argument("--repo_id", default=MODEL_REPO)
32
+ parser.add_argument("--model_dir", default="out/pretrain/luna-100m-english-1b",
33
+ help="Directory containing trained model")
34
+ parser.add_argument("--path_in_repo", default="english_1b_continued",
35
+ help="Subfolder in HF repo")
36
+ parser.add_argument("--include_gguf", action="store_true",
37
+ help="Also upload GGUF quantisations")
38
+ parser.add_argument("--include_tokenizer", action="store_true", default=True,
39
+ help="Upload tokenizer files")
40
+ parser.add_argument("--private", action="store_true")
41
+ return parser.parse_args()
42
+
43
+
44
+ def main():
45
+ args = parse_args()
46
+ token = os.environ.get("HF_TOKEN")
47
+ if not token:
48
+ raise RuntimeError("Set HF_TOKEN environment variable")
49
+
50
+ api = HfApi(token=token)
51
+
52
+ # Create model repo
53
+ api.create_repo(
54
+ repo_id=args.repo_id,
55
+ repo_type="model",
56
+ private=args.private,
57
+ exist_ok=True,
58
+ )
59
+ print(f"Model repo: https://huggingface.co/{args.repo_id}\n")
60
+
61
+ total = 0
62
+ model_dir = Path(args.model_dir)
63
+
64
+ # ── 1. Model weights ──────────────────────────────────────────────────
65
+ print("── Model weights ──")
66
+ if model_dir.exists():
67
+ # Upload the full model directory
68
+ api.upload_folder(
69
+ repo_id=args.repo_id,
70
+ repo_type="model",
71
+ folder_path=str(model_dir),
72
+ path_in_repo=args.path_in_repo,
73
+ )
74
+ file_count = len(list(model_dir.rglob("*")))
75
+ print(f" Uploaded {file_count} files from {model_dir}")
76
+ total += file_count
77
+ else:
78
+ print(f" SKIP: {model_dir} not found")
79
+ # Try common alternative paths
80
+ for alt in [
81
+ "Base/out/pretrain/luna_100m/final",
82
+ "Base/out/pretrain/custom-100m-english/final_raw",
83
+ ]:
84
+ alt_path = Path(alt)
85
+ if alt_path.exists():
86
+ print(f" Found alternative: {alt_path}")
87
+ api.upload_folder(
88
+ repo_id=args.repo_id,
89
+ repo_type="model",
90
+ folder_path=str(alt_path),
91
+ path_in_repo="pretrained",
92
+ )
93
+ total += len(list(alt_path.rglob("*")))
94
+ break
95
+
96
+ # ── 2. Tokenizer ──────────────────────────────────────────────────────
97
+ if args.include_tokenizer:
98
+ print("\n── Tokenizer ──")
99
+ tok_dir = Path("Base/checkpoints/EleutherAI/pythia-160m")
100
+ tok_files = ["config.json", "tokenizer_config.json", "tokenizer.json"]
101
+ for tf in tok_files:
102
+ fpath = tok_dir / tf
103
+ if fpath.exists():
104
+ api.upload_file(
105
+ path_or_fileobj=str(fpath),
106
+ path_in_repo=f"tokenizer/{tf}",
107
+ repo_id=args.repo_id,
108
+ repo_type="model",
109
+ )
110
+ print(f" OK: {fpath}")
111
+ total += 1
112
+
113
+ # ── 3. Training config ────────────────────────────────────────────────
114
+ print("\n── Config ──")
115
+ for cfg in ["train_continue_english_1b.yaml", "train_config.yaml"]:
116
+ if os.path.exists(cfg):
117
+ api.upload_file(
118
+ path_or_fileobj=cfg,
119
+ path_in_repo=f"config/{cfg}",
120
+ repo_id=args.repo_id,
121
+ repo_type="model",
122
+ )
123
+ print(f" OK: {cfg}")
124
+ total += 1
125
+
126
+ # ── 4. GGUF quantisations ────────────────────────────────────────────
127
+ if args.include_gguf:
128
+ print("\n── GGUF quantisations ──")
129
+ gguf_dir = Path("quantisations")
130
+ if gguf_dir.exists():
131
+ for gf in gguf_dir.glob("*.gguf"):
132
+ api.upload_file(
133
+ path_or_fileobj=str(gf),
134
+ path_in_repo=f"gguf/{gf.name}",
135
+ repo_id=args.repo_id,
136
+ repo_type="model",
137
+ )
138
+ print(f" OK: {gf}")
139
+ total += 1
140
+
141
+ print(f"\nDone! Uploaded {total} items to https://huggingface.co/{args.repo_id}")
142
+
143
+
144
+ if __name__ == "__main__":
145
+ main()