Skip to content

Commit dc89574

Browse files
Merge pull request #231433 from santiagxf/santiagxf/mlflow-new-queryapi
Update how-to-track-experiments-mlflow.md
2 parents 5ebd135 + fe18845 commit dc89574

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

articles/machine-learning/how-to-track-experiments-mlflow.md

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,18 @@ ms.custom: how-to, devx-track-python, ignite-2022
1515

1616
# Query & compare experiments and runs with MLflow
1717

18-
Experiments and runs tracking information in Azure Machine Learning can be queried using MLflow. You don't need to install any specific SDK to manage what happens inside of a training job, creating a more seamless transition between local runs and the cloud by removing cloud-specific dependencies.
19-
20-
> [!NOTE]
21-
> The Azure Machine Learning Python SDK v2 does not provide native logging or tracking capabilities. This applies not just for logging but also for querying the metrics logged. Instead, we recommend to use MLflow to manage experiments and runs. This article explains how to use MLflow to manage experiments and runs in Azure Machine Learning.
18+
Experiments and runs tracking information in Azure Machine Learning can be queried using MLflow. You don't need to install any specific SDK to manage what happens inside of a training job, creating a more seamless transition between local runs and the cloud by removing cloud-specific dependencies. In this article, you'll learn how to query and compare experiments and runs in your workspace using Azure Machine Learning and MLflow SDK in Python.
2219

2320
MLflow allows you to:
2421

25-
* Create, delete and search for experiments in a workspace.
26-
* Start, stop, cancel and query runs for experiments.
22+
* Create, query, delete and search for experiments in a workspace.
23+
* Query, delete, and search for runs in a workspace.
2724
* Track and retrieve metrics, parameters, artifacts and models from runs.
2825

29-
In this article, you'll learn how to manage experiments and runs in your workspace using Azure Machine Learning and MLflow SDK in Python.
30-
31-
> [!IMPORTANT]
32-
> Items marked (preview) in this article are currently in public preview.
33-
> The preview version is provided without a service level agreement, and it's not recommended for production workloads. Certain features might not be supported or might have constrained capabilities.
34-
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
35-
36-
## Using MLflow SDK in Azure Machine Learning
26+
See [Support matrix for querying runs and experiments in Azure Machine Learning](#support-matrix-for-querying-runs-and-experiments) for a detailed comparison between MLflow Open-Source and MLflow when connected to Azure Machine Learning.
3727

38-
Use MLflow to query and manage all the experiments in Azure Machine Learning. The MLflow SDK has capabilities to query everything that happens inside of a training job in Azure Machine Learning. See [Support matrix for querying runs and experiments in Azure Machine Learning](#support-matrix-for-querying-runs-and-experiments) for a detailed comparison between MLflow Open-Source and MLflow when connected to Azure Machine Learning.
28+
> [!NOTE]
29+
> The Azure Machine Learning Python SDK v2 does not provide native logging or tracking capabilities. This applies not just for logging but also for querying the metrics logged. Instead, use MLflow to manage experiments and runs. This article explains how to use MLflow to manage experiments and runs in Azure Machine Learning.
3930
4031
### Prerequisites
4132

@@ -64,6 +55,16 @@ for exp in experiments:
6455
print(exp.name)
6556
```
6657

58+
## Search experiments
59+
60+
The `search_experiments()` method available since Mlflow 2.0 allows searching experiment matching a criteria using `filter_string`. The following query retrieves three experiments with different IDs.
61+
62+
```python
63+
mlflow.search_experiments(filter_string="experiment_id IN (
64+
'CDEFG-1234-5678-90AB', '1234-5678-90AB-CDEFG', '5678-1234-90AB-CDEFG')"
65+
)
66+
```
67+
6768
## Getting a specific experiment
6869

6970
Details about a specific experiment can be retrieved using the `get_experiment_by_name` method:
@@ -73,7 +74,7 @@ exp = mlflow.get_experiment_by_name(experiment_name)
7374
print(exp)
7475
```
7576

76-
## Getting runs inside an experiment
77+
## Query runs inside an experiment
7778

7879
MLflow allows searching runs inside of any experiment, including multiple experiments at the same time. By default, MLflow returns the data in Pandas `Dataframe` format, which makes it handy when doing further processing our analysis of the runs. Returned data includes columns with:
7980

@@ -132,6 +133,13 @@ mlflow.search_runs(experiment_ids=[ "1234-5678-90AB-CDEFG" ],
132133
filter_string="params.num_boost_round='100'")
133134
```
134135

136+
Specific run field can also be indicated. Fields do not need a qualifier like `params`, `metrics` or `attributes`. The following search query for runs with specific IDs.
137+
138+
```python
139+
mlflow.search_runs(experiment_ids=[ "1234-5678-90AB-CDEFG" ],
140+
filter_string="run_id IN ('CDEFG-1234-5678-90AB', '1234-5678-90AB-CDEFG', '5678-1234-90AB-CDEFG')")
141+
```
142+
135143
### Filter runs by status
136144

137145
You can also filter experiment by status. It becomes useful to find runs that are running, completed, canceled or failed. In MLflow, `status` is an `attribute`, so we can access this value using the expression `attributes.status`. The following table shows the possible values:
@@ -227,23 +235,20 @@ model_local_path = mlflow.artifacts.download_artifacts(
227235
)
228236
```
229237

230-
You can then load the model back from the downloaded artifacts using the typical function `load_model`:
238+
You can then load the model back from the downloaded artifacts using the typical function `load_model` in the flavor-specific namespace. The following example uses `xgboost`:
231239

232240
```python
233241
model = mlflow.xgboost.load_model(model_local_path)
234242
```
235243

236-
> [!NOTE]
237-
> The previous example assumes the model was created using `xgboost`. Change it to the flavor applies to your case.
238-
239244
MLflow also allows you to both operations at once and download and load the model in a single instruction. MLflow will download the model to a temporary folder and load it from there. The method `load_model` uses an URI format to indicate from where the model has to be retrieved. In the case of loading a model from a run, the URI structure is as follows:
240245

241246
```python
242247
model = mlflow.xgboost.load_model(f"runs:/{last_run.info.run_id}/{artifact_path}")
243248
```
244249

245250
> [!TIP]
246-
> You can also load models from the registry using MLflow. View [loading MLflow models with MLflow](how-to-manage-models-mlflow.md#loading-models-from-registry) for details.
251+
> For query and loading models registered in the Model Registry, view [Manage models registries in Azure Machine Learning with MLflow](how-to-manage-models-mlflow.md).
247252
248253
## Getting child (nested) runs
249254

@@ -260,15 +265,18 @@ child_runs = mlflow.search_runs(
260265

261266
To compare and evaluate the quality of your jobs and models in Azure Machine Learning Studio, use the [preview panel](./how-to-enable-preview-features.md) to enable the feature. Once enabled, you can compare the parameters, metrics, and tags between the jobs and/or models you selected.
262267

263-
:::image type="content" source="media/how-to-track-experiments-mlflow/compare.gif" alt-text="Screenshot of the preview panel showing how to compare jobs and models in Azure Machine Learning studio.":::
268+
> [!IMPORTANT]
269+
> Items marked (preview) in this article are currently in public preview.
270+
> The preview version is provided without a service level agreement, and it's not recommended for production workloads. Certain features might not be supported or might have constrained capabilities.
271+
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
264272
273+
:::image type="content" source="media/how-to-track-experiments-mlflow/compare.gif" alt-text="Screenshot of the preview panel showing how to compare jobs and models in Azure Machine Learning studio.":::
265274

266275
The [MLflow with Azure Machine Learning notebooks](https://github.com/Azure/azureml-examples/tree/main/sdk/python/using-mlflow) demonstrate and expand upon concepts presented in this article.
267276

268277
* [Training and tracking a classifier with MLflow](https://github.com/Azure/azureml-examples/blob/main/sdk/python/using-mlflow/train-and-log/xgboost_classification_mlflow.ipynb): Demonstrates how to track experiments using MLflow, log models and combine multiple flavors into pipelines.
269278
* [Manage experiments and runs with MLflow](https://github.com/Azure/azureml-examples/blob/main/sdk/python/using-mlflow/runs-management/run_history.ipynb): Demonstrates how to query experiments, runs, metrics, parameters and artifacts from Azure Machine Learning using MLflow.
270279

271-
272280
## Support matrix for querying runs and experiments
273281

274282
The MLflow SDK exposes several methods to retrieve runs, including options to control what is returned and how. Use the following table to learn about which of those methods are currently supported in MLflow when connected to Azure Machine Learning:
@@ -294,7 +302,7 @@ The MLflow SDK exposes several methods to retrieve runs, including options to co
294302
| Renaming experiments | **✓** | |
295303

296304
> [!NOTE]
297-
> - <sup>1</sup> Check the section [Getting runs inside an experiment](#getting-runs-inside-an-experiment) for instructions and examples on how to achieve the same functionality in Azure Machine Learning.
305+
> - <sup>1</sup> Check the section [Query runs inside an experiment](#query-runs-inside-an-experiment) for instructions and examples on how to achieve the same functionality in Azure Machine Learning.
298306
> - <sup>2</sup> `!=` for tags not supported.
299307
300308
## Next steps

0 commit comments

Comments
 (0)