Lazy-load embedding engine; force HF_REGISTRY_PATH to /data/registry.db
Browse files- scripts/hf_train_job.py +6 -0
- src/pino/embeddings.py +12 -3
scripts/hf_train_job.py
CHANGED
|
@@ -34,6 +34,12 @@ def _log(msg: str) -> None:
|
|
| 34 |
print(f"[LOG-FAIL] {exc}", flush=True)
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
_log("[HF-JOB] hf_train_job.py top-level started")
|
| 38 |
|
| 39 |
|
|
|
|
| 34 |
print(f"[LOG-FAIL] {exc}", flush=True)
|
| 35 |
|
| 36 |
|
| 37 |
+
# Force the fallback to the mounted dataset volume if the source-tree registry
|
| 38 |
+
# is not available (model volumes only contain tracked files).
|
| 39 |
+
if "HF_REGISTRY_PATH" not in os.environ:
|
| 40 |
+
os.environ["HF_REGISTRY_PATH"] = "/data/registry.db"
|
| 41 |
+
|
| 42 |
+
|
| 43 |
_log("[HF-JOB] hf_train_job.py top-level started")
|
| 44 |
|
| 45 |
|
src/pino/embeddings.py
CHANGED
|
@@ -287,13 +287,22 @@ class OlfactoryEmbeddingEngine:
|
|
| 287 |
raise NotImplementedError("Real OpenPOM model not yet loaded")
|
| 288 |
|
| 289 |
|
| 290 |
-
# Module-level
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
|
| 294 |
def get_openpom_embedding(smiles: str, dim: int = COMBINED_DIM, cas: str | None = None) -> np.ndarray:
|
| 295 |
"""Convenience accessor used by the PIMT pipeline."""
|
| 296 |
-
|
|
|
|
| 297 |
if embedding.shape[0] != dim:
|
| 298 |
raise ValueError(f"Embedding dimension mismatch: {embedding.shape[0]} != {dim}")
|
| 299 |
return embedding
|
|
|
|
| 287 |
raise NotImplementedError("Real OpenPOM model not yet loaded")
|
| 288 |
|
| 289 |
|
| 290 |
+
# Module-level engine is lazily instantiated so that import-time side effects
|
| 291 |
+
# (e.g., opening the SQLite registry) do not run until the first actual use.
|
| 292 |
+
_DEFAULT_ENGINE: OlfactoryEmbeddingEngine | None = None
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def _get_default_engine() -> OlfactoryEmbeddingEngine:
|
| 296 |
+
global _DEFAULT_ENGINE
|
| 297 |
+
if _DEFAULT_ENGINE is None:
|
| 298 |
+
_DEFAULT_ENGINE = OlfactoryEmbeddingEngine(use_fallback=True)
|
| 299 |
+
return _DEFAULT_ENGINE
|
| 300 |
|
| 301 |
|
| 302 |
def get_openpom_embedding(smiles: str, dim: int = COMBINED_DIM, cas: str | None = None) -> np.ndarray:
|
| 303 |
"""Convenience accessor used by the PIMT pipeline."""
|
| 304 |
+
engine = _get_default_engine()
|
| 305 |
+
embedding = engine.get_embedding(smiles, cas=cas)
|
| 306 |
if embedding.shape[0] != dim:
|
| 307 |
raise ValueError(f"Embedding dimension mismatch: {embedding.shape[0]} != {dim}")
|
| 308 |
return embedding
|