Skip to content

latent.mlflow.mlflow_setup

MLFlow tracking setup for Prefect flows.

Classes

ResolvedTrackingUri

ResolvedTrackingUri()

Result of tracking URI resolution with its source for diagnostics.

Functions

create_latest_symlink(flow_name: str, mlflow_run_id: str) -> None

Create/update a 'latest' symlink pointing to the most recent MLflow run's outputs.

Creates: data//output/latest -> ../../../mlartifacts///artifacts/outputs/

Args: flow_name: Name of the flow mlflow_run_id: MLflow run ID to link to

end_mlflow_run

end_mlflow_run(flow_name: str | None = None) -> None

End the current MLFlow run and optionally create a 'latest' symlink.

Args: flow_name: If provided, creates a symlink at data//output/latest pointing to the run's artifacts/outputs directory

log_artifact

log_artifact(file_path: str, artifact_path: str | None = None)

Log an artifact to MLFlow.

Args: file_path: Path to the file to log artifact_path: Optional subdirectory within the artifact store

log_metrics

log_metrics(metrics: dict)

Log metrics to MLFlow.

Args: metrics: Dictionary of metric name -> value

resolve_tracking_uri

resolve_tracking_uri(mlflow_config: dict | None = None) -> ResolvedTrackingUri

Resolve the MLflow tracking URI using a priority chain.

Priority (highest to lowest): 1. mlflow_config from parameters.yaml 2. LATENT_MLFLOW_TRACKING_URI env var 3. MLFLOW_TRACKING_URI env var (standard MLflow convention) 4. TOML config file 5. Default to SQLite backend

Args: mlflow_config: MLflow configuration dict (e.g. from parameters.yaml)

Returns: ResolvedTrackingUri with the URI and its source

setup_mlflow_tracking

setup_mlflow_tracking(flow_name: str, run_id: str, parameters: dict | None = None, mlflow_config: dict | None = None, flow_run_name: str | None = None) -> str

Setup MLFlow tracking for a flow run.

Args: flow_name: Name of the flow (used as experiment name) run_id: Prefect run ID (used to link runs) parameters: Flow parameters to log mlflow_config: MLFlow configuration from parameters.yaml

Returns: MLFlow run ID