V6.5-7ds cleanup: remove legacy scripts/upload_v6_4_resilient.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148"""upload_v6_4_resilient.py — V6.4 upload to HuggingFace (single commit).
User requirement: HF_TOKEN should be deleted after use (read from env, never written to file).
Uploads V6.4 critical files to PowerMachine/BiGRU_T_version via singlecommit (upload_folder). Token is read from env var, never written to file."""from __future__ import annotations
import jsonimport osimport sysimport timefrom pathlib import Path
PROJECT_ROOT = Path("/home/z/my-project")BIGRU_ROOT = PROJECT_ROOT / "BiGRU_T_version"
# V6.4 critical files to verify after uploadCRITICAL_FILES_V64 = [ # V6.4 refactored Kohonen module (canonical user code) "src/bigru_t/model/kohonen_refactored/__init__.py", "src/bigru_t/model/kohonen_refactored/kohonen_learning_system.py", # hyp_t.py — pgvector_lookup REMOVED "src/bigru_t/model/hyp_t.py", # Reports "v6_4_report.json", "v6_4_training_metrics.json", # Training script "scripts/train_v6_4.py", # This upload script "scripts/upload_v6_4_resilient.py", # Required support modules "src/bigru_t/utils/xeon_runtime.py", "src/bigru_t/data/streaming_datasets.py", "src/bigru_t/training/ewc.py", "src/bigru_t/model/orq_cell.py",]
def main() -> int: print("=" * 72) print("V6.4 — UPLOAD TO HUGGINGFACE") print("=" * 72)
hf_token = os.environ.get("HF_TOKEN") if not hf_token: print("ERROR: HF_TOKEN not set in env") return 1 print(f" HF_TOKEN loaded from env (length={len(hf_token)})")
# CRITICAL: scrub token from any script files before upload # (V6.3 had a bug where token was in docstrings — fixed) # Use regex to detect any HF token format (hf_<32+ alphanumeric>) import re token_pattern = re.compile(r'hf_[A-Za-z0-9]{32,}') print("\n Pre-upload safety: scrubbing token from scripts...") for script_path in BIGRU_ROOT.glob("scripts/*.py"): try: content = script_path.read_text() if token_pattern.search(content): # Replace any HF token with redacted placeholder scrubbed = token_pattern.sub("hf_<REDACTED_TOKEN>", content) script_path.write_text(scrubbed) print(f" SCRUBBED: {script_path.name}") except Exception as e: print(f" SKIP {script_path.name}: {e}")
# Import huggingface_hub try: from huggingface_hub import HfApi, upload_folder except ImportError: print("ERROR: huggingface_hub not installed") return 1
api = HfApi(token=hf_token) repo_id = "PowerMachine/BiGRU_T_version"
# Verify repo exists try: info = api.repo_info(repo_id=repo_id, repo_type="model") print(f" Repo: {repo_id} (existing, files={len(info.siblings)})") except Exception as e: print(f" ERROR: cannot access repo: {e}") return 1
# Upload as single commit print(f"\n Uploading {BIGRU_ROOT} as single commit...") t0 = time.time() try: commit_info = upload_folder( repo_id=repo_id, repo_type="model", folder_path=str(BIGRU_ROOT), commit_message="V6.4: refactored Kohonen SOM 4D (canonical user code, pgvector_lookup REMOVED)", token=hf_token, ) t1 = time.time() print(f" Upload completed in {t1 - t0:.2f}s") print(f" Commit: {commit_info.oid}") print(f" URL: https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_info.oid}") except Exception as e: print(f" ERROR: upload failed: {e}") return 1
# Verify critical files print("\n Verifying critical files in repo...") try: files_in_repo = [f.rfilename for f in api.list_repo_tree( repo_id=repo_id, repo_type="model", recursive=True )] all_present = True for cf in CRITICAL_FILES_V64: present = cf in files_in_repo mark = "✓" if present else "✗" print(f" {mark} {cf}") if not present: all_present = False print(f"\n Files in repo: {len(files_in_repo)}") if not all_present: print(" WARNING: some critical files missing!") except Exception as e: print(f" WARNING: cannot verify files: {e}")
# Save upload report report = { "version": "V6.4", "upload_timestamp": time.strftime("%Y-%m-%dT%H:%M:%S"), "repo_id": repo_id, "commit_oid": commit_info.oid, "commit_url": f"https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_info.oid}", "duration_s": float(t1 - t0), "critical_files": CRITICAL_FILES_V64, "n_files_in_repo": len(files_in_repo) if "files_in_repo" in dir() else 0, } report_path = BIGRU_ROOT / "v6_4_upload_report.json" report_path.write_text(json.dumps(report, indent=2, ensure_ascii=False)) print(f"\n Upload report: {report_path}")
print("\n" + "=" * 72) print("V6.4 — UPLOAD COMPLETED") print("=" * 72) return 0
if __name__ == "__main__": sys.exit(main())scripts/upload_v6_4_resilient.pyDeleted-148