Skip to content

Commit 4246b83

Browse files
authored
Merge pull request #204797 from santiagxf/santiagxf/aml-mlflow-artifacts-fix
AML mlflow artifacts fix for the "applies to section"
2 parents a326a7f + d97e633 commit 4246b83

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

articles/machine-learning/concept-mlflow-models.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ If you are not familiar with MLflow, you may not be aware of the difference betw
2424

2525
Any file generated (and captured) from an experiment's run or job is an artifact. It may represent a model serialized as a Pickle file, the weights of a PyTorch or TensorFlow model, or even a text file containing the coefficients of a linear regression. Other artifacts can have nothing to do with the model itself, but they can contain configuration to run the model, pre-processing information, sample data, etc. As you can see, an artifact can come in any format.
2626

27-
You can log artifacts in MLflow in a similar way you log a file with Azure ML SDK v1:
27+
You may have been logging artifacts already:
28+
29+
# [Using MLflow SDK](#tab/mlflow)
2830

2931
```python
3032
filename = 'model.pkl'
@@ -34,6 +36,32 @@ with open(filename, 'wb') as f:
3436
mlflow.log_artifact(filename)
3537
```
3638

39+
# [Using Azure ML SDK v1](#tab/sdkv1)
40+
41+
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
42+
43+
```python
44+
filename = 'model.pkl'
45+
with open(filename, 'wb') as f:
46+
pickle.dump(model, f)
47+
48+
mlflow.log_file(filename)
49+
```
50+
51+
# [Using the outputs folder](#tab/outputs)
52+
53+
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
54+
55+
```python
56+
os.mkdirs("outputs", exists_ok=True)
57+
58+
filename = 'outputs/model.pkl'
59+
with open(filename, 'wb') as f:
60+
pickle.dump(model, f)
61+
```
62+
63+
---
64+
3765
### Models
3866

3967
A model in MLflow is also an artifact, as it matches the definition we introduced above. However, we make stronger assumptions about this type of artifacts. Such assumptions allow us to create a clear contract between the saved artifacts and what they mean. When you log your models as artifacts (simple files), you need to know what the model builder meant for each of them in order to know how to load the model for inference. When you log your models as a Model entity, you should be able to tell what it is based on the contract mentioned.
@@ -45,6 +73,32 @@ Logging models has the following advantages:
4573
> * Models can be used as pipelines inputs directly.
4674
> * You can use the Responsable AI dashbord.
4775
76+
Models can get logged by:
77+
78+
# [Using MLflow SDK](#tab/mlflow)
79+
80+
```python
81+
mlflow..sklearn.log_model(sklearn_estimator, "classifier")
82+
```
83+
84+
# [Using Azure ML SDK v1](#tab/sdkv1)
85+
86+
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
87+
88+
Logging models using Azure ML SDK v1 is not possible. We recommend to use MLflow SDK.
89+
90+
# [Using the outputs folder](#tab/outputs)
91+
92+
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
93+
94+
```python
95+
os.mkdirs("outputs/classifier", exists_ok=True)
96+
97+
mlflow.sklearn.save_model(sklearn_estimator, "outputs/classifier")
98+
```
99+
100+
---
101+
48102
## The MLModel format
49103

50104
MLflow adopts the MLModel format as a way to create a contract between the artifacts and what they represent. The MLModel format stores assets in a folder. Among them, there is a particular file named MLModel. This file is the single source of truth about how a model can be loaded and used.

articles/machine-learning/how-to-use-mlflow-cli-runs.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ ms.devlang: azurecli
1616

1717
# Track ML experiments and models with MLflow
1818

19-
[!INCLUDE [cli v1](../../includes/machine-learning-cli-v2.md)]
20-
21-
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v2.md)]
22-
2319
> [!div class="op_single_selector" title1="Select the version of Azure Machine Learning developer platform you are using:"]
2420
> * [v1](./v1/how-to-use-mlflow.md)
2521
> * [v2 (current version)](how-to-use-mlflow-cli-runs.md)
@@ -61,6 +57,8 @@ To track a run that is not running on Azure Machine Learning compute (from now o
6157
6258
# [Using the Azure ML SDK v2](#tab/azuremlsdk)
6359

60+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
61+
6462
You can get the Azure ML MLflow tracking URI using the [Azure Machine Learning SDK v2 for Python](concept-v2.md). Ensure you have the library `azure-ai-ml` installed in the cluster you are using. The following sample gets the unique MLFLow tracking URI associated with your workspace. Then the method [`set_tracking_uri()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_tracking_uri) points the MLflow tracking URI to that URI.
6563

6664
1. Using the workspace configuration file:
@@ -106,6 +104,8 @@ You can get the Azure ML MLflow tracking URI using the [Azure Machine Learning S
106104

107105
# [Using an environment variable](#tab/environ)
108106

107+
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
108+
109109
Another option is to set one of the MLflow environment variables [MLFLOW_TRACKING_URI](https://mlflow.org/docs/latest/tracking.html#logging-to-a-tracking-server) directly in your terminal.
110110

111111
```Azure CLI
@@ -248,7 +248,6 @@ client.download_artifacts(run_id, "helloworld.txt", ".")
248248

249249
For more details about how to retrieve information from experiments and runs in Azure Machine Learning using MLflow view [Manage experiments and runs with MLflow](how-to-track-experiments-mlflow.md).
250250

251-
252251
## Manage models
253252

254253
Register and track your models with the [Azure Machine Learning model registry](concept-model-management-and-deployment.md#register-package-and-deploy-models-from-anywhere), which supports the MLflow model registry. Azure Machine Learning models are aligned with the MLflow model schema making it easy to export and import these models across different workflows. The MLflow-related metadata, such as run ID, is also tracked with the registered model for traceability. Users can submit training runs, register, and deploy models produced from MLflow runs.
@@ -285,7 +284,7 @@ To register and view a model from a run, use the following steps:
285284

286285
## Example files
287286

288-
[Use MLflow and CLI (v2)](https://github.com/Azure/azureml-examples/blob/main/cli/jobs/basics/hello-mlflow.yml)
287+
[Using MLflow (Jupyter Notebooks)](https://github.com/Azure/azureml-examples/tree/main/notebooks/using-mlflow)
289288

290289
## Limitations
291290

0 commit comments

Comments
 (0)