Add scripts/push_scripts_to_hub.py
Browse files
scripts/push_scripts_to_hub.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Push zindango-slm scripts to Hugging Face model repo (scripts/ folder).
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
python scripts/push_scripts_to_hub.py [--repo-id USERNAME/zindango-slm]
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
from huggingface_hub import HfApi, create_repo, upload_file
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def main():
|
| 16 |
+
parser = argparse.ArgumentParser()
|
| 17 |
+
parser.add_argument("--repo-id", default=None)
|
| 18 |
+
parser.add_argument("--skip-create", action="store_true")
|
| 19 |
+
args = parser.parse_args()
|
| 20 |
+
|
| 21 |
+
sft_root = Path(__file__).resolve().parent.parent
|
| 22 |
+
benchmark_root = sft_root.parent / "nanbeige-benchmark-verification"
|
| 23 |
+
|
| 24 |
+
api = HfApi()
|
| 25 |
+
user = api.whoami()
|
| 26 |
+
username = user["name"]
|
| 27 |
+
repo_id = args.repo_id or f"{username}/zindango-slm"
|
| 28 |
+
|
| 29 |
+
if not args.skip_create:
|
| 30 |
+
try:
|
| 31 |
+
create_repo(repo_id, repo_type="model", exist_ok=True)
|
| 32 |
+
except Exception as e:
|
| 33 |
+
if "403" in str(e).lower() or "forbidden" in str(e).lower():
|
| 34 |
+
print("Create repo failed. Run with --skip-create.")
|
| 35 |
+
raise
|
| 36 |
+
|
| 37 |
+
scripts_to_upload = [
|
| 38 |
+
(sft_root / "scripts/convert_and_push_gguf.py", "scripts/convert_and_push_gguf.py"),
|
| 39 |
+
(sft_root / "scripts/push_to_hub.py", "scripts/push_to_hub.py"),
|
| 40 |
+
(sft_root / "scripts/push_scripts_to_hub.py", "scripts/push_scripts_to_hub.py"),
|
| 41 |
+
(benchmark_root / "scripts/test_zindango_gguf.py", "scripts/test_zindango_gguf.py"),
|
| 42 |
+
(benchmark_root / "scripts/llamacpp_chat.py", "scripts/llamacpp_chat.py"),
|
| 43 |
+
(benchmark_root / "scripts/llamacpp_chat.sh", "scripts/llamacpp_chat.sh"),
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
for local_path, path_in_repo in scripts_to_upload:
|
| 47 |
+
if not local_path.exists():
|
| 48 |
+
print(f"Skipping {local_path} (not found)")
|
| 49 |
+
continue
|
| 50 |
+
print(f"Uploading {path_in_repo}...")
|
| 51 |
+
upload_file(
|
| 52 |
+
path_or_fileobj=str(local_path),
|
| 53 |
+
path_in_repo=path_in_repo,
|
| 54 |
+
repo_id=repo_id,
|
| 55 |
+
repo_type="model",
|
| 56 |
+
commit_message=f"Add {path_in_repo}",
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
print(f"Done. https://huggingface.co/{repo_id}")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
main()
|