fix(hf_job): prepare writable registry before pino imports
Browse filesThe pino.embeddings module instantiates a default OlfactoryEmbeddingEngine
(and therefore AromaRegistry) at import time. This happened before
hf_train_job.py had a chance to set PINO_REGISTRY_PATH, so the registry was
still opened inside the read-only source mount.
Now _prepare_registry() runs before any pino imports, copies the mounted
registry to /workspace/registry.db, and sets PINO_REGISTRY_PATH. Also added a
try/except around train_main() so future failures surface in the logs.
- scripts/hf_train_job.py +30 -30
scripts/hf_train_job.py
CHANGED
|
@@ -13,9 +13,6 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
| 13 |
SRC_DIR = REPO_ROOT / "src"
|
| 14 |
sys.path.insert(0, str(SRC_DIR))
|
| 15 |
|
| 16 |
-
import torch
|
| 17 |
-
from pino.train import main as train_main
|
| 18 |
-
|
| 19 |
# Writable workspace outside the read-only source mount.
|
| 20 |
WORKSPACE = Path("/workspace")
|
| 21 |
OUTPUT_DIR = WORKSPACE / "models"
|
|
@@ -36,13 +33,32 @@ def _copy_registry_to_writable(registry_path: Path) -> Path:
|
|
| 36 |
return writable_registry
|
| 37 |
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def hf_train_5epoch() -> None:
|
| 40 |
"""Run a controlled 5-epoch training pass and push artifacts to the Hub."""
|
| 41 |
token = os.environ.get("HF_TOKEN")
|
| 42 |
|
| 43 |
-
# Allow mounted data
|
| 44 |
data_path = Path(os.environ.get("HF_DATA_PATH", REPO_ROOT / "data" / "empirical_dataset_v1.jsonl"))
|
| 45 |
-
registry_path = Path(os.environ.get("HF_REGISTRY_PATH", REPO_ROOT / "src" / "pino" / "registry.db"))
|
| 46 |
|
| 47 |
if not data_path.exists() and token:
|
| 48 |
# Download the dataset from the canonical dataset repository.
|
|
@@ -63,28 +79,6 @@ def hf_train_5epoch() -> None:
|
|
| 63 |
# Allow the dataset to be mounted elsewhere in the container.
|
| 64 |
data_path = Path("/data/empirical_dataset_v1.jsonl")
|
| 65 |
|
| 66 |
-
if not registry_path.exists() and token:
|
| 67 |
-
from huggingface_hub import hf_hub_download
|
| 68 |
-
|
| 69 |
-
print("📥 Downloading warm registry cache from Hugging Face Hub...")
|
| 70 |
-
registry_path.parent.mkdir(parents=True, exist_ok=True)
|
| 71 |
-
downloaded = hf_hub_download(
|
| 72 |
-
repo_id="mattbitzesty/pino-synthetic-dataset",
|
| 73 |
-
filename="registry.db",
|
| 74 |
-
repo_type="dataset",
|
| 75 |
-
token=token,
|
| 76 |
-
local_dir=str(registry_path.parent),
|
| 77 |
-
)
|
| 78 |
-
registry_path = Path(downloaded)
|
| 79 |
-
print(f" Registry cache downloaded to {registry_path}")
|
| 80 |
-
elif not registry_path.exists():
|
| 81 |
-
# Use the local registry file if it was cloned with the repo.
|
| 82 |
-
registry_path = Path("/workspace/pino/src/pino/registry.db")
|
| 83 |
-
|
| 84 |
-
# Registry must be writable for embedding caching. Copy if it's mounted read-only.
|
| 85 |
-
registry_path = _copy_registry_to_writable(registry_path)
|
| 86 |
-
os.environ["PINO_REGISTRY_PATH"] = str(registry_path)
|
| 87 |
-
|
| 88 |
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 89 |
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 90 |
|
|
@@ -104,13 +98,19 @@ def hf_train_5epoch() -> None:
|
|
| 104 |
print(f" Device: {'cuda' if torch.cuda.is_available() else 'cpu'}")
|
| 105 |
print(f" Args: {' '.join(sys.argv[1:])}")
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
print(f"✅ Training complete. Checkpoint: {checkpoint_path}")
|
| 110 |
|
| 111 |
# Push checkpoint to the model hub if token is present.
|
| 112 |
-
token
|
| 113 |
-
if token and checkpoint_path:
|
| 114 |
from huggingface_hub import HfApi, create_repo
|
| 115 |
|
| 116 |
repo_id = "mattbitzesty/pino-pimt-checkpoint"
|
|
|
|
| 13 |
SRC_DIR = REPO_ROOT / "src"
|
| 14 |
sys.path.insert(0, str(SRC_DIR))
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
# Writable workspace outside the read-only source mount.
|
| 17 |
WORKSPACE = Path("/workspace")
|
| 18 |
OUTPUT_DIR = WORKSPACE / "models"
|
|
|
|
| 33 |
return writable_registry
|
| 34 |
|
| 35 |
|
| 36 |
+
def _prepare_registry() -> None:
|
| 37 |
+
"""Prepare a writable registry path before any pino imports happen."""
|
| 38 |
+
registry_path = Path(
|
| 39 |
+
os.environ.get("HF_REGISTRY_PATH", REPO_ROOT / "src" / "pino" / "registry.db")
|
| 40 |
+
)
|
| 41 |
+
if not registry_path.exists():
|
| 42 |
+
# Try the mounted dataset location as a fallback.
|
| 43 |
+
registry_path = Path("/data/registry.db")
|
| 44 |
+
if registry_path.exists():
|
| 45 |
+
registry_path = _copy_registry_to_writable(registry_path)
|
| 46 |
+
os.environ["PINO_REGISTRY_PATH"] = str(registry_path)
|
| 47 |
+
print(f"📍 PINO_REGISTRY_PATH set to {registry_path}")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
_prepare_registry()
|
| 51 |
+
|
| 52 |
+
import torch # noqa: E402
|
| 53 |
+
from pino.train import main as train_main # noqa: E402
|
| 54 |
+
|
| 55 |
+
|
| 56 |
def hf_train_5epoch() -> None:
|
| 57 |
"""Run a controlled 5-epoch training pass and push artifacts to the Hub."""
|
| 58 |
token = os.environ.get("HF_TOKEN")
|
| 59 |
|
| 60 |
+
# Allow mounted data path to override the repo default.
|
| 61 |
data_path = Path(os.environ.get("HF_DATA_PATH", REPO_ROOT / "data" / "empirical_dataset_v1.jsonl"))
|
|
|
|
| 62 |
|
| 63 |
if not data_path.exists() and token:
|
| 64 |
# Download the dataset from the canonical dataset repository.
|
|
|
|
| 79 |
# Allow the dataset to be mounted elsewhere in the container.
|
| 80 |
data_path = Path("/data/empirical_dataset_v1.jsonl")
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
| 83 |
LOG_DIR.mkdir(parents=True, exist_ok=True)
|
| 84 |
|
|
|
|
| 98 |
print(f" Device: {'cuda' if torch.cuda.is_available() else 'cpu'}")
|
| 99 |
print(f" Args: {' '.join(sys.argv[1:])}")
|
| 100 |
|
| 101 |
+
try:
|
| 102 |
+
checkpoint_path = train_main()
|
| 103 |
+
except Exception as exc:
|
| 104 |
+
print(f"❌ Training failed: {exc}")
|
| 105 |
+
import traceback
|
| 106 |
+
|
| 107 |
+
traceback.print_exc()
|
| 108 |
+
sys.exit(1)
|
| 109 |
|
| 110 |
print(f"✅ Training complete. Checkpoint: {checkpoint_path}")
|
| 111 |
|
| 112 |
# Push checkpoint to the model hub if token is present.
|
| 113 |
+
if token and checkpoint_path and Path(checkpoint_path).exists():
|
|
|
|
| 114 |
from huggingface_hub import HfApi, create_repo
|
| 115 |
|
| 116 |
repo_id = "mattbitzesty/pino-pimt-checkpoint"
|