Download rsm_rise/scripts/hf_push/code_upload.py from rli14/rsm_rise_code: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/rli14/rsm_rise_code/resolve/main/rsm_rise/scripts/hf_push/code_upload.py
- Command line
-
hf download hf://rli14/rsm_rise_code/rsm_rise/scripts/hf_push/code_upload.py
-
curl -L -o code_upload.py https://huggingface.co/rli14/rsm_rise_code/resolve/main/rsm_rise/scripts/hf_push/code_upload.py
1.12 kB
| #!/usr/bin/env python | |
| """upload_folder the staged code tree as ONE commit, deleting remote files no longer staged; verify file count.""" | |
| import os, sys, json, time | |
| from huggingface_hub import HfApi | |
| repo, st, outj = sys.argv[1:4] | |
| api = HfApi(token=os.environ["HF_TOKEN"]) | |
| api.create_repo(repo, repo_type="model", private=False, exist_ok=True) | |
| t0 = time.time() | |
| ci = api.upload_folder(repo_id=repo, repo_type="model", folder_path=st, delete_patterns=["*"], | |
| commit_message="rsm_rise code snapshot (HF_PUSH_ALL)") | |
| local = {os.path.relpath(os.path.join(d, f), st) for d, _, fs in os.walk(st) for f in fs} | |
| remote = {e.path for e in api.list_repo_tree(repo, repo_type="model", recursive=True) if getattr(e, "blob_id", None) and hasattr(e, "size")} | |
| miss = sorted(local - remote) | |
| json.dump({"repo": repo, "commit": getattr(ci, "oid", str(ci)), "local_files": len(local), "remote_files": len(remote), | |
| "missing": miss[:50], "seconds": time.time() - t0}, open(outj, "w"), indent=1) | |
| print(f"[code_up] local={len(local)} remote={len(remote)} missing={len(miss)}", flush=True) | |
| sys.exit(1 if miss else 0) | |