| |
| """Back up the lightweight ABForge scratch artifacts to a PRIVATE HF dataset repo. |
| |
| Mirrors scripts/upload_abforge_models.py conventions: |
| - token from HF_TOKEN env (source secrets/hf_slowguess.env first), NOT global login |
| - verifies the token belongs to SlowGuess before doing anything |
| - idempotent: upload_folder skips files already on the Hub |
| |
| Covers: results (infer/*.jsonl), analysis, server-only scripts, run meta, logs.tar.gz, |
| and a curated data_local set. See docs/scratch_backup_manifest.md for the full rationale. |
| |
| Usage: |
| source $WORK_ROOT/secrets/hf_slowguess.env |
| python scripts/backup_scratch_archive.py # dry-run: print plan only |
| python scripts/backup_scratch_archive.py --upload # actually create repo + upload |
| """ |
| import argparse, fnmatch, os, sys |
| from huggingface_hub import HfApi |
|
|
| WORK = "/gpfs/radev/scratch/cohan/yz979/xucai/Abforge_Training" |
| CODE = "/gpfs/radev/project/cohan/yz979/xucai/Abforge_Training" |
| ORG = "SlowGuess" |
| REPO_ID = f"{ORG}/abforge-scratch-archive" |
|
|
| |
| SCRIPT_FILES = [ |
| f"{WORK}/run_inference_local.py", |
| f"{WORK}/run_inference_local_tm_only.py", |
| f"{WORK}/run_inference_bailian.py", |
| f"{WORK}/run_inference_claude_cli.py", |
| f"{WORK}/run_eval_v18_bench44.sh", |
| f"{WORK}/run_eval_v18_retry.sh", |
| f"{WORK}/env_misha.sh", |
| f"{WORK}/scripts/case_diff_v17_v18.py", |
| f"{WORK}/scripts/compare_v17_v18_bench44.py", |
| ] |
|
|
| |
| DATA_LOCAL = [ |
| f"{WORK}/data/rl_task1_25479_filt2_6.jsonl", |
| f"{WORK}/data/bench_1000_rubric_v2_final_tagfixed.jsonl", |
| f"{WORK}/data/bench_200_rubric_v2_final_tagfixed.jsonl", |
| f"{WORK}/data/bench_44_rubric_v2.jsonl", |
| f"{WORK}/data/bench_50_rubric_v2.jsonl", |
| f"{WORK}/data/bench_150_remaining_rubric_v2.jsonl", |
| f"{WORK}/data/bench_3_rubric_v2.jsonl", |
| f"{WORK}/data/bench_data_4_subset50_simple.jsonl", |
| ] |
|
|
| |
| FOLDER_UPLOADS = [ |
| (f"{WORK}/infer", "results", ["*.jsonl"]), |
| (f"{WORK}/analysis", "analysis", None), |
| (f"{WORK}/hydra_outputs", "meta/hydra_outputs", None), |
| (f"{WORK}/wandb", "meta/wandb", ["*.json", "*.yaml", "*.csv", "*.txt", "*.log"]), |
| ] |
| FOLDER_IGNORE = ["__pycache__/*", "*.pyc"] |
|
|
| |
| EXTRA_FILES = [ |
| (f"{WORK}/hf_upload/logs.tar.gz", "logs/logs.tar.gz"), |
| (f"{CODE}/docs/scratch_backup_manifest.md", "meta/scratch_backup_manifest.md"), |
| ] |
|
|
|
|
| def plan(): |
| print(f"target repo (private dataset): {REPO_ID}\n") |
| print("== folders ==") |
| for src, dst, allow in FOLDER_UPLOADS: |
| ok = "OK " if os.path.isdir(src) else "MISS" |
| print(f" [{ok}] {src} -> {dst}/ allow={allow}") |
| print("== scripts -> scripts/ ==") |
| for f in SCRIPT_FILES: |
| print(f" [{'OK ' if os.path.isfile(f) else 'MISS'}] {f}") |
| print("== data_local -> data_local/ ==") |
| for f in DATA_LOCAL: |
| print(f" [{'OK ' if os.path.isfile(f) else 'MISS'}] {f}") |
| print("== extra files ==") |
| for src, dst in EXTRA_FILES: |
| print(f" [{'OK ' if os.path.isfile(src) else 'MISS'}] {src} -> {dst}") |
|
|
|
|
| def main(): |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--upload", action="store_true", help="actually create repo + upload (default: dry-run)") |
| args = ap.parse_args() |
|
|
| plan() |
| if not args.upload: |
| print("\n[dry-run] re-run with --upload to create the private repo and push.") |
| return |
|
|
| tok = os.environ.get("HF_TOKEN") |
| if not tok: |
| sys.exit("HF_TOKEN not set — source secrets/hf_slowguess.env first") |
| api = HfApi(token=tok) |
| who = api.whoami()["name"] |
| if who != ORG: |
| sys.exit(f"HF_TOKEN belongs to {who}, not {ORG} — aborting") |
|
|
| api.create_repo(REPO_ID, repo_type="dataset", private=True, exist_ok=True) |
|
|
| for src, dst, allow in FOLDER_UPLOADS: |
| if not os.path.isdir(src): |
| print(f"SKIP folder (missing): {src}"); continue |
| print(f"\n=== folder {src} -> {dst}/ ===", flush=True) |
| api.upload_folder(repo_id=REPO_ID, repo_type="dataset", folder_path=src, |
| path_in_repo=dst, allow_patterns=allow, |
| ignore_patterns=FOLDER_IGNORE, commit_message=f"archive {dst}") |
|
|
| for group, dst in ((SCRIPT_FILES, "scripts"), (DATA_LOCAL, "data_local")): |
| for f in group: |
| if not os.path.isfile(f): |
| print(f"SKIP file (missing): {f}"); continue |
| print(f"upload {f} -> {dst}/{os.path.basename(f)}", flush=True) |
| api.upload_file(repo_id=REPO_ID, repo_type="dataset", path_or_fileobj=f, |
| path_in_repo=f"{dst}/{os.path.basename(f)}", |
| commit_message=f"archive {dst}/{os.path.basename(f)}") |
|
|
| for src, dst in EXTRA_FILES: |
| if not os.path.isfile(src): |
| print(f"SKIP extra (missing): {src}"); continue |
| print(f"upload {src} -> {dst}", flush=True) |
| api.upload_file(repo_id=REPO_ID, repo_type="dataset", path_or_fileobj=src, |
| path_in_repo=dst, commit_message=f"archive {dst}") |
|
|
| print(f"\nDONE https://huggingface.co/datasets/{REPO_ID}", flush=True) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|