handicate-code / jobs /run_handicate.py
AmongTheCouch23's picture
Upload folder using huggingface_hub
9bd725a verified
Raw
History Blame Contribute Delete
3.07 kB
# /// script
# dependencies = [
# "trl>=0.12", "peft", "transformers>=4.46", "datasets", "accelerate",
# "huggingface_hub", "hf-transfer", "trimesh", "numpy",
# ]
# requires-python = ">=3.11,<3.13"
# ///
# Run the Handicate self-refinement loop on an HF GPU Job.
# The framework is multi-file; push it to a Hub dataset repo first, the job downloads it.
#
# 1) (from HandicateAI/) hf upload AmongTheCouch23/handicate-code . . --repo-type dataset
# 2) smoke (cheap): hf jobs uv run -d --flavor a100-large --timeout 2h --python 3.11 -s HF_TOKEN ./jobs/run_handicate.py smoke
# full: hf jobs uv run -d --flavor a100-large --timeout 12h --python 3.11 -s HF_TOKEN ./jobs/run_handicate.py
import os
import subprocess
import sys
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
CODE_REPO = "AmongTheCouch23/handicate-code"
WORK = "/tmp/handicate"
MODE = sys.argv[1] if len(sys.argv) > 1 else "full"
from huggingface_hub import snapshot_download, HfApi
snapshot_download(CODE_REPO, repo_type="dataset", local_dir=WORK)
env = dict(os.environ)
if MODE == "smoke":
env.update({"HANDICATE_ROUNDS": "1", "HANDICATE_STEPS": "4", "HANDICATE_NUMGEN": "4",
"HANDICATE_CURATE": "4", "HANDICATE_JUDGE": "Qwen/Qwen2.5-3B-Instruct",
"HANDICATE_ACCEPT": "0.6"})
print("SMOKE mode: 1 round, 4 RL steps, 3B judge", flush=True)
elif MODE == "real":
# bigger, real refinement: 3 rounds x 40 GRPO steps, 8 candidates, 7B judge (config default)
env.update({"HANDICATE_ROUNDS": "3", "HANDICATE_STEPS": "40", "HANDICATE_NUMGEN": "8",
"HANDICATE_CURATE": "20", "HANDICATE_ACCEPT": "0.65"})
print("REAL mode: 3 rounds x 40 RL steps, 8 candidates, 7B judge", flush=True)
env["TOKENIZERS_PARALLELISM"] = "false"
# Don't check=True: torch/CUDA can SIGABRT during interpreter teardown AFTER the model is
# already saved. We upload from disk below regardless of that cosmetic exit crash.
rc = subprocess.run(["python", "loop.py"], cwd=WORK, env=env).returncode
print(f"loop.py exit code: {rc} (a SIGABRT-on-exit is harmless if the policy saved)", flush=True)
# persist only the FINAL KEPT policy WEIGHTS (no raw data) to the Hub
import glob
fp = f"{WORK}/FINAL_POLICY.txt"
final_dir = None
if os.path.exists(fp):
name = open(fp).read().strip()
final_dir = os.path.join(WORK, os.path.basename(name.rstrip("/")))
if not final_dir or not os.path.isdir(final_dir): # fallback: newest non-intermediate dir
cands = [d for d in glob.glob(f"{WORK}/handicate-r*") if not d.endswith("-rl") and os.path.isdir(d)]
final_dir = sorted(cands)[-1] if cands else None
if final_dir and os.path.isdir(final_dir):
api = HfApi()
api.create_repo("AmongTheCouch23/handicate-policy", repo_type="model", exist_ok=True)
api.upload_folder(folder_path=final_dir, repo_id="AmongTheCouch23/handicate-policy",
repo_type="model", ignore_patterns=["*.optim*", "runs/*", "checkpoint-*"])
print("Uploaded final policy:", final_dir)
else:
print("WARNING: no final policy dir found to upload")