refactor(train): directive-style molecule-disjoint data ingestion
Browse filesAdd explicit console prints for partitioning and 0% overlap assertion.
Pass train_dataset and val_dataset directly to DataLoaders. Remove test
split for this verification pass. state_dim remains locked to 2.
- src/pino/train.py +35 -18
src/pino/train.py
CHANGED
|
@@ -11,7 +11,7 @@ import torch
|
|
| 11 |
import torch.nn as nn
|
| 12 |
import torch.nn.functional as F
|
| 13 |
import torch.optim as optim
|
| 14 |
-
from torch.utils.data import DataLoader
|
| 15 |
from torch.utils.tensorboard import SummaryWriter
|
| 16 |
|
| 17 |
from pino.heads import PIMTHeads
|
|
@@ -291,30 +291,47 @@ def main():
|
|
| 291 |
all_genres = ["citrus_cologne", "fougere", "floral_woody", "amber_oriental", "wildcard"]
|
| 292 |
genre_map = {genre: idx for idx, genre in enumerate(all_genres)}
|
| 293 |
|
| 294 |
-
#
|
| 295 |
-
|
| 296 |
dataset_dict = create_molecule_disjoint_split(
|
| 297 |
args.data, train_ratio=0.8, seed=args.seed, solvent_cas="64-17-5"
|
| 298 |
)
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
use_embedding_fallback=True,
|
| 302 |
genre_map=genre_map,
|
| 303 |
)
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
train_loader = DataLoader(
|
| 311 |
-
|
| 312 |
)
|
| 313 |
val_loader = DataLoader(
|
| 314 |
-
|
| 315 |
-
)
|
| 316 |
-
test_loader = DataLoader(
|
| 317 |
-
test_ds, batch_size=cfg["batch_size"], shuffle=False, num_workers=args.workers, collate_fn=pad_trajectory_collate
|
| 318 |
)
|
| 319 |
|
| 320 |
model = PhysicsInformedMixtureTransformer(
|
|
@@ -364,10 +381,10 @@ def main():
|
|
| 364 |
}, checkpoint_path)
|
| 365 |
logger.info("Saved best checkpoint to %s", checkpoint_path)
|
| 366 |
|
| 367 |
-
|
| 368 |
logger.info(
|
| 369 |
-
"
|
| 370 |
-
|
| 371 |
)
|
| 372 |
writer.close()
|
| 373 |
return checkpoint_path
|
|
|
|
| 11 |
import torch.nn as nn
|
| 12 |
import torch.nn.functional as F
|
| 13 |
import torch.optim as optim
|
| 14 |
+
from torch.utils.data import DataLoader
|
| 15 |
from torch.utils.tensorboard import SummaryWriter
|
| 16 |
|
| 17 |
from pino.heads import PIMTHeads
|
|
|
|
| 291 |
all_genres = ["citrus_cologne", "fougere", "floral_woody", "amber_oriental", "wildcard"]
|
| 292 |
genre_map = {genre: idx for idx, genre in enumerate(all_genres)}
|
| 293 |
|
| 294 |
+
# Ingest and slice the dataset using the strict molecule-disjoint boundaries.
|
| 295 |
+
print("⏳ Initiating strict molecule-disjoint dataset partitioning...")
|
| 296 |
dataset_dict = create_molecule_disjoint_split(
|
| 297 |
args.data, train_ratio=0.8, seed=args.seed, solvent_cas="64-17-5"
|
| 298 |
)
|
| 299 |
+
|
| 300 |
+
train_dataset = FragranceTrajectoryDataset(
|
| 301 |
+
records=dataset_dict["train"].to_list(),
|
| 302 |
+
use_embedding_fallback=True,
|
| 303 |
+
genre_map=genre_map,
|
| 304 |
+
)
|
| 305 |
+
val_dataset = FragranceTrajectoryDataset(
|
| 306 |
+
records=dataset_dict["validation"].to_list(),
|
| 307 |
use_embedding_fallback=True,
|
| 308 |
genre_map=genre_map,
|
| 309 |
)
|
| 310 |
+
|
| 311 |
+
# Verify zero molecular overlap between splits and surface it to console.
|
| 312 |
+
def _cas_set(records):
|
| 313 |
+
cas = set()
|
| 314 |
+
for rec in records:
|
| 315 |
+
for comp in rec.get("metadata", {}).get("initial_components") or rec.get("formula", []):
|
| 316 |
+
c = comp.get("cas")
|
| 317 |
+
if c and c != "64-17-5":
|
| 318 |
+
cas.add(c)
|
| 319 |
+
return cas
|
| 320 |
+
|
| 321 |
+
train_cas = _cas_set(dataset_dict["train"].to_list())
|
| 322 |
+
val_cas = _cas_set(dataset_dict["validation"].to_list())
|
| 323 |
+
overlap = train_cas & val_cas
|
| 324 |
+
overlap_pct = 100.0 * len(overlap) / max(len(train_cas | val_cas), 1)
|
| 325 |
+
print(f"🔒 Disjoint isolation check: {len(overlap)} shared molecules ({overlap_pct:.2f}%) between train and validation.")
|
| 326 |
+
assert len(overlap) == 0, f"Molecule leakage detected: {overlap}"
|
| 327 |
+
|
| 328 |
+
print(f"📊 Dataset fully loaded. Training samples: {len(train_dataset)} | Validation samples: {len(val_dataset)}")
|
| 329 |
|
| 330 |
train_loader = DataLoader(
|
| 331 |
+
train_dataset, batch_size=cfg["batch_size"], shuffle=True, num_workers=args.workers, collate_fn=pad_trajectory_collate
|
| 332 |
)
|
| 333 |
val_loader = DataLoader(
|
| 334 |
+
val_dataset, batch_size=cfg["batch_size"], shuffle=False, num_workers=args.workers, collate_fn=pad_trajectory_collate
|
|
|
|
|
|
|
|
|
|
| 335 |
)
|
| 336 |
|
| 337 |
model = PhysicsInformedMixtureTransformer(
|
|
|
|
| 381 |
}, checkpoint_path)
|
| 382 |
logger.info("Saved best checkpoint to %s", checkpoint_path)
|
| 383 |
|
| 384 |
+
val_final_metrics = validate(model, heads, val_loader, device, weights)
|
| 385 |
logger.info(
|
| 386 |
+
"Final Val | total=%.4f | obj=%.4f | season=%.4f | gender=%.4f | wear=%.4f | contrastive=%.4f",
|
| 387 |
+
val_final_metrics["total"], val_final_metrics["obj"], val_final_metrics["season"], val_final_metrics["gender"], val_final_metrics["wear"], val_final_metrics["contrastive"],
|
| 388 |
)
|
| 389 |
writer.close()
|
| 390 |
return checkpoint_path
|