Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions mostlyai/sdk/_local/execution/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,31 +88,18 @@ def _set_random_state(random_state: int | None = None):
def _move_training_artefacts(generator_dir: Path, job_workspace_dir: Path):
for dir in ["Logs", "ModelStore", "FKModelsStore", "ModelQAReports", "ModelQAStatistics"]:
shutil.rmtree(generator_dir / dir, ignore_errors=True)
(generator_dir / dir).mkdir()
for path in job_workspace_dir.absolute().rglob("*"):
if "FKModelsStore" in path.parts:
fk_store_idx = path.parts.index("FKModelsStore")
if path.is_dir() and (
path.name == "fk_matching_model" or ("cardinality_model" in path.parts and path.name == "ModelStore")
):
relative_path = Path(*path.parts[fk_store_idx + 1 :])
dest = generator_dir / "FKModelsStore" / relative_path
dest.parent.mkdir(parents=True, exist_ok=True)
path.rename(dest)
else:
if path.is_dir() and path.name == "ModelStore":
model_label = path.parent.name
dest = generator_dir / "ModelStore" / model_label
dest.parent.mkdir(parents=True, exist_ok=True)
path.rename(dest)
if path.is_file() and path.parent.name == "ModelQAReports":
dest = generator_dir / "ModelQAReports" / path.name
dest.parent.mkdir(parents=True, exist_ok=True)
path.rename(dest)
if path.is_dir() and path.name == "ModelQAStatistics":
model_label = path.parent.name
dest = generator_dir / "ModelQAStatistics" / model_label
dest.parent.mkdir(parents=True, exist_ok=True)
path.rename(dest)
if path.is_dir() and path.name == "ModelStore":
model_label = path.parent.name
path.rename(generator_dir / "ModelStore" / model_label)
if path.is_dir() and path.name == "FKModelsStore":
path.rename(generator_dir / "FKModelsStore")
if path.is_file() and path.parent.name == "ModelQAReports":
path.rename(generator_dir / "ModelQAReports" / path.name)
if path.is_dir() and path.name == "ModelQAStatistics":
model_label = path.parent.name
path.rename(generator_dir / "ModelQAStatistics" / model_label)


def _move_generation_artefacts(synthetic_dataset_dir: Path, job_workspace_dir: Path):
Expand Down
10 changes: 10 additions & 0 deletions mostlyai/sdk/_local/execution/step_finalize_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


import logging
import shutil
import time
import traceback
from pathlib import Path
Expand Down Expand Up @@ -275,6 +276,13 @@ def train_non_context_models_for_single_relation(
)


def clean_up_non_context_models_dirs(fk_models_workspace_dir: Path):
# ensure OriginalData is not persisted
for path in fk_models_workspace_dir.absolute().rglob("*"):
if path.name == "OriginalData":
shutil.rmtree(path)


def execute_step_finalize_training(
*,
generator: Generator,
Expand Down Expand Up @@ -306,3 +314,5 @@ def execute_step_finalize_training(
except Exception as e:
_LOG.error(f"FK model training failed for table {tgt_table_name}: {e}\n{traceback.format_exc()}")
continue
finally:
clean_up_non_context_models_dirs(fk_models_workspace_dir=fk_models_workspace_dir)
Loading