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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""HF GPU job (eval-only): drydown evals for the FULL-physics openpom_256 arm.
|
| 3 |
+
|
| 4 |
+
The time_only control chain (10/10 checkpoints + drydown evals) is complete, and
|
| 5 |
+
the physoff arm already has drydown evals. The missing leg of the three-arm
|
| 6 |
+
comparison (full vs time_only vs off) is the drydown eval of the original
|
| 7 |
+
full-physics A/B checkpoints pimt_ab_openpom_256_seed{n}.pt, n=1..10, which
|
| 8 |
+
were trained with --physics-mode full but never drydown-evaled.
|
| 9 |
+
|
| 10 |
+
This job is eval-only (no training): for each seed it downloads the existing
|
| 11 |
+
checkpoint, runs scripts/evaluate_drydown_physics.py with --physics-mode full
|
| 12 |
+
(matched conditioning), stamps provenance, and uploads
|
| 13 |
+
drydown_fullphys_openpom_256_seed{n}.json. Resume-safe and self-chaining on the
|
| 14 |
+
wall budget, same pattern as hf_gpu_timeonly_job.py.
|
| 15 |
+
"""
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
import json
|
| 19 |
+
import os
|
| 20 |
+
import shutil
|
| 21 |
+
import subprocess
|
| 22 |
+
import sys
|
| 23 |
+
import time
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
|
| 26 |
+
TOKEN = os.environ.get("HF_TOKEN")
|
| 27 |
+
os.environ.setdefault("HF_HUB_ENABLE_XET", "0")
|
| 28 |
+
os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
|
| 29 |
+
|
| 30 |
+
WORKSPACE = Path("/workspace")
|
| 31 |
+
SOURCE_DIR = WORKSPACE / "pino-fresh"
|
| 32 |
+
DATASET_DIR = WORKSPACE / "pino-dataset"
|
| 33 |
+
OUT_DIR = WORKSPACE / "ab_out"
|
| 34 |
+
|
| 35 |
+
SOURCE_REPO = os.environ.get("PINO_SOURCE_REPO", "mattbitzesty/pino-source-code")
|
| 36 |
+
DATASET_REPO = os.environ.get("PINO_DATASET_REPO", "mattbitzesty/pino-synthetic-dataset-v3")
|
| 37 |
+
AB_REPO = os.environ.get("PINO_AB_REPO", "mattbitzesty/pino-pimt-representation-ab")
|
| 38 |
+
|
| 39 |
+
TRAIN_RATIO = os.environ.get("PINO_TRAIN_RATIO", "0.85")
|
| 40 |
+
SEEDS = [int(s) for s in os.environ.get("PINO_SEEDS", "1,2,3,4,5,6,7,8,9,10").split(",") if s.strip()]
|
| 41 |
+
|
| 42 |
+
DATASET_V10 = "empirical_dataset_v10_alltags.jsonl"
|
| 43 |
+
|
| 44 |
+
WALL_BUDGET_S = int(os.environ.get("PINO_WALL_BUDGET_S", "5100")) # ~85 min
|
| 45 |
+
JOB_IMAGE = os.environ.get("PINO_JOB_IMAGE", "pytorch/pytorch:2.4.0-cuda12.1-cudnn9-runtime")
|
| 46 |
+
JOB_FLAVOR = os.environ.get("PINO_JOB_FLAVOR", "t4-medium")
|
| 47 |
+
JOB_TIMEOUT = os.environ.get("PINO_JOB_TIMEOUT", "21600")
|
| 48 |
+
_START = time.time()
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def log(msg: str) -> None:
|
| 52 |
+
print(f"{time.strftime('%Y-%m-%dT%H:%M:%SZ')} {msg}", flush=True)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def run(cmd: list[str]) -> None:
|
| 56 |
+
log(f"$ {' '.join(cmd)}")
|
| 57 |
+
subprocess.check_call(cmd, stdout=sys.stdout, stderr=sys.stderr)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _disable_xet() -> None:
|
| 61 |
+
try:
|
| 62 |
+
import huggingface_hub.utils._runtime as _runtime
|
| 63 |
+
_runtime.is_xet_available = lambda: False
|
| 64 |
+
except Exception as e: # noqa: BLE001
|
| 65 |
+
log(f"[FE] warn: xet-disable patch failed ({e})")
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _retry(fn, what: str, attempts: int = 3, delay_s: int = 10):
|
| 69 |
+
for attempt in range(1, attempts + 1):
|
| 70 |
+
try:
|
| 71 |
+
return fn()
|
| 72 |
+
except Exception as e: # noqa: BLE001
|
| 73 |
+
if attempt == attempts:
|
| 74 |
+
raise
|
| 75 |
+
log(f"[FE] warn: {what} failed (attempt {attempt}/{attempts}): {e}; retrying in {delay_s}s")
|
| 76 |
+
time.sleep(delay_s)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def _upload_with_retry(api, local: Path, remote: str) -> None:
|
| 80 |
+
_retry(
|
| 81 |
+
lambda: api.upload_file(path_or_fileobj=str(local), path_in_repo=remote,
|
| 82 |
+
repo_id=AB_REPO, repo_type="model"),
|
| 83 |
+
f"upload {remote}",
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def main() -> int:
|
| 88 |
+
run([sys.executable, "-m", "pip", "install", "--quiet",
|
| 89 |
+
"huggingface-hub", "scipy", "tensorboard", "rdkit", "numpy"])
|
| 90 |
+
_disable_xet()
|
| 91 |
+
|
| 92 |
+
from huggingface_hub import snapshot_download, HfApi, hf_hub_download
|
| 93 |
+
|
| 94 |
+
SOURCE_DIR.mkdir(parents=True, exist_ok=True)
|
| 95 |
+
DATASET_DIR.mkdir(parents=True, exist_ok=True)
|
| 96 |
+
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 97 |
+
|
| 98 |
+
log(f"[FE] downloading source {SOURCE_REPO} + dataset {DATASET_REPO}")
|
| 99 |
+
snapshot_download(repo_id=SOURCE_REPO, repo_type="model", local_dir=str(SOURCE_DIR), token=TOKEN)
|
| 100 |
+
snapshot_download(repo_id=DATASET_REPO, repo_type="dataset", local_dir=str(DATASET_DIR), token=TOKEN)
|
| 101 |
+
|
| 102 |
+
reg_src = DATASET_DIR / "registry.db"
|
| 103 |
+
if reg_src.exists():
|
| 104 |
+
shutil.copy2(reg_src, WORKSPACE / "registry.db")
|
| 105 |
+
os.environ["PINO_REGISTRY_PATH"] = str(WORKSPACE / "registry.db")
|
| 106 |
+
ss = DATASET_DIR / "scalar_stats_v1.json"
|
| 107 |
+
if ss.exists():
|
| 108 |
+
(SOURCE_DIR / "artifacts").mkdir(exist_ok=True)
|
| 109 |
+
shutil.copy2(ss, SOURCE_DIR / "artifacts" / "scalar_stats_v1.json")
|
| 110 |
+
|
| 111 |
+
pom_src_dir = DATASET_DIR / "artifacts" / "pom"
|
| 112 |
+
if pom_src_dir.exists():
|
| 113 |
+
pom_dst = SOURCE_DIR / "artifacts" / "pom"
|
| 114 |
+
pom_dst.mkdir(parents=True, exist_ok=True)
|
| 115 |
+
for fname in ("pom_embeddings.npy", "pom_index.json", "pom_manifest.json"):
|
| 116 |
+
f = pom_src_dir / fname
|
| 117 |
+
if f.exists():
|
| 118 |
+
shutil.copy2(f, pom_dst / fname)
|
| 119 |
+
log(f"[FE] staged POM assets -> {pom_dst}")
|
| 120 |
+
else:
|
| 121 |
+
log(f"[FE] WARN: no POM assets at {pom_src_dir}; openpom_256 backbone will fail")
|
| 122 |
+
|
| 123 |
+
run([sys.executable, "-m", "pip", "install", "--quiet", "-e", str(SOURCE_DIR)])
|
| 124 |
+
sys.path.insert(0, str(SOURCE_DIR / "src"))
|
| 125 |
+
|
| 126 |
+
import torch # noqa: E402,F401
|
| 127 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 128 |
+
log(f"[FE] device={device} seeds={SEEDS}")
|
| 129 |
+
|
| 130 |
+
api = HfApi(token=TOKEN)
|
| 131 |
+
have = set()
|
| 132 |
+
try:
|
| 133 |
+
have = set(api.list_repo_files(AB_REPO, repo_type="model"))
|
| 134 |
+
except Exception as e: # noqa: BLE001
|
| 135 |
+
log(f"[FE] warn: could not list AB repo ({e}); assuming nothing done")
|
| 136 |
+
|
| 137 |
+
def _elapsed() -> float:
|
| 138 |
+
return time.time() - _START
|
| 139 |
+
|
| 140 |
+
data_path = str(DATASET_DIR / DATASET_V10)
|
| 141 |
+
pending = [s for s in SEEDS
|
| 142 |
+
if f"drydown_fullphys_openpom_256_seed{s}.json" not in have]
|
| 143 |
+
log(f"[FE] {len(SEEDS)} seeds total, {len(pending)} pending (elapsed {(_elapsed()/60):.1f} min)")
|
| 144 |
+
|
| 145 |
+
completed_now: list[int] = []
|
| 146 |
+
for seed in pending:
|
| 147 |
+
if _elapsed() > WALL_BUDGET_S:
|
| 148 |
+
log(f"[FE] wall budget reached ({(_elapsed()/60):.1f} min); chaining")
|
| 149 |
+
break
|
| 150 |
+
tag = f"fullphys_openpom_256_seed{seed}"
|
| 151 |
+
ckpt_name = f"pimt_ab_openpom_256_seed{seed}.pt"
|
| 152 |
+
dd_name = f"drydown_{tag}.json"
|
| 153 |
+
log(f"[FE] ===== {tag} (eval-only, physics-mode full) =====")
|
| 154 |
+
|
| 155 |
+
if ckpt_name not in have:
|
| 156 |
+
log(f"[FE] ERROR: checkpoint {ckpt_name} missing from AB repo; skipping seed {seed}")
|
| 157 |
+
continue
|
| 158 |
+
ckpt = OUT_DIR / ckpt_name
|
| 159 |
+
if not ckpt.exists():
|
| 160 |
+
downloaded = str(_retry(
|
| 161 |
+
lambda: hf_hub_download(repo_id=AB_REPO, repo_type="model",
|
| 162 |
+
filename=ckpt_name, local_dir=str(OUT_DIR),
|
| 163 |
+
token=TOKEN),
|
| 164 |
+
f"download {ckpt_name}",
|
| 165 |
+
))
|
| 166 |
+
if Path(downloaded) != ckpt:
|
| 167 |
+
shutil.copy2(downloaded, ckpt)
|
| 168 |
+
|
| 169 |
+
final_val, best_epoch = None, None
|
| 170 |
+
try:
|
| 171 |
+
blob = torch.load(ckpt, map_location="cpu")
|
| 172 |
+
final_val = float(blob.get("val_loss")) if blob.get("val_loss") is not None else None
|
| 173 |
+
best_epoch = int(blob.get("epoch")) if blob.get("epoch") is not None else None
|
| 174 |
+
except Exception as e: # noqa: BLE001
|
| 175 |
+
log(f"[FE] warn: could not read checkpoint for val stamp ({e})")
|
| 176 |
+
|
| 177 |
+
dd_out = OUT_DIR / dd_name
|
| 178 |
+
dd_cmd = [sys.executable, str(SOURCE_DIR / "scripts" / "evaluate_drydown_physics.py"),
|
| 179 |
+
"--checkpoint", str(ckpt), "--data", data_path,
|
| 180 |
+
"--train-ratio", str(TRAIN_RATIO), "--seed", str(seed),
|
| 181 |
+
"--max-eval", "400",
|
| 182 |
+
"--physics-mode", "full",
|
| 183 |
+
"--structural-source", "openpom_256",
|
| 184 |
+
"--arm-label", tag, "--output", str(dd_out)]
|
| 185 |
+
run(dd_cmd)
|
| 186 |
+
try:
|
| 187 |
+
dj = json.loads(dd_out.read_text())
|
| 188 |
+
dj["final_val_total"] = final_val
|
| 189 |
+
dj["best_epoch"] = best_epoch
|
| 190 |
+
dj["seed"] = seed
|
| 191 |
+
dj["physics_mode"] = "full"
|
| 192 |
+
dd_out.write_text(json.dumps(dj, indent=2))
|
| 193 |
+
except Exception as e: # noqa: BLE001
|
| 194 |
+
log(f"[FE] warn: could not stamp drydown JSON ({e})")
|
| 195 |
+
_upload_with_retry(api, dd_out, dd_name)
|
| 196 |
+
have.add(dd_name)
|
| 197 |
+
completed_now.append(seed)
|
| 198 |
+
log(f"[FE] completed {tag}")
|
| 199 |
+
|
| 200 |
+
remaining = [s for s in pending if s not in completed_now]
|
| 201 |
+
log(f"[FE] completed this job: {len(completed_now)} | remaining: {len(remaining)}")
|
| 202 |
+
|
| 203 |
+
summary = {"experiment": "full-physics openpom_256 drydown evals (eval-only leg of full vs time_only vs off), n=10",
|
| 204 |
+
"arm": "fullphys", "seeds": SEEDS,
|
| 205 |
+
"structural_source": "openpom_256",
|
| 206 |
+
"physics_mode": "full",
|
| 207 |
+
"eval_only": True,
|
| 208 |
+
"completed_this_job": completed_now,
|
| 209 |
+
"remaining": remaining,
|
| 210 |
+
"all_complete": not remaining}
|
| 211 |
+
api.upload_file(path_or_fileobj=json.dumps(summary, indent=2).encode(),
|
| 212 |
+
path_in_repo="gpu_run_summary_fullphys_eval.json",
|
| 213 |
+
repo_id=AB_REPO, repo_type="model")
|
| 214 |
+
|
| 215 |
+
if remaining:
|
| 216 |
+
log(f"[FE] chaining: relaunching for seeds {remaining}")
|
| 217 |
+
try:
|
| 218 |
+
import base64
|
| 219 |
+
_inner = (
|
| 220 |
+
"from huggingface_hub import hf_hub_download; import runpy; "
|
| 221 |
+
f"p=hf_hub_download('{SOURCE_REPO}','scripts/hf_eval_fullphys_job.py',repo_type='model'); "
|
| 222 |
+
"runpy.run_path(p,run_name='__main__')"
|
| 223 |
+
)
|
| 224 |
+
chain_cmd = (
|
| 225 |
+
"set -e; pip install -q huggingface-hub; "
|
| 226 |
+
f"echo {base64.b64encode(_inner.encode()).decode()} | base64 -d > /tmp/chain_job.py; "
|
| 227 |
+
"python /tmp/chain_job.py"
|
| 228 |
+
)
|
| 229 |
+
new_job = _retry(
|
| 230 |
+
lambda: api.run_job(
|
| 231 |
+
image=JOB_IMAGE,
|
| 232 |
+
command=["bash", "-lc", chain_cmd],
|
| 233 |
+
secrets={
|
| 234 |
+
"HF_TOKEN": TOKEN,
|
| 235 |
+
"PINO_SEEDS": ",".join(str(s) for s in remaining),
|
| 236 |
+
"PINO_TRAIN_RATIO": TRAIN_RATIO,
|
| 237 |
+
"PINO_JOB_FLAVOR": JOB_FLAVOR,
|
| 238 |
+
"PINO_JOB_TIMEOUT": JOB_TIMEOUT,
|
| 239 |
+
"PINO_WALL_BUDGET_S": str(WALL_BUDGET_S),
|
| 240 |
+
},
|
| 241 |
+
flavor=JOB_FLAVOR,
|
| 242 |
+
timeout=int(JOB_TIMEOUT),
|
| 243 |
+
namespace="mattbitzesty",
|
| 244 |
+
),
|
| 245 |
+
"chain relaunch",
|
| 246 |
+
)
|
| 247 |
+
log(f"[FE] chained job started: {getattr(new_job,'id',new_job)} for seeds {remaining}")
|
| 248 |
+
except Exception as e: # noqa: BLE001
|
| 249 |
+
log(f"[FE] ERROR: chain relaunch failed ({e}); rerun manually")
|
| 250 |
+
return 2
|
| 251 |
+
else:
|
| 252 |
+
log("[FE] DONE - all full-physics drydown evals complete")
|
| 253 |
+
return 0
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
if __name__ == "__main__":
|
| 257 |
+
try:
|
| 258 |
+
raise SystemExit(main())
|
| 259 |
+
except Exception as exc: # noqa: BLE001
|
| 260 |
+
import traceback
|
| 261 |
+
traceback.print_exc()
|
| 262 |
+
print(f"[FE] FAILED: {exc}", flush=True)
|
| 263 |
+
raise SystemExit(1)
|