"""Push the staged tree to the Hugging Face repository. Reads the token from HF_TOKEN in the environment; never writes it anywhere. Safe to run repeatedly — the Hub skips files whose contents have not changed. Paths below are the historical ones; hf_layout.py maps them onto the public layout (MTLCC/ PLANTEUR/ PASTIS/ BASELINES/ PAPER/ PROJECT/ + README.md): stage2/{BASELINES,PLANTEUR,PAPER} -> same folders in the repo stage3/REPORTS -> PAPER/reports ; stage3/LOGS -> MTLCC|PLANTEUR|PROJECT logs ; stage3/TOOLS -> PROJECT/tools stage3/assets -> PAPER/figures/overview ; stage3/FOUNDATION -> MTLCC|PLANTEUR /enhancement stage3/README.md -> the repository's front page plus the MTLCC files that live outside the staging tree (seed runs, ablations, the mask-0.4 re-pre-training, and the two code files that changed) """ import os, sys, glob, datetime from pathlib import Path # Must be set BEFORE huggingface_hub is imported: the Xet storage backend caches to a # directory this machine does not let us create, and it reads the switch at import time. os.environ["HF_HUB_DISABLE_XET"] = "1" os.environ.setdefault("HF_HOME", "/home/ubuntu/pro/hf_work/hfhome") os.environ.setdefault("HF_XET_CACHE", "/home/ubuntu/pro/hf_work/hfhome/xet") from huggingface_hub import HfApi # noqa: E402 REPO = "Dhruv1000/TSRDA" S2 = Path("/home/ubuntu/pro/hf_work/stage2") S3 = Path("/home/ubuntu/pro/hf_work/stage3") M = Path("/home/ubuntu/pro/TSRDA_MTLCC") sys.path.insert(0, "/home/ubuntu/pro/hf_work") import hf_layout # noqa: E402 (maps the historical paths used below onto the simple public layout) api = hf_layout.patch(HfApi(token=os.environ["HF_TOKEN"])) STAMP = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC") def say(*a): print(f"[sync {datetime.datetime.utcnow():%H:%M:%S}]", *a, flush=True) def folder(local, remote, msg, **kw): if not Path(local).exists(): return api.upload_folder(folder_path=str(local), path_in_repo=remote, repo_id=REPO, commit_message=f"{msg} ({STAMP})", **kw) say("folder", remote) def file(local, remote, msg): if not Path(local).exists(): return api.upload_file(path_or_fileobj=str(local), path_in_repo=remote, repo_id=REPO, commit_message=f"{msg} ({STAMP})") say("file", remote) # --- MTLCC extras: the runs that live outside stage2 ------------------------- def mtlcc_extras(): file(M / "code/config.py", "MTLCC/code/config.py", "MTLCC config: MASK_RATIO and R_SCHEDULE overridable by environment (defaults unchanged)") file(M / "code/train_initial.py", "MTLCC/code/train_initial.py", "MTLCC fine-tune: --pretrain_pth none trains from scratch, --lovasz_weight overrides the " "Lovasz term (both for ablations; defaults unchanged)") for s in (42, 1234): d = M / f"runs/finetune_seed{s}" for f in ("history.json", "eval_test_raw.json", "eval_test_ema.json"): file(d / f, f"MTLCC/results/seed_variance/seed{s}/{f}", f"MTLCC seed {s}: {f}") for f in ("model_best_raw.tar", "model_best_ema.tar"): file(d / f, f"MTLCC/checkpoints/seed_variance/seed{s}/{f}", f"MTLCC seed {s} checkpoint") for f in ("seeds.sh", "eval_seeds.sh"): file(M / "runs" / f, f"MTLCC/scripts/{f}", "MTLCC seed-variance runner") for p in glob.glob(str(M / "runs_ablate/*")): n = Path(p).name for f in ("meta.json", "history.json", "eval_test_raw.json", "eval_test_ema.json"): file(f"{p}/{f}", f"MTLCC/results/ablations/{n}/{f}", f"MTLCC ablation {n}: {f}") for f in ("model_best_raw.tar", "model_best_ema.tar"): file(f"{p}/{f}", f"MTLCC/checkpoints/ablations/{n}/{f}", f"MTLCC ablation {n} checkpoint") d = M / "runs_mask04" file(d / "run.sh", "MTLCC/scripts/mask04_run.sh", "MTLCC mask-0.4 runner") for f in ("finetune_mask04/history.json", "finetune_mask04/eval_test_raw.json", "finetune_mask04/eval_test_ema.json"): file(d / f, f"MTLCC/results/mask04/{Path(f).name}", "MTLCC mask-0.4 result") file(M / "runs/ablate.sh", "MTLCC/scripts/ablate.sh", "MTLCC ablation queue") # --- Enhancement / foundation track ------------------------------------------- FD = Path("/home/ubuntu/pro/TSRDA_FOUNDATION") def foundation(): """stage3/FOUNDATION (code, results, logs, scripts, report) + PLANTEUR branch checkpoints once each branch is done.""" for src, dst in (("enh_README_mtlcc.md", "MTLCC/enhancement/README.md"), ("enh_README_planteur.md", "PLANTEUR/enhancement/README.md"), ("project_README.md", "PROJECT/README.md")): file(Path("/home/ubuntu/pro/hf_work") / src, dst, "Folder README") folder(S3 / "FOUNDATION", "FOUNDATION", "Enhancement track (TESSERA readouts, PASTIS branches, ladders): code, results, logs, report") R = FD / "runs_planteur" log = lambda n: (FD / "logs" / n).read_text(errors="ignore") if (FD / "logs" / n).exists() else "" done = { "refinement": (R / "refinement/result.json").exists(), "sam": (R / "sam/result.json").exists(), "structured_pre": (R / "structured_pre/completed.json").exists(), "structured_ft": (R / "structured_ft/result.json").exists(), "cnn_old": (R / "cnn_old/completed.json").exists(), "cnn_new": (R / "cnn_new/completed.json").exists(), } files = {"refinement": ["model_best_raw.tar", "model_best_ema.tar", "result.json", "history.json"], "sam": ["model_best_raw.tar", "model_best_ema.tar", "result.json", "history.json"], "structured_pre": ["encoder_structured.tar", "completed.json"], "structured_ft": ["model_best_raw.tar", "model_best_ema.tar", "result.json", "history.json"], "cnn_old": ["best.tar", "completed.json"], "cnn_new": ["best.tar", "completed.json"]} for n, ok in done.items(): if ok: for f in files[n]: file(R / n / f, f"FOUNDATION/checkpoints/planteur/{n}/{f}", f"PLANTEUR {n} branch: {f}") def main(): which = sys.argv[1] if len(sys.argv) > 1 else "all" if which in ("all", "reports"): folder(S3 / "REPORTS", "REPORTS", "Reports regenerated from the run files") folder(S3 / "LOGS", "LOGS", "Raw training logs") folder(S3 / "TOOLS", "TOOLS", "Report and sync generators") folder(S3 / "assets", "assets", "Figures and GIFs regenerated from the run files") file(S3 / "README.md", "README.md", "README regenerated from the run files") foundation() if which in ("all", "stage2"): for d in ("BASELINES", "PLANTEUR", "PAPER"): folder(S2 / d, d, f"{d}: results, logs and README refreshed") if which in ("all", "mtlcc"): mtlcc_extras() if which == "foundation": foundation() say("done") if __name__ == "__main__": main()