Matthew Ford commited on
Commit
8377646
·
1 Parent(s): 634ed65

feat: pom_alltags structural source — 269-dim OpenPOM input, 575-dim tag objective head

Browse files

Third representation arm. structural_source='pom_alltags' uses genuine 256-dim
OpenPOM input (same as openpom_256 arm) but a 575-dim molequles all-tags objective
target instead of the 138-dim Pyrfume pyramid — isolates target-vocabulary as the
single variable against the OpenPOM arm.

- pimt_model: FragranceTrajectoryDataset gains objective_dim (138|575); selects
alltags_targets when objective_dim=575; objective_targets_to_pyramid is now
width-agnostic (138 or 575) instead of hard-rejecting non-138.
- train.py: --structural-source gains pom_alltags; threads objective_dim through
dataset construction + PIMTHeads; collate reads target width from the batch.
- Smoke-tested all three arms end-to-end on corrected v10_alltags dataset:
morgan (151->138), openpom_256 (269->138), pom_alltags (269->575); all train.


Former-commit-id: ccccfa67d1f3e5680360c153a6ba42024f8607c0
Former-commit-id: 8b4dcf6421418e22b29e80d2e9acb40bd2748273

Files changed (2) hide show
  1. src/pino/pimt_model.py +11 -5
  2. src/pino/train.py +15 -7
src/pino/pimt_model.py CHANGED
@@ -32,10 +32,11 @@ def objective_targets_to_pyramid(targets: np.ndarray | torch.Tensor) -> np.ndarr
32
  """
33
  if targets.ndim != 2:
34
  raise ValueError(f"objective targets must be 2-D, got shape {tuple(targets.shape)}")
35
- if targets.shape == (3, 138):
36
  return targets
37
- if targets.shape[1] != 138:
38
- raise ValueError(f"objective targets must have 138 descriptors, got shape {tuple(targets.shape)}")
 
39
 
40
  if isinstance(targets, torch.Tensor):
41
  chunks = torch.tensor_split(targets, 3, dim=0)
@@ -82,12 +83,14 @@ class FragranceTrajectoryDataset(Dataset):
82
  structural_source: str = "morgan",
83
  label_noise: bool = True,
84
  genre_map: dict[str, int] | None = None,
 
85
  ) -> None:
86
  self.data_path = Path(data_path) if data_path else None
87
  self.records = records
88
  self.max_ingredients = max_ingredients
89
  self.embedding_dim = embedding_dim
90
  self.state_dim = state_dim
 
91
  self.embedding_engine = OlfactoryEmbeddingEngine(use_fallback=use_embedding_fallback, structural_source=structural_source)
92
  self.embedding_dim = self.embedding_engine.embedding_dim
93
  self.label_noise = label_noise
@@ -154,8 +157,11 @@ class FragranceTrajectoryDataset(Dataset):
154
  strategy = record.get("metadata", {}).get("generation_strategy", "wildcard")
155
 
156
  # Prefer the new static pyramid targets (3, 138) when present; otherwise
157
- # fall back to the legacy time-resolved objective trajectory.
158
- if "pyramid_targets" in record:
 
 
 
159
  objective_targets = np.array(record["pyramid_targets"], dtype=np.float32)
160
  elif "objective_targets" in record:
161
  objective_targets = np.array(record["objective_targets"], dtype=np.float32)
 
32
  """
33
  if targets.ndim != 2:
34
  raise ValueError(f"objective targets must be 2-D, got shape {tuple(targets.shape)}")
35
+ if targets.shape[0] == 3:
36
  return targets
37
+ width = targets.shape[1]
38
+ if width not in (138, 575):
39
+ raise ValueError(f"objective targets must have 138 (pyramid) or 575 (all-tags) width, got {width}")
40
 
41
  if isinstance(targets, torch.Tensor):
42
  chunks = torch.tensor_split(targets, 3, dim=0)
 
83
  structural_source: str = "morgan",
84
  label_noise: bool = True,
85
  genre_map: dict[str, int] | None = None,
86
+ objective_dim: int = 138,
87
  ) -> None:
88
  self.data_path = Path(data_path) if data_path else None
89
  self.records = records
90
  self.max_ingredients = max_ingredients
91
  self.embedding_dim = embedding_dim
92
  self.state_dim = state_dim
93
+ self.objective_dim = objective_dim
94
  self.embedding_engine = OlfactoryEmbeddingEngine(use_fallback=use_embedding_fallback, structural_source=structural_source)
95
  self.embedding_dim = self.embedding_engine.embedding_dim
96
  self.label_noise = label_noise
 
157
  strategy = record.get("metadata", {}).get("generation_strategy", "wildcard")
158
 
159
  # Prefer the new static pyramid targets (3, 138) when present; otherwise
160
+ # fall back to the legacy time-resolved objective trajectory. For the
161
+ # pom_alltags arm (objective_dim=575) use the 575-dim molequles tag targets.
162
+ if self.objective_dim == 575 and "alltags_targets" in record:
163
+ objective_targets = np.array(record["alltags_targets"], dtype=np.float32)
164
+ elif "pyramid_targets" in record:
165
  objective_targets = np.array(record["pyramid_targets"], dtype=np.float32)
166
  elif "objective_targets" in record:
167
  objective_targets = np.array(record["objective_targets"], dtype=np.float32)
src/pino/train.py CHANGED
@@ -54,10 +54,12 @@ def pad_trajectory_collate(batch: list[dict[str, Any]]) -> dict[str, Any]:
54
  bsz = len(batch)
55
 
56
  emb_dim = batch[0]["tokens"].size(1)
 
 
57
  tokens = torch.zeros(bsz, max_molecules, emb_dim, dtype=torch.float32)
58
  physics = torch.zeros(bsz, max_timesteps, max_molecules, 2, dtype=torch.float32)
59
  src_key_padding_mask = torch.ones(bsz, max_molecules, dtype=torch.bool)
60
- target_obj = torch.zeros(bsz, 3, 138, dtype=torch.float32)
61
  target_sub_seasonality = torch.zeros(bsz, 4, dtype=torch.float32)
62
  target_sub_gender = torch.zeros(bsz, dtype=torch.float32)
63
  target_sub_wearability = torch.zeros(bsz, 2, dtype=torch.float32)
@@ -267,7 +269,7 @@ def main():
267
  parser.add_argument("--log-dir", default="runs")
268
  parser.add_argument("--checkpoint-name", default="pimt_v9.pt", help="Filename for the best checkpoint")
269
  parser.add_argument("--train-ratio", type=float, default=DEFAULT_TRAIN_RATIO, help="Molecule-disjoint train molecule ratio; default keeps a 15% molecule holdout")
270
- parser.add_argument("--structural-source", choices=["morgan", "openpom_256"], default="morgan", help="Structural embedding block: 138-dim Morgan fallback (input 151) or genuine 256-dim OpenPOM (input 269)")
271
  parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
272
  args = parser.parse_args()
273
 
@@ -286,8 +288,12 @@ def main():
286
  logger.info("Device: %s", device)
287
 
288
  logger.info("Structural source: %s", args.structural_source)
289
- embedding_dim = COMBINED_DIM_REAL_POM if args.structural_source == "openpom_256" else DEFAULT_EMBEDDING_DIM
290
- logger.info("Embedding input dim: %d", embedding_dim)
 
 
 
 
291
 
292
  cfg = SMOKE_TEST_CONFIG if args.smoke_test else {
293
  "hidden_dim": args.hidden_dim,
@@ -339,14 +345,16 @@ def main():
339
  train_dataset = FragranceTrajectoryDataset(
340
  records=train_records,
341
  use_embedding_fallback=True,
342
- structural_source=args.structural_source,
343
  genre_map=genre_map,
 
344
  )
345
  val_dataset = FragranceTrajectoryDataset(
346
  records=val_records,
347
  use_embedding_fallback=True,
348
- structural_source=args.structural_source,
349
  genre_map=genre_map,
 
350
  )
351
 
352
  train_loader = DataLoader(
@@ -363,7 +371,7 @@ def main():
363
  num_heads=cfg["num_heads"],
364
  num_layers=cfg["num_layers"],
365
  ).to(device)
366
- heads = PIMTHeads(hidden_dim=cfg["hidden_dim"], objective_dim=138).to(device)
367
 
368
  params = list(model.parameters()) + list(heads.parameters())
369
  optimizer = optim.AdamW(params, lr=cfg["lr"], weight_decay=cfg["weight_decay"])
 
54
  bsz = len(batch)
55
 
56
  emb_dim = batch[0]["tokens"].size(1)
57
+ # objective target width from the batch itself (138 for pyramid, 575 for all-tags)
58
+ obj_dim = batch[0]["target_obj"].size(-1)
59
  tokens = torch.zeros(bsz, max_molecules, emb_dim, dtype=torch.float32)
60
  physics = torch.zeros(bsz, max_timesteps, max_molecules, 2, dtype=torch.float32)
61
  src_key_padding_mask = torch.ones(bsz, max_molecules, dtype=torch.bool)
62
+ target_obj = torch.zeros(bsz, 3, obj_dim, dtype=torch.float32)
63
  target_sub_seasonality = torch.zeros(bsz, 4, dtype=torch.float32)
64
  target_sub_gender = torch.zeros(bsz, dtype=torch.float32)
65
  target_sub_wearability = torch.zeros(bsz, 2, dtype=torch.float32)
 
269
  parser.add_argument("--log-dir", default="runs")
270
  parser.add_argument("--checkpoint-name", default="pimt_v9.pt", help="Filename for the best checkpoint")
271
  parser.add_argument("--train-ratio", type=float, default=DEFAULT_TRAIN_RATIO, help="Molecule-disjoint train molecule ratio; default keeps a 15% molecule holdout")
272
+ 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)")
273
  parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
274
  args = parser.parse_args()
275
 
 
288
  logger.info("Device: %s", device)
289
 
290
  logger.info("Structural source: %s", args.structural_source)
291
+ use_pom = args.structural_source in ("openpom_256", "pom_alltags")
292
+ embedding_dim = COMBINED_DIM_REAL_POM if use_pom else DEFAULT_EMBEDDING_DIM
293
+ objective_dim = 575 if args.structural_source == "pom_alltags" else 138
294
+ # engine only knows the two structural blocks; the tag target is selected in the dataset via objective_dim
295
+ engine_source = "openpom_256" if args.structural_source == "pom_alltags" else args.structural_source
296
+ logger.info("Embedding input dim: %d | objective target dim: %d", embedding_dim, objective_dim)
297
 
298
  cfg = SMOKE_TEST_CONFIG if args.smoke_test else {
299
  "hidden_dim": args.hidden_dim,
 
345
  train_dataset = FragranceTrajectoryDataset(
346
  records=train_records,
347
  use_embedding_fallback=True,
348
+ structural_source=engine_source,
349
  genre_map=genre_map,
350
+ objective_dim=objective_dim,
351
  )
352
  val_dataset = FragranceTrajectoryDataset(
353
  records=val_records,
354
  use_embedding_fallback=True,
355
+ structural_source=engine_source,
356
  genre_map=genre_map,
357
+ objective_dim=objective_dim,
358
  )
359
 
360
  train_loader = DataLoader(
 
371
  num_heads=cfg["num_heads"],
372
  num_layers=cfg["num_layers"],
373
  ).to(device)
374
+ heads = PIMTHeads(hidden_dim=cfg["hidden_dim"], objective_dim=objective_dim).to(device)
375
 
376
  params = list(model.parameters()) + list(heads.parameters())
377
  optimizer = optim.AdamW(params, lr=cfg["lr"], weight_decay=cfg["weight_decay"])