MLFlow creates a new experiment run when logging manually along with autolog

Viewed 316

I am using MLFlow to log metrics and artefacts in the AzureML workspace. With autolog, tensorflow training metrics are available in the experiment run in the AzureML workspace. Along with auto-logging of metrics - I want to log extra metrics and plots in the same experiment run. Doing it with MLFlow - it is creating a new experiment run.

Auto logging:

mlflow.autolog()

Manual logging:

mlflow.log_metric(f"label-A", random.randint(80, 90))

enter image description here

Expected: Manually logged metrics are available in the same experiment run.

1 Answers

Instead of using the module method call mlflow.log_metric to log the metrics, use the client MlflowClient which takes run_id as the parameter.

Following code logs the metrics in the same run_id passed as the parameter.

from mlflow.tracking import MlflowClient
from azureml.core import Run

run_id = Run.get_context(allow_offline=True).id
MlflowClient().log_metric(run_id, "precision", 0.91)
Related