Lesson 3 of 4 Training Jobs and Experiment Tracking

Tracking Experiments with MLflow

This lesson explains how the workspace acts as an MLflow tracking server, how experiments, runs and jobs relate, and how autologging and explicit logging work together.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain the workspace's role as a tracking server.
  • Describe the relationship between jobs and MLflow runs.
  • Distinguish autologging from explicit logging.
  • Explain why metric names must be consistent.

The workspace as a tracking server

Every Azure Machine Learning workspace exposes an MLflow tracking server. Code running in a job or on a compute instance is configured to use it automatically. Code running elsewhere, such as on a laptop or in a GitHub runner, sets the tracking URI, which the workspace provides, and authenticates with Microsoft Entra ID through the azureml-mlflow plug-in.

import mlflow
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential

ml_client = MLClient.from_config(credential=DefaultAzureCredential())
mlflow.set_tracking_uri(ml_client.workspaces.get(ml_client.workspace_name).mlflow_tracking_uri)
mlflow.set_experiment("churn")

Because tracking uses the open MLflow API, the same training code works with any MLflow server, and teams that already use MLflow keep their code when they move to Azure Machine Learning.

Experiments, runs and jobs

An experiment groups runs, usually one experiment per modelling problem. A run records one execution: its parameters, metrics, tags and artifacts. In a job, the job itself is the MLflow run, so calling mlflow.log_metric() in the script logs to the job without starting a run explicitly. Child runs, created with mlflow.start_run(nested=True), group several trials inside one job.

ConceptIn MLflowIn Azure Machine Learning
Experimentmlflow.set_experiment()The experiment shown in the studio, or experiment_name of a job
Runmlflow.start_run()A job, or a run started in a notebook
Child runstart_run(nested=True)Child jobs such as sweep trials
Model registrymlflow.register_model()Workspace or registry model assets

Autologging and explicit logging

mlflow.autolog() enables framework-specific logging for libraries such as scikit-learn, XGBoost, LightGBM, PyTorch Lightning, Keras and Spark. For scikit-learn, it logs estimator parameters, training metrics and the fitted model. Autologging is a fast way to record a lot, but it does not know the business metrics or evaluation data that matter for the decision, so most scripts add explicit logging.

  • mlflow.log_param("features", "v3") records a setting; parameters are logged once.
  • mlflow.log_metric("val_loss", 0.23, step=epoch) records a value, with a step for curves.
  • mlflow.log_metrics({...}) and log_params({...}) log several at once.
  • mlflow.log_artifact("confusion_matrix.png") and log_figure() store files and plots.
  • mlflow.set_tag("data_version", "3") adds a searchable label.
  • mlflow.sklearn.log_model(model, "model", signature=signature) logs a model with its signature.

A signature, inferred with mlflow.models.infer_signature(X, y_pred), records the input and output schema of the model, which deployment uses to validate requests and generate documentation.

Naming and consistency

Tracking pays off when runs can be compared, which requires consistency. Metric names should be identical across runs and scripts, because val_auc and validation_auc are different metrics. Sweep jobs rely on this: their primary_metric must match exactly the name the script logs, or every trial reports nothing and the sweep cannot rank them.

Log the context

Log the dataset version, Git commit and feature set version as tags or parameters in every run. When two runs differ, these tags usually explain why faster than the metrics do.

Worked example

Tracking from outside the workspace

A data scientist trains models on a workstation with a local GPU and wants the runs to appear in the team's Azure Machine Learning workspace next to cloud jobs, without storing credentials in the code. The script already uses mlflow.log_metric.

Install azureml-mlflow, sign in with the Azure CLI, and set the MLflow tracking URI to the workspace's URI, obtained with ml_client.workspaces.get(...).mlflow_tracking_uri. Authentication uses the CLI sign-in through DefaultAzureCredential, so no secret is stored. Setting the experiment name to the team's experiment puts the local runs alongside the cloud ones.

Exporting the local MLflow folder and uploading it to the datastore would store files without making them runs. Running a local MLflow server would keep runs out of the workspace. Embedding a workspace key is not how MLflow authenticates to Azure Machine Learning.

Check yourself

Inside an Azure Machine Learning job, what does mlflow.log_metric() log to?

Show answer

The job's own MLflow run in the workspace. The job is the run, so no tracking URI or start_run() call is needed.

Exam Tips

Remember for the exam

  • Every workspace is an MLflow tracking server; jobs and compute instances use it automatically.
  • In a job, the job is the MLflow run; nested runs group trials.
  • Autologging captures framework details; log business metrics and context explicitly.
  • Keep metric names consistent; sweep primary metrics must match exactly.