feat: wire genuine 256-dim OpenPOM into training (--structural-source)
Browse filesAdds a structural_source toggle to OlfactoryEmbeddingEngine and threads it
through FragranceTrajectoryDataset -> train.py CLI (--structural-source
morgan|openpom_256). Genuine OpenPOM v1.0.0 ensemble (256-dim, 10-model mean)
is loaded from artifacts/pom and takes priority over the registry's 138-dim
Morgan fallback. CAS absent from the genuine set get a real Morgan block
zero-padded to 256 so the combined input dim stays constant (269 vs 151).
Model input_proj and the collate pad dim now derive from the actual embedding
dim rather than a hardcoded 151. Both arms smoke-test end-to-end:
morgan val_total=0.6349 (dim 151), openpom_256 val_total=0.6397 (dim 269).
POM asset load fails closed if absent (no silent Morgan substitution).
Former-commit-id: 10a28c38b626dc97f610c0eb98798b4772fb17e3
Former-commit-id: c57e69d542d2e258990391b3f2bd2e12d37e823f
- src/pino/embeddings.py +75 -32
- src/pino/pimt_model.py +3 -1
- src/pino/train.py +11 -2
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
| 2 |
|
| 3 |
import json
|
| 4 |
import logging
|
|
|
|
| 5 |
from typing import Any
|
| 6 |
|
| 7 |
import numpy as np
|
|
@@ -18,11 +19,16 @@ logger = logging.getLogger("pino.embeddings")
|
|
| 18 |
class RealOpenPOMUnavailableError(RuntimeError):
|
| 19 |
"""Raised when a caller requires real POM features but no model is loaded."""
|
| 20 |
|
| 21 |
-
STRUCTURAL_DIM = OPENPOM_DIM # 138
|
|
|
|
| 22 |
SHAPE_DIM = SHAPE_DIM # 7
|
| 23 |
PHYSICAL_DIM = 2 # molecular_weight, logp
|
| 24 |
FUNCTIONAL_DIM = 4 # ester, alcohol, ketone, aldehyde
|
| 25 |
COMBINED_DIM = STRUCTURAL_DIM + SHAPE_DIM + PHYSICAL_DIM + FUNCTIONAL_DIM # 151
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Mute RDKit's internal C++ warning streams globally.
|
| 28 |
rd_logger = RDLogger.logger()
|
|
@@ -91,18 +97,48 @@ class OlfactoryEmbeddingEngine:
|
|
| 91 |
Empty or invalid inputs short-circuit to a zero fallback without invoking RDKit.
|
| 92 |
"""
|
| 93 |
|
| 94 |
-
def __init__(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
self.use_fallback = use_fallback
|
| 96 |
-
self.
|
|
|
|
|
|
|
| 97 |
self.shape_dim = SHAPE_DIM
|
| 98 |
self.physical_dim = PHYSICAL_DIM
|
| 99 |
self.functional_dim = FUNCTIONAL_DIM
|
| 100 |
-
self.embedding_dim =
|
|
|
|
|
|
|
| 101 |
self.registry = AromaRegistry()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
self.global_median_logp = self._compute_median_logp() if global_median_logp is None else global_median_logp
|
| 103 |
if not self.use_fallback:
|
| 104 |
self._initialize_real_openpom()
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
def _compute_median_logp(self) -> float:
|
| 107 |
rows = self.registry._conn.execute(
|
| 108 |
"SELECT logp FROM aroma_chemicals WHERE logp IS NOT NULL AND logp != 0"
|
|
@@ -143,7 +179,7 @@ class OlfactoryEmbeddingEngine:
|
|
| 143 |
return _functional_group_flags(record.get("unifac_groups"))
|
| 144 |
|
| 145 |
def get_embedding(self, smiles: str, cas: str | None = None) -> np.ndarray:
|
| 146 |
-
"""Main entry point. Returns a
|
| 147 |
normalized_cas = self._normalized_cas(cas)
|
| 148 |
is_natural = bool(cas and str(cas).startswith("NATURAL:"))
|
| 149 |
|
|
@@ -151,9 +187,13 @@ class OlfactoryEmbeddingEngine:
|
|
| 151 |
try:
|
| 152 |
record = self.registry.get(normalized_cas)
|
| 153 |
if record:
|
| 154 |
-
|
| 155 |
-
|
| 156 |
structural = self._compute_structural_embedding(smiles, cas)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
shape = np.asarray(record.get("shape_3d_features") or [0.0] * SHAPE_DIM, dtype=np.float32)
|
| 158 |
if shape.shape[0] != SHAPE_DIM or (not is_natural and np.count_nonzero(shape) == 0):
|
| 159 |
shape = self._compute_shape_features(smiles, cas)
|
|
@@ -162,8 +202,6 @@ class OlfactoryEmbeddingEngine:
|
|
| 162 |
combined = np.concatenate([structural, shape, physical, functional]).astype(np.float32)
|
| 163 |
norm = np.linalg.norm(combined)
|
| 164 |
return combined / norm if norm > 0 else combined
|
| 165 |
-
# If the registry has no record at all but this is a natural-oil token,
|
| 166 |
-
# still try to resolve from the natural-oil constituent profile.
|
| 167 |
if is_natural:
|
| 168 |
structural = self._compute_structural_embedding(smiles, cas)
|
| 169 |
shape = self._compute_shape_features(smiles, cas)
|
|
@@ -178,7 +216,7 @@ class OlfactoryEmbeddingEngine:
|
|
| 178 |
# Fallback: compute structural/shape features on the fly.
|
| 179 |
structural = self._compute_structural_embedding(smiles, cas)
|
| 180 |
shape = self._compute_shape_features(smiles, cas)
|
| 181 |
-
physical = np.array([0.5, self.global_median_logp / 5.0], dtype=np.float32)
|
| 182 |
functional = _functional_group_flags(None)
|
| 183 |
combined = np.concatenate([structural, shape, physical, functional]).astype(np.float32)
|
| 184 |
norm = np.linalg.norm(combined)
|
|
@@ -187,7 +225,18 @@ class OlfactoryEmbeddingEngine:
|
|
| 187 |
def _compute_structural_embedding(self, smiles: str, cas: str | None = None) -> np.ndarray:
|
| 188 |
normalized_cas = self._normalized_cas(cas)
|
| 189 |
|
| 190 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
if normalized_cas:
|
| 192 |
try:
|
| 193 |
record = self.registry.get(normalized_cas)
|
|
@@ -198,8 +247,7 @@ class OlfactoryEmbeddingEngine:
|
|
| 198 |
except Exception as exc:
|
| 199 |
logger.debug("Registry lookup failed for %s: %s", normalized_cas, exc)
|
| 200 |
|
| 201 |
-
|
| 202 |
-
if normalized_cas and ((cas or "").startswith("NATURAL:") or normalized_cas.startswith("8") or normalized_cas.startswith("6") or normalized_cas.startswith("9")):
|
| 203 |
try:
|
| 204 |
all_records = self.registry.all_records()
|
| 205 |
openpom, _ = resolve_natural_oil_vectors(normalized_cas, all_records)
|
|
@@ -208,35 +256,30 @@ class OlfactoryEmbeddingEngine:
|
|
| 208 |
except Exception as exc:
|
| 209 |
logger.debug("Natural oil resolution failed for %s: %s", normalized_cas, exc)
|
| 210 |
|
| 211 |
-
|
| 212 |
-
if not self._is_valid_smiles(smiles):
|
| 213 |
-
return np.zeros(self.structural_dim, dtype=np.float32)
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
mol = Chem.MolFromSmiles(smiles)
|
| 216 |
if not mol:
|
| 217 |
-
return np.zeros(
|
| 218 |
-
|
| 219 |
try:
|
| 220 |
fpgen = AllChem.GetMorganGenerator(radius=2, fpSize=128)
|
| 221 |
-
|
| 222 |
-
fp_array = np.array(fp_bitvect, dtype=np.float32)
|
| 223 |
except AttributeError:
|
| 224 |
fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=2, nBits=128)
|
| 225 |
fp_array = np.array(fp, dtype=np.float32)
|
| 226 |
-
|
| 227 |
physchem = np.array([
|
| 228 |
-
Descriptors.MolWt(mol),
|
| 229 |
-
Descriptors.
|
| 230 |
-
Descriptors.
|
| 231 |
-
Descriptors.
|
| 232 |
-
Descriptors.NumHAcceptors(mol),
|
| 233 |
-
Descriptors.NumHDonors(mol),
|
| 234 |
-
Descriptors.NumRotatableBonds(mol),
|
| 235 |
-
Descriptors.FractionCSP3(mol),
|
| 236 |
-
Descriptors.TPSA(mol),
|
| 237 |
-
Descriptors.LabuteASA(mol)
|
| 238 |
], dtype=np.float32)
|
| 239 |
-
|
| 240 |
return np.concatenate([fp_array, physchem]).astype(np.float32)
|
| 241 |
|
| 242 |
def _compute_shape_features(self, smiles: str, cas: str | None = None) -> np.ndarray:
|
|
|
|
| 2 |
|
| 3 |
import json
|
| 4 |
import logging
|
| 5 |
+
from pathlib import Path
|
| 6 |
from typing import Any
|
| 7 |
|
| 8 |
import numpy as np
|
|
|
|
| 19 |
class RealOpenPOMUnavailableError(RuntimeError):
|
| 20 |
"""Raised when a caller requires real POM features but no model is loaded."""
|
| 21 |
|
| 22 |
+
STRUCTURAL_DIM = OPENPOM_DIM # 138 (Morgan fallback structural block)
|
| 23 |
+
REAL_POM_DIM = 256 # genuine OpenPOM v1.0.0 penultimate embedding (ablation-proven)
|
| 24 |
SHAPE_DIM = SHAPE_DIM # 7
|
| 25 |
PHYSICAL_DIM = 2 # molecular_weight, logp
|
| 26 |
FUNCTIONAL_DIM = 4 # ester, alcohol, ketone, aldehyde
|
| 27 |
COMBINED_DIM = STRUCTURAL_DIM + SHAPE_DIM + PHYSICAL_DIM + FUNCTIONAL_DIM # 151
|
| 28 |
+
COMBINED_DIM_REAL_POM = REAL_POM_DIM + SHAPE_DIM + PHYSICAL_DIM + FUNCTIONAL_DIM # 269
|
| 29 |
+
|
| 30 |
+
_REPO_ROOT = Path(__file__).resolve().parents[2]
|
| 31 |
+
_POM_DIR = _REPO_ROOT / "artifacts" / "pom"
|
| 32 |
|
| 33 |
# Mute RDKit's internal C++ warning streams globally.
|
| 34 |
rd_logger = RDLogger.logger()
|
|
|
|
| 97 |
Empty or invalid inputs short-circuit to a zero fallback without invoking RDKit.
|
| 98 |
"""
|
| 99 |
|
| 100 |
+
def __init__(
|
| 101 |
+
self,
|
| 102 |
+
use_fallback: bool = True,
|
| 103 |
+
global_median_logp: float = 2.15,
|
| 104 |
+
structural_source: str = "morgan",
|
| 105 |
+
) -> None:
|
| 106 |
self.use_fallback = use_fallback
|
| 107 |
+
self.structural_source = structural_source
|
| 108 |
+
self.use_real_pom = structural_source == "openpom_256"
|
| 109 |
+
self.structural_dim = REAL_POM_DIM if self.use_real_pom else STRUCTURAL_DIM
|
| 110 |
self.shape_dim = SHAPE_DIM
|
| 111 |
self.physical_dim = PHYSICAL_DIM
|
| 112 |
self.functional_dim = FUNCTIONAL_DIM
|
| 113 |
+
self.embedding_dim = (
|
| 114 |
+
COMBINED_DIM_REAL_POM if self.use_real_pom else COMBINED_DIM
|
| 115 |
+
)
|
| 116 |
self.registry = AromaRegistry()
|
| 117 |
+
self._pom_index: dict[str, int] = {}
|
| 118 |
+
self._pom_matrix: np.ndarray | None = None
|
| 119 |
+
if self.use_real_pom:
|
| 120 |
+
self._load_real_pom()
|
| 121 |
self.global_median_logp = self._compute_median_logp() if global_median_logp is None else global_median_logp
|
| 122 |
if not self.use_fallback:
|
| 123 |
self._initialize_real_openpom()
|
| 124 |
|
| 125 |
+
def _load_real_pom(self) -> None:
|
| 126 |
+
"""Load the genuine OpenPOM v1.0.0 ensemble (256-dim, 10-model mean).
|
| 127 |
+
|
| 128 |
+
Indexed by CAS (with some SMILES:-prefixed keys). Fail closed if the
|
| 129 |
+
provenance-manifest asset is absent so a Morgan feature is never
|
| 130 |
+
silently substituted for POM."""
|
| 131 |
+
emb_path = _POM_DIR / "pom_embeddings.npy"
|
| 132 |
+
idx_path = _POM_DIR / "pom_index.json"
|
| 133 |
+
if not (emb_path.exists() and idx_path.exists()):
|
| 134 |
+
raise RealOpenPOMUnavailableError(
|
| 135 |
+
f"Genuine POM asset missing under {_POM_DIR}; cannot honour structural_source='openpom_256'"
|
| 136 |
+
)
|
| 137 |
+
self._pom_matrix = np.load(emb_path).astype(np.float32)
|
| 138 |
+
idx = json.loads(idx_path.read_text())
|
| 139 |
+
ids = idx.get("ids", [])
|
| 140 |
+
self._pom_index = {self._normalized_cas(k): i for i, k in enumerate(ids)}
|
| 141 |
+
|
| 142 |
def _compute_median_logp(self) -> float:
|
| 143 |
rows = self.registry._conn.execute(
|
| 144 |
"SELECT logp FROM aroma_chemicals WHERE logp IS NOT NULL AND logp != 0"
|
|
|
|
| 179 |
return _functional_group_flags(record.get("unifac_groups"))
|
| 180 |
|
| 181 |
def get_embedding(self, smiles: str, cas: str | None = None) -> np.ndarray:
|
| 182 |
+
"""Main entry point. Returns a float32 embedding (dim = self.embedding_dim)."""
|
| 183 |
normalized_cas = self._normalized_cas(cas)
|
| 184 |
is_natural = bool(cas and str(cas).startswith("NATURAL:"))
|
| 185 |
|
|
|
|
| 187 |
try:
|
| 188 |
record = self.registry.get(normalized_cas)
|
| 189 |
if record:
|
| 190 |
+
if self.use_real_pom:
|
| 191 |
+
# POM arm: never reuse the registry's 138-dim Morgan block.
|
| 192 |
structural = self._compute_structural_embedding(smiles, cas)
|
| 193 |
+
else:
|
| 194 |
+
structural = np.asarray(record.get("openpom_embedding") or [0.0] * STRUCTURAL_DIM, dtype=np.float32)
|
| 195 |
+
if structural.shape[0] != STRUCTURAL_DIM or (not is_natural and np.count_nonzero(structural) == 0):
|
| 196 |
+
structural = self._compute_structural_embedding(smiles, cas)
|
| 197 |
shape = np.asarray(record.get("shape_3d_features") or [0.0] * SHAPE_DIM, dtype=np.float32)
|
| 198 |
if shape.shape[0] != SHAPE_DIM or (not is_natural and np.count_nonzero(shape) == 0):
|
| 199 |
shape = self._compute_shape_features(smiles, cas)
|
|
|
|
| 202 |
combined = np.concatenate([structural, shape, physical, functional]).astype(np.float32)
|
| 203 |
norm = np.linalg.norm(combined)
|
| 204 |
return combined / norm if norm > 0 else combined
|
|
|
|
|
|
|
| 205 |
if is_natural:
|
| 206 |
structural = self._compute_structural_embedding(smiles, cas)
|
| 207 |
shape = self._compute_shape_features(smiles, cas)
|
|
|
|
| 216 |
# Fallback: compute structural/shape features on the fly.
|
| 217 |
structural = self._compute_structural_embedding(smiles, cas)
|
| 218 |
shape = self._compute_shape_features(smiles, cas)
|
| 219 |
+
physical = np.array([0.5, self.global_median_logp / 5.0], dtype=np.float32)
|
| 220 |
functional = _functional_group_flags(None)
|
| 221 |
combined = np.concatenate([structural, shape, physical, functional]).astype(np.float32)
|
| 222 |
norm = np.linalg.norm(combined)
|
|
|
|
| 225 |
def _compute_structural_embedding(self, smiles: str, cas: str | None = None) -> np.ndarray:
|
| 226 |
normalized_cas = self._normalized_cas(cas)
|
| 227 |
|
| 228 |
+
# Genuine OpenPOM arm: authoritative 256-dim ensemble for known CAS.
|
| 229 |
+
if self.use_real_pom:
|
| 230 |
+
if normalized_cas and normalized_cas in self._pom_index and self._pom_matrix is not None:
|
| 231 |
+
return self._pom_matrix[self._pom_index[normalized_cas]]
|
| 232 |
+
# CAS absent from the genuine-POM asset: real Morgan block, zero-padded
|
| 233 |
+
# to the 256-dim structural slot so the combined dim stays constant.
|
| 234 |
+
morgan = self._morgan_structural(smiles)
|
| 235 |
+
padded = np.zeros(self.structural_dim, dtype=np.float32)
|
| 236 |
+
padded[: morgan.shape[0]] = morgan
|
| 237 |
+
return padded
|
| 238 |
+
|
| 239 |
+
# Morgan arm: live SQLite cache, natural-oil blend, then Morgan compute.
|
| 240 |
if normalized_cas:
|
| 241 |
try:
|
| 242 |
record = self.registry.get(normalized_cas)
|
|
|
|
| 247 |
except Exception as exc:
|
| 248 |
logger.debug("Registry lookup failed for %s: %s", normalized_cas, exc)
|
| 249 |
|
| 250 |
+
if normalized_cas and ((cas or "").startswith("NATURAL:") or normalized_cas.startswith(("8", "6", "9"))):
|
|
|
|
| 251 |
try:
|
| 252 |
all_records = self.registry.all_records()
|
| 253 |
openpom, _ = resolve_natural_oil_vectors(normalized_cas, all_records)
|
|
|
|
| 256 |
except Exception as exc:
|
| 257 |
logger.debug("Natural oil resolution failed for %s: %s", normalized_cas, exc)
|
| 258 |
|
| 259 |
+
return self._morgan_structural(smiles)
|
|
|
|
|
|
|
| 260 |
|
| 261 |
+
def _morgan_structural(self, smiles: str) -> np.ndarray:
|
| 262 |
+
"""Deterministic 128-bit Morgan + 10 physicochemical descriptors (138-D).
|
| 263 |
+
|
| 264 |
+
Used as the Morgan arm's structural block and as the fallback for CAS
|
| 265 |
+
absent from the genuine-POM asset."""
|
| 266 |
+
if not self._is_valid_smiles(smiles):
|
| 267 |
+
return np.zeros(STRUCTURAL_DIM, dtype=np.float32)
|
| 268 |
mol = Chem.MolFromSmiles(smiles)
|
| 269 |
if not mol:
|
| 270 |
+
return np.zeros(STRUCTURAL_DIM, dtype=np.float32)
|
|
|
|
| 271 |
try:
|
| 272 |
fpgen = AllChem.GetMorganGenerator(radius=2, fpSize=128)
|
| 273 |
+
fp_array = np.array(fpgen.GetFingerprint(mol), dtype=np.float32)
|
|
|
|
| 274 |
except AttributeError:
|
| 275 |
fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=2, nBits=128)
|
| 276 |
fp_array = np.array(fp, dtype=np.float32)
|
|
|
|
| 277 |
physchem = np.array([
|
| 278 |
+
Descriptors.MolWt(mol), Descriptors.ExactMolWt(mol), Descriptors.MolLogP(mol),
|
| 279 |
+
Descriptors.HeavyAtomCount(mol), Descriptors.NumHAcceptors(mol),
|
| 280 |
+
Descriptors.NumHDonors(mol), Descriptors.NumRotatableBonds(mol),
|
| 281 |
+
Descriptors.FractionCSP3(mol), Descriptors.TPSA(mol), Descriptors.LabuteASA(mol),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
], dtype=np.float32)
|
|
|
|
| 283 |
return np.concatenate([fp_array, physchem]).astype(np.float32)
|
| 284 |
|
| 285 |
def _compute_shape_features(self, smiles: str, cas: str | None = None) -> np.ndarray:
|
|
@@ -79,6 +79,7 @@ class FragranceTrajectoryDataset(Dataset):
|
|
| 79 |
embedding_dim: int = DEFAULT_EMBEDDING_DIM,
|
| 80 |
state_dim: int = 4,
|
| 81 |
use_embedding_fallback: bool = True,
|
|
|
|
| 82 |
label_noise: bool = True,
|
| 83 |
genre_map: dict[str, int] | None = None,
|
| 84 |
) -> None:
|
|
@@ -87,7 +88,8 @@ class FragranceTrajectoryDataset(Dataset):
|
|
| 87 |
self.max_ingredients = max_ingredients
|
| 88 |
self.embedding_dim = embedding_dim
|
| 89 |
self.state_dim = state_dim
|
| 90 |
-
self.embedding_engine = OlfactoryEmbeddingEngine(use_fallback=use_embedding_fallback)
|
|
|
|
| 91 |
self.label_noise = label_noise
|
| 92 |
self.genre_map = genre_map or {}
|
| 93 |
self.poucher_substantivity = _load_poucher_substantivity_targets()
|
|
|
|
| 79 |
embedding_dim: int = DEFAULT_EMBEDDING_DIM,
|
| 80 |
state_dim: int = 4,
|
| 81 |
use_embedding_fallback: bool = True,
|
| 82 |
+
structural_source: str = "morgan",
|
| 83 |
label_noise: bool = True,
|
| 84 |
genre_map: dict[str, int] | None = None,
|
| 85 |
) -> None:
|
|
|
|
| 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
|
| 94 |
self.genre_map = genre_map or {}
|
| 95 |
self.poucher_substantivity = _load_poucher_substantivity_targets()
|
|
@@ -17,6 +17,7 @@ from torch.utils.data import DataLoader
|
|
| 17 |
from torch.utils.tensorboard import SummaryWriter
|
| 18 |
|
| 19 |
from pino.heads import PIMTHeads
|
|
|
|
| 20 |
from pino.pimt_model import (
|
| 21 |
DEFAULT_EMBEDDING_DIM,
|
| 22 |
FragranceTrajectoryDataset,
|
|
@@ -52,7 +53,8 @@ def pad_trajectory_collate(batch: list[dict[str, Any]]) -> dict[str, Any]:
|
|
| 52 |
max_timesteps = max(item["physics"].size(0) for item in batch)
|
| 53 |
bsz = len(batch)
|
| 54 |
|
| 55 |
-
|
|
|
|
| 56 |
physics = torch.zeros(bsz, max_timesteps, max_molecules, 2, dtype=torch.float32)
|
| 57 |
src_key_padding_mask = torch.ones(bsz, max_molecules, dtype=torch.bool)
|
| 58 |
target_obj = torch.zeros(bsz, 3, 138, dtype=torch.float32)
|
|
@@ -265,6 +267,7 @@ def main():
|
|
| 265 |
parser.add_argument("--log-dir", default="runs")
|
| 266 |
parser.add_argument("--checkpoint-name", default="pimt_v9.pt", help="Filename for the best checkpoint")
|
| 267 |
parser.add_argument("--train-ratio", type=float, default=DEFAULT_TRAIN_RATIO, help="Molecule-disjoint train molecule ratio; default keeps a 15% molecule holdout")
|
|
|
|
| 268 |
parser.add_argument("--smoke-test", action="store_true", help="Run lightweight CPU smoke test")
|
| 269 |
args = parser.parse_args()
|
| 270 |
|
|
@@ -282,6 +285,10 @@ def main():
|
|
| 282 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 283 |
logger.info("Device: %s", device)
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
cfg = SMOKE_TEST_CONFIG if args.smoke_test else {
|
| 286 |
"hidden_dim": args.hidden_dim,
|
| 287 |
"num_layers": args.num_layers,
|
|
@@ -332,11 +339,13 @@ def main():
|
|
| 332 |
train_dataset = FragranceTrajectoryDataset(
|
| 333 |
records=train_records,
|
| 334 |
use_embedding_fallback=True,
|
|
|
|
| 335 |
genre_map=genre_map,
|
| 336 |
)
|
| 337 |
val_dataset = FragranceTrajectoryDataset(
|
| 338 |
records=val_records,
|
| 339 |
use_embedding_fallback=True,
|
|
|
|
| 340 |
genre_map=genre_map,
|
| 341 |
)
|
| 342 |
|
|
@@ -348,7 +357,7 @@ def main():
|
|
| 348 |
)
|
| 349 |
|
| 350 |
model = PhysicsInformedMixtureTransformer(
|
| 351 |
-
embedding_dim=
|
| 352 |
state_dim=2,
|
| 353 |
hidden_dim=cfg["hidden_dim"],
|
| 354 |
num_heads=cfg["num_heads"],
|
|
|
|
| 17 |
from torch.utils.tensorboard import SummaryWriter
|
| 18 |
|
| 19 |
from pino.heads import PIMTHeads
|
| 20 |
+
from pino.embeddings import COMBINED_DIM_REAL_POM
|
| 21 |
from pino.pimt_model import (
|
| 22 |
DEFAULT_EMBEDDING_DIM,
|
| 23 |
FragranceTrajectoryDataset,
|
|
|
|
| 53 |
max_timesteps = max(item["physics"].size(0) for item in batch)
|
| 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)
|
|
|
|
| 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 |
|
|
|
|
| 285 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 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,
|
| 294 |
"num_layers": args.num_layers,
|
|
|
|
| 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 |
|
|
|
|
| 357 |
)
|
| 358 |
|
| 359 |
model = PhysicsInformedMixtureTransformer(
|
| 360 |
+
embedding_dim=embedding_dim,
|
| 361 |
state_dim=2,
|
| 362 |
hidden_dim=cfg["hidden_dim"],
|
| 363 |
num_heads=cfg["num_heads"],
|