Upload src/pino/train.py with huggingface_hub
Browse files- src/pino/train.py +54 -36
src/pino/train.py
CHANGED
|
@@ -276,6 +276,7 @@ def main():
|
|
| 276 |
parser.add_argument("--structural-source", choices=["morgan", "openpom_256", "pom_alltags"], default="morgan", help="Structural embedding block + objective target: 'morgan' (138-dim Morgan, input 151, 138-dim pyramid) | 'openpom_256' (genuine 256-dim OpenPOM, input 269, 138-dim pyramid) | 'pom_alltags' (genuine 256-dim OpenPOM, input 269, 575-dim molequles all-tags objective)")
|
| 277 |
parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
|
| 278 |
parser.add_argument("--use-gamma", action="store_true", help="Add the UNIFAC blend-interaction (gamma) 3rd physics channel; requires a gamma-augmented dataset (physics_gamma field)")
|
|
|
|
| 279 |
args = parser.parse_args()
|
| 280 |
|
| 281 |
logging.basicConfig(
|
|
@@ -329,44 +330,61 @@ def main():
|
|
| 329 |
control_records = [r for r in all_records if r.get("is_control", False)]
|
| 330 |
print(f"π Extracted {len(control_records)} pure single-molecule anchors.")
|
| 331 |
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
if not train_records or not val_records:
|
| 368 |
raise RuntimeError(
|
| 369 |
-
"
|
| 370 |
"Adjust --train-ratio or --seed."
|
| 371 |
)
|
| 372 |
|
|
|
|
| 276 |
parser.add_argument("--structural-source", choices=["morgan", "openpom_256", "pom_alltags"], default="morgan", help="Structural embedding block + objective target: 'morgan' (138-dim Morgan, input 151, 138-dim pyramid) | 'openpom_256' (genuine 256-dim OpenPOM, input 269, 138-dim pyramid) | 'pom_alltags' (genuine 256-dim OpenPOM, input 269, 575-dim molequles all-tags objective)")
|
| 277 |
parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
|
| 278 |
parser.add_argument("--use-gamma", action="store_true", help="Add the UNIFAC blend-interaction (gamma) 3rd physics channel; requires a gamma-augmented dataset (physics_gamma field)")
|
| 279 |
+
parser.add_argument("--split-strategy", choices=["molecule", "formula"], default="molecule", help="molecule = strict molecule-disjoint holdout (default, used for frozen-task headline results); formula = random formula-level holdout (E1 physics-gamma substantivity experiment; discloses molecule leakage for measured-Poucher eval power)")
|
| 280 |
args = parser.parse_args()
|
| 281 |
|
| 282 |
logging.basicConfig(
|
|
|
|
| 330 |
control_records = [r for r in all_records if r.get("is_control", False)]
|
| 331 |
print(f"π Extracted {len(control_records)} pure single-molecule anchors.")
|
| 332 |
|
| 333 |
+
if getattr(args, "split_strategy", "molecule") == "formula":
|
| 334 |
+
# Formula-level random holdout. Used by the E1 physics-gamma substantivity
|
| 335 |
+
# experiment, where strict molecule-disjointness starves the measured-
|
| 336 |
+
# Poucher eval (n~10) because Poucher molecules are ubiquitous. Trades a
|
| 337 |
+
# weaker generalization claim (molecules may leak) for eval power; the
|
| 338 |
+
# leakage is disclosed in the run summary. The frozen-task headline
|
| 339 |
+
# results in the paper still use the molecule-disjoint path below.
|
| 340 |
+
rng = np.random.default_rng(args.seed)
|
| 341 |
+
n_total = len(all_records)
|
| 342 |
+
n_val = max(1, int(round(n_total * (1.0 - args.train_ratio))))
|
| 343 |
+
perm = rng.permutation(n_total)
|
| 344 |
+
val_idx = set(perm[:n_val].tolist())
|
| 345 |
+
train_records = [all_records[i] for i in range(n_total) if i not in val_idx]
|
| 346 |
+
val_records = [all_records[i] for i in sorted(val_idx)]
|
| 347 |
+
print(f"π Formula-level split (E1; leakage disclosed): train={len(train_records)} val={len(val_records)}")
|
| 348 |
+
else:
|
| 349 |
+
split = create_molecule_disjoint_split_from_records(
|
| 350 |
+
all_records,
|
| 351 |
+
train_ratio=args.train_ratio,
|
| 352 |
+
seed=args.seed,
|
| 353 |
+
)
|
| 354 |
+
train_records = split["train"]
|
| 355 |
+
val_records = split["validation"]
|
| 356 |
+
|
| 357 |
+
if getattr(args, "split_strategy", "molecule") == "molecule":
|
| 358 |
+
train_cas = set(split["train_compounds"])
|
| 359 |
+
val_cas = set(split["validation_compounds"])
|
| 360 |
+
overlap = train_cas & val_cas
|
| 361 |
+
print(f"π Molecule isolation check: {len(overlap)} active CAS shared between splits.")
|
| 362 |
+
print(f"π« Excluded mixed-boundary records: {len(split['excluded_indices'])}")
|
| 363 |
+
assert len(overlap) == 0, f"Molecule leakage detected: {sorted(overlap)}"
|
| 364 |
+
# Persist the zero-intersection assertion for the paper's reproducibility ledger.
|
| 365 |
+
try:
|
| 366 |
+
leakage_report = {
|
| 367 |
+
"split_strategy": "molecule_disjoint",
|
| 368 |
+
"seed": args.seed,
|
| 369 |
+
"train_ratio": args.train_ratio,
|
| 370 |
+
"n_train_records": len(train_records),
|
| 371 |
+
"n_validation_records": len(val_records),
|
| 372 |
+
"n_excluded_records": len(split["excluded_indices"]),
|
| 373 |
+
"n_train_molecules": len(train_cas),
|
| 374 |
+
"n_validation_molecules": len(val_cas),
|
| 375 |
+
"shared_molecule_count": len(overlap),
|
| 376 |
+
"zero_intersection_assertion": "PASSED" if not overlap else "FAILED",
|
| 377 |
+
}
|
| 378 |
+
Path(args.output_dir).mkdir(parents=True, exist_ok=True)
|
| 379 |
+
report_name = f"split_leakage_report_seed{args.seed}.json"
|
| 380 |
+
with open(Path(args.output_dir) / report_name, "w") as rf:
|
| 381 |
+
json.dump(leakage_report, rf, indent=2)
|
| 382 |
+
print(f"π Split leakage report: {report_name} (zero-intersection: {leakage_report['zero_intersection_assertion']})")
|
| 383 |
+
except Exception as e: # noqa: BLE001
|
| 384 |
+
logger.warning("Could not write split leakage report: %s", e)
|
| 385 |
if not train_records or not val_records:
|
| 386 |
raise RuntimeError(
|
| 387 |
+
"Split produced an empty train or validation set. "
|
| 388 |
"Adjust --train-ratio or --seed."
|
| 389 |
)
|
| 390 |
|