round-7: disjoint encoder pipeline (scripts/hf_disjoint_encoder_job.py)
Browse files
scripts/hf_disjoint_encoder_job.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""HF GPU job: train the benchmark-disjoint MPNN odor encoder (round-7 panel response).
|
| 3 |
+
|
| 4 |
+
Trains scripts/train_disjoint_encoder.py on the disjoint corpus (3,662 molecules,
|
| 5 |
+
benchmark-overlapping molecules removed) and uploads checkpoint + 256-d corpus
|
| 6 |
+
embeddings to mattbitzesty/pino-disjoint-encoder.
|
| 7 |
+
"""
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import json
|
| 11 |
+
import os
|
| 12 |
+
import subprocess
|
| 13 |
+
import sys
|
| 14 |
+
import time
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
TOKEN = os.environ.get("HF_TOKEN")
|
| 18 |
+
os.environ.setdefault("HF_HUB_ENABLE_XET", "0")
|
| 19 |
+
os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
|
| 20 |
+
|
| 21 |
+
WORKSPACE = Path("/workspace")
|
| 22 |
+
OUT = WORKSPACE / "encoder_out"
|
| 23 |
+
RESULT_REPO = os.environ.get("PINO_ENCODER_REPO", "mattbitzesty/pino-disjoint-encoder")
|
| 24 |
+
EPOCHS = int(os.environ.get("PINO_ENCODER_EPOCHS", "60"))
|
| 25 |
+
_START = time.time()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def log(msg: str) -> None:
|
| 29 |
+
print(f"{time.strftime('%Y-%m-%dT%H:%M:%SZ')} {msg}", flush=True)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _disable_xet() -> None:
|
| 33 |
+
try:
|
| 34 |
+
import huggingface_hub.utils._runtime as _runtime
|
| 35 |
+
_runtime.is_xet_available = lambda: False
|
| 36 |
+
except Exception as e: # noqa: BLE001
|
| 37 |
+
log(f"warn: xet-disable patch failed ({e})")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def main() -> int:
|
| 41 |
+
_disable_xet()
|
| 42 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 43 |
+
|
| 44 |
+
api = HfApi(token=TOKEN)
|
| 45 |
+
OUT.mkdir(parents=True, exist_ok=True)
|
| 46 |
+
|
| 47 |
+
script_p = hf_hub_download("mattbitzesty/pino-source-code",
|
| 48 |
+
"scripts/train_disjoint_encoder.py",
|
| 49 |
+
repo_type="model", token=TOKEN)
|
| 50 |
+
csv_p = hf_hub_download("mattbitzesty/pino-source-code",
|
| 51 |
+
"data/openpom_curated_disjoint.csv",
|
| 52 |
+
repo_type="model", token=TOKEN)
|
| 53 |
+
log(f"staged script={script_p} csv={csv_p}")
|
| 54 |
+
|
| 55 |
+
ckpt = OUT / "disjoint_encoder.pt"
|
| 56 |
+
emb = OUT / "corpus_embeddings.npy"
|
| 57 |
+
idx = OUT / "corpus_embeddings_index.json"
|
| 58 |
+
cmd = [sys.executable, str(script_p),
|
| 59 |
+
"--csv", str(csv_p),
|
| 60 |
+
"--epochs", str(EPOCHS),
|
| 61 |
+
"--batch-size", "64", "--lr", "1e-3", "--seed", "2026",
|
| 62 |
+
"--checkpoint-out", str(ckpt),
|
| 63 |
+
"--embed-out", str(emb)]
|
| 64 |
+
log(f"$ {' '.join(cmd)}")
|
| 65 |
+
subprocess.check_call(cmd, stdout=sys.stdout, stderr=sys.stderr)
|
| 66 |
+
|
| 67 |
+
# embed-out writes <stem>.npy + <stem>_index.json next to --embed-out
|
| 68 |
+
produced = list(OUT.glob("*"))
|
| 69 |
+
log(f"produced: {[p.name for p in produced]}")
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
api.create_repo(RESULT_REPO, repo_type="model", private=True, exist_ok=True)
|
| 73 |
+
except Exception as e: # noqa: BLE001
|
| 74 |
+
log(f"warn: create_repo ({e})")
|
| 75 |
+
|
| 76 |
+
# companion index json lives beside the npy
|
| 77 |
+
candidates = [ckpt, emb, OUT / "corpus_embeddings_index.json"]
|
| 78 |
+
for p in candidates:
|
| 79 |
+
if p.exists():
|
| 80 |
+
api.upload_file(path_or_fileobj=str(p), path_in_repo=p.name,
|
| 81 |
+
repo_id=RESULT_REPO, repo_type="model",
|
| 82 |
+
commit_message=f"disjoint encoder training run ({EPOCHS} epochs, 3662-molecule corpus)")
|
| 83 |
+
log(f"uploaded {p.name}")
|
| 84 |
+
|
| 85 |
+
summary = {"epochs": EPOCHS, "corpus": "openpom_curated_disjoint.csv (3662 molecules)",
|
| 86 |
+
"exclusion": "benchmark/threshold/substantivity/descriptor/prospective/substitution/validation CAS removed (assembly_summary.json)",
|
| 87 |
+
"checkpoint": ckpt.name, "embeddings": emb.name,
|
| 88 |
+
"elapsed_min": round((time.time() - _START) / 60, 1)}
|
| 89 |
+
api.upload_file(path_or_fileobj=json.dumps(summary, indent=2).encode(),
|
| 90 |
+
path_in_repo="training_summary.json", repo_id=RESULT_REPO, repo_type="model")
|
| 91 |
+
log("DONE")
|
| 92 |
+
return 0
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
try:
|
| 97 |
+
raise SystemExit(main())
|
| 98 |
+
except Exception as exc: # noqa: BLE001
|
| 99 |
+
import traceback
|
| 100 |
+
traceback.print_exc()
|
| 101 |
+
print(f"[ENCODER] FAILED: {exc}", flush=True)
|
| 102 |
+
raise SystemExit(1)
|