Matthew Ford commited on
Commit
ca7335c
·
1 Parent(s): 73fe875

feat: HF GPU two-arm A/B training job

Browse files

Pulls fresh source + repaired corpus + genuine-POM assets from HF, trains both
representation arms back-to-back on GPU (default 20 epochs, batch 32), runs the
preregistered frozen-benchmark evaluator on each, uploads checkpoints + eval JSON
to mattbitzesty/pino-pimt-representation-ab. Deterministic seed/split; the only
difference between arms is --structural-source.


Former-commit-id: d1d8740e0291c3b84c7d1dc449de8f5fb56c910e
Former-commit-id: 085d3aaf4ea935f52672f6d7a484cf2987f82bc3

Files changed (1) hide show
  1. scripts/hf_gpu_ab_job.py +137 -0
scripts/hf_gpu_ab_job.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """HF GPU job: two-arm representation A/B (Morgan vs genuine OpenPOM), longer run.
3
+
4
+ Pulls fresh source + repaired dataset + genuine-POM assets from HF, trains BOTH
5
+ representation arms back-to-back on GPU, runs the preregistered frozen-benchmark
6
+ evaluator on each, and uploads checkpoints + eval JSON to the A/B model repo.
7
+
8
+ Deterministic: fixed seed, molecule-disjoint split, identical corpus/split for
9
+ both arms; the ONLY difference is --structural-source (morgan vs openpom_256).
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import json
14
+ import os
15
+ import shutil
16
+ import subprocess
17
+ import sys
18
+ import time
19
+ from pathlib import Path
20
+
21
+ TOKEN = os.environ.get("HF_TOKEN")
22
+ os.environ.setdefault("HF_HUB_ENABLE_XET", "0")
23
+ os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
24
+
25
+ WORKSPACE = Path("/workspace")
26
+ SOURCE_DIR = WORKSPACE / "pino-fresh"
27
+ DATASET_DIR = WORKSPACE / "pino-dataset"
28
+ OUT_DIR = WORKSPACE / "ab_out"
29
+
30
+ SOURCE_REPO = os.environ.get("PINO_SOURCE_REPO", "mattbitzesty/pino-source-code")
31
+ DATASET_REPO = os.environ.get("PINO_DATASET_REPO", "mattbitzesty/pino-synthetic-dataset-v3")
32
+ AB_REPO = os.environ.get("PINO_AB_REPO", "mattbitzesty/pino-pimt-representation-ab")
33
+
34
+ EPOCHS = int(os.environ.get("PINO_EPOCHS", "20"))
35
+ BATCH = int(os.environ.get("PINO_BATCH", "32"))
36
+ LR = os.environ.get("PINO_LR", "3e-4")
37
+ SEED = int(os.environ.get("PINO_SEED", "42"))
38
+ TRAIN_RATIO = os.environ.get("PINO_TRAIN_RATIO", "0.85")
39
+ DATASET_NAME = "empirical_dataset_v9_plus_wisemoor_clean.repaired.jsonl"
40
+
41
+
42
+ def log(msg: str) -> None:
43
+ print(f"{time.strftime('%Y-%m-%dT%H:%M:%SZ')} {msg}", flush=True)
44
+
45
+
46
+ def run(cmd: list[str]) -> None:
47
+ log(f"$ {' '.join(cmd)}")
48
+ subprocess.check_call(cmd, stdout=sys.stdout, stderr=sys.stderr)
49
+
50
+
51
+ def main() -> int:
52
+ run([sys.executable, "-m", "pip", "install", "--quiet",
53
+ "huggingface-hub", "scipy", "tensorboard", "rdkit", "numpy",
54
+ "torch", "--index-url", "https://download.pytorch.org/whl/cu121"])
55
+
56
+ from huggingface_hub import snapshot_download
57
+ SOURCE_DIR.mkdir(parents=True, exist_ok=True)
58
+ DATASET_DIR.mkdir(parents=True, exist_ok=True)
59
+ OUT_DIR.mkdir(parents=True, exist_ok=True)
60
+
61
+ log(f"[AB] downloading source {SOURCE_REPO}")
62
+ snapshot_download(repo_id=SOURCE_REPO, repo_type="model", local_dir=str(SOURCE_DIR), token=TOKEN)
63
+ log(f"[AB] downloading dataset {DATASET_REPO}")
64
+ snapshot_download(repo_id=DATASET_REPO, repo_type="dataset", local_dir=str(DATASET_DIR), token=TOKEN)
65
+
66
+ # Writable registry.
67
+ reg_src = DATASET_DIR / "registry.db"
68
+ if reg_src.exists():
69
+ shutil.copy2(reg_src, WORKSPACE / "registry.db")
70
+ os.environ["PINO_REGISTRY_PATH"] = str(WORKSPACE / "registry.db")
71
+ # scalar_stats for heads
72
+ ss = DATASET_DIR / "scalar_stats_v1.json"
73
+ if ss.exists():
74
+ (SOURCE_DIR / "artifacts").mkdir(exist_ok=True)
75
+ shutil.copy2(ss, SOURCE_DIR / "artifacts" / "scalar_stats_v1.json")
76
+
77
+ run([sys.executable, "-m", "pip", "install", "--quiet", "-e", str(SOURCE_DIR)])
78
+ sys.path.insert(0, str(SOURCE_DIR / "src"))
79
+
80
+ import torch # noqa: E402
81
+ device = "cuda" if torch.cuda.is_available() else "cpu"
82
+ log(f"[AB] device={device} cuda_devices={torch.cuda.device_count()}")
83
+
84
+ data_path = str(DATASET_DIR / DATASET_NAME)
85
+ results = {}
86
+ for arm in ("morgan", "openpom_256"):
87
+ ckpt_name = f"pimt_ab_{arm}_gpu.pt"
88
+ logdir = OUT_DIR / "runs" / arm
89
+ log(f"[AB] ===== training arm {arm} ({EPOCHS} epochs) =====")
90
+ run([sys.executable, "-m", "pino.train",
91
+ "--data", data_path,
92
+ "--structural-source", arm,
93
+ "--epochs", str(EPOCHS),
94
+ "--batch-size", str(BATCH),
95
+ "--lr", LR,
96
+ "--seed", str(SEED),
97
+ "--train-ratio", str(TRAIN_RATIO),
98
+ "--output-dir", str(OUT_DIR),
99
+ "--checkpoint-name", ckpt_name,
100
+ "--log-dir", str(logdir)])
101
+ ckpt = OUT_DIR / ckpt_name
102
+ log(f"[AB] ===== frozen-benchmark eval arm {arm} =====")
103
+ eval_out = OUT_DIR / f"frozen_eval_{arm}_gpu.json"
104
+ run([sys.executable, str(SOURCE_DIR / "scripts" / "evaluate_frozen_benchmarks.py"),
105
+ "--checkpoint", str(ckpt),
106
+ "--structural-source", arm,
107
+ "--arm-label", f"{arm}_gpu",
108
+ "--output", str(eval_out)])
109
+ results[arm] = {"checkpoint": str(ckpt), "eval": str(eval_out)}
110
+
111
+ # Upload everything to the A/B repo.
112
+ from huggingface_hub import HfApi
113
+ api = HfApi(token=TOKEN)
114
+ for arm in ("morgan", "openpom_256"):
115
+ api.upload_file(path_or_fileobj=str(OUT_DIR / f"pimt_ab_{arm}_gpu.pt"),
116
+ path_in_repo=f"pimt_ab_{arm}_gpu.pt", repo_id=AB_REPO, repo_type="model")
117
+ api.upload_file(path_or_fileobj=str(OUT_DIR / f"frozen_eval_{arm}_gpu.json"),
118
+ path_in_repo=f"frozen_eval_{arm}_gpu.json", repo_id=AB_REPO, repo_type="model")
119
+ log(f"[AB] uploaded {arm} checkpoint + eval")
120
+
121
+ summary = {"epochs": EPOCHS, "batch": BATCH, "lr": LR, "seed": SEED,
122
+ "train_ratio": TRAIN_RATIO, "device": device, "dataset": DATASET_NAME,
123
+ "arms": results, "note": "two-arm representation A/B on HF GPU, longer run"}
124
+ api.upload_file(path_or_fileobj=json.dumps(summary, indent=2).encode(),
125
+ path_in_repo="gpu_run_summary.json", repo_id=AB_REPO, repo_type="model")
126
+ log("[AB] DONE")
127
+ return 0
128
+
129
+
130
+ if __name__ == "__main__":
131
+ try:
132
+ raise SystemExit(main())
133
+ except Exception as exc: # noqa: BLE001
134
+ import traceback
135
+ traceback.print_exc()
136
+ print(f"[AB] FAILED: {exc}", flush=True)
137
+ raise SystemExit(1)