Skip to content

Commit b0c6414

Browse files
Merge pull request #206986 from santiagxf/santiagxf/aml-mlflow-review
AML MLflow review
2 parents eea0abb + 3d4abe3 commit b0c6414

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,30 @@ with open(filename, 'wb') as f:
6464

6565
### Models
6666

67-
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.
67+
A model in MLflow is also an artifact. However, we make stronger assumptions about this type of artifacts. Such assumptions provide a clear contract between the saved files 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. On the contrary, MLflow models can be loaded using the contract specified in the [The MLModel format](concept-mlflow-models.md#the-mlmodel-format).
6868

69-
Logging models has the following advantages:
69+
In Azure Machine Learning, logging models has the following advantages:
7070
> [!div class="checklist"]
71-
> * You don't need to provide an scoring script nor an environment for deployment.
72-
> * Swagger is enabled in endpoints automatically and the __Test__ feature can be used in Azure ML studio.
71+
> * You can deploy them on real-time or batch endpoints without providing an scoring script nor an environment.
72+
> * When deployed, Model's deployments have a Swagger generated automatically and the __Test__ feature can be used in Azure ML studio.
7373
> * Models can be used as pipelines inputs directly.
74-
> * You can use the Responsable AI dashbord.
74+
> * You can use the [Responsible AI dashbord (preview)](how-to-responsible-ai-dashboard.md).
7575
7676
Models can get logged by:
7777

7878
# [Using MLflow SDK](#tab/mlflow)
7979

8080
```python
81+
import mlflow
8182
mlflow..sklearn.log_model(sklearn_estimator, "classifier")
8283
```
8384

8485
# [Using Azure ML SDK v1](#tab/sdkv1)
8586

8687
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
8788

88-
Logging models using Azure ML SDK v1 is not possible. We recommend to use MLflow SDK.
89+
> [!IMPORTANT]
90+
> Azure ML SDK v1 doesn't have the *model* concept.
8991
9092
# [Using the outputs folder](#tab/outputs)
9193

@@ -99,9 +101,11 @@ mlflow.sklearn.save_model(sklearn_estimator, "outputs/classifier")
99101

100102
---
101103

102-
## The MLModel format
104+
## The MLmodel format
103105

104-
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.
106+
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.
107+
108+
![a sample MLflow model in MLmodel format](media/concept-mlflow-models/mlflow-mlmodel.png)
105109

106110
The following example shows how the `MLmodel` file for a computer version model trained with `fastai` may look like:
107111

@@ -157,8 +161,8 @@ Signatures are indicated when the model gets logged and persisted in the `MLmode
157161

158162
There are two types of signatures:
159163

160-
* **Column-based signature** corresponding to signatures that operate to tabular data. Models with this signature can expect to receive `pandas.DataFrame` objects as inputs.
161-
* **Tensor-based signature:** corresponding to signatures that operate with n-dimensional arrays or tensors. Models with this signature can expect to receive a `numpy.ndarray` as inputs (or a dictionary of `numpy.ndarray` in the case of named-tensors).
164+
* **Column-based signature** corresponding to signatures that operate to tabular data. For models with this signature, MLflow supplies `pandas.DataFrame` objects as inputs.
165+
* **Tensor-based signature:** corresponding to signatures that operate with n-dimensional arrays or tensors. For models with this signature, MLflow supplies `numpy.ndarray` as inputs (or a dictionary of `numpy.ndarray` in the case of named-tensors).
162166

163167
The following example corresponds to a computer vision model trained with `fastai`. This model receives a batch of images represented as tensors of shape `(300, 300, 3)` with the RGB representation of them (unsigned integers). It outputs batches of predictions (probabilities) for two classes.
164168

@@ -177,7 +181,7 @@ signature:
177181
```
178182

179183
> [!TIP]
180-
> Azure Machine Learning generates Swagger endpoints for MLflow models with a signature available. This makes easier to test deployed endpoints using the Azure ML studio.
184+
> Azure Machine Learning generates Swagger for model's deployment in MLflow format with a signature available. This makes easier to test deployed endpoints using the Azure ML studio.
181185

182186
### Model's environment
183187

@@ -221,8 +225,8 @@ Models created as MLflow models can be loaded back directly from the run where t
221225

222226
There are two workflows available for loading models:
223227

224-
* **Loading back the same object and types that were logged:**: You can load models using MLflow SDK and obtain an instance of the model with types belonging to the training library. For instance, an ONNX model will return a `ModelProto` while a decision tree trained with Scikit-Learn model will return a `DecisionTreeClassifier` object. Use `mlflow.<flavor>.load_model()` to do so.
225-
* **Loading back a model for running inference:** You can load models using MLflow SDK and obtain a wrapper where MLflow warranties there will be a `predict` function. It doesn't matter which flavor you are using, every MLflow model needs to implement this contract. Furthermore, MLflow warranties that this function can be called using arguments of type `pandas.DataFrame`, `numpy.ndarray` or `dict[strin, numpyndarray]` (depending on the signature of the model). MLflow handles the type conversion to the input type the model actually expects. Use `mlflow.pyfunc.load_model()` to do so.
228+
* **Loading back the same object and types that were logged:** You can load models using MLflow SDK and obtain an instance of the model with types belonging to the training library. For instance, an ONNX model will return a `ModelProto` while a decision tree trained with Scikit-Learn model will return a `DecisionTreeClassifier` object. Use `mlflow.<flavor>.load_model()` to do so.
229+
* **Loading back a model for running inference:** You can load models using MLflow SDK and obtain a wrapper where MLflow warranties there will be a `predict` function. It doesn't matter which flavor you are using, every MLflow model needs to implement this contract. Furthermore, MLflow warranties that this function can be called using arguments of type `pandas.DataFrame`, `numpy.ndarray` or `dict[string, numpyndarray]` (depending on the signature of the model). MLflow handles the type conversion to the input type the model actually expects. Use `mlflow.pyfunc.load_model()` to do so.
226230

227231
## Start logging models
228232

articles/machine-learning/concept-mlflow.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ms.custom: devx-track-python, cliv2, sdkv2, event-tier1-build-2022
2323
[MLflow](https://www.mlflow.org) is an open-source framework, designed to manage the complete machine learning lifecycle. Its ability to train and serve models on different platforms allows you to use a consistent set of tools regardless of where your experiments are running: locally on your computer, on a remote compute target, a virtual machine or an Azure Machine Learning compute instance.
2424

2525
> [!TIP]
26-
> Azure Machine Learning workspaces are MLflow compatible, meaning that you can use Azure Machine Learning workspaces in the same way you use an MLflow Tracking Server. Such compatibility has the following advantages:
26+
> Azure Machine Learning workspaces are MLflow-compatible, meaning that you can use Azure Machine Learning workspaces in the same way you use an MLflow Tracking Server. Such compatibility has the following advantages:
2727
> * You can use Azure Machine Learning workspaces as your tracking server for any experiment you are running with MLflow, regardless if they run on Azure Machine Learning or not. You only need to configure MLflow to point to the workspace where the tracking should happen.
2828
> * You can run any training routine that uses MLflow in Azure Machine Learning without changes. Model mangagement and model deployment capabilities are also supported.
2929
@@ -37,21 +37,22 @@ MLflow can manage the complete machine learning lifecycle using four core capabi
3737

3838
## Tracking with MLflow
3939

40-
Azure Machine Learning uses MLflow Tracking for metric logging and artifact storage for your experiments, whether you created the experiment via the Azure Machine Learning Python SDK, Azure Machine Learning CLI or the Azure Machine Learning studio. Learn more at [Log & view metrics and log files with MLflow](how-to-log-view-metrics.md).
40+
Azure Machine Learning uses MLflow Tracking for metric logging and artifact storage for your experiments, whether you created the experiment via the Azure Machine Learning Python SDK, Azure Machine Learning CLI or the Azure Machine Learning studio. We recommend using MLflow for tracking experiments. To get you started, see [Log & view metrics and log files with MLflow](how-to-log-view-metrics.md).
4141

4242
> [!NOTE]
4343
> Unlike the Azure Machine Learning SDK v1, there's no logging functionality in the SDK v2 (preview), and it is recommended to use MLflow for logging and tracking.
4444
45-
With MLflow Tracking you can connect Azure Machine Learning as the backend of your MLflow experiments. By doing so, you can:
45+
With MLflow Tracking you can connect Azure Machine Learning as the backend of your MLflow experiments. The workspace provides a centralized, secure, and scalable location to store training metrics and models. This includes:
4646

47-
+ Track and log experiment metrics and artifacts in your [Azure Machine Learning workspace](./concept-azure-machine-learning-v2.md#workspace).
48-
+ If you're using Azure Machine Learning computes, they're already configured to work with MLflow for tracking. Just import `mlflow` in your training routine and start using it.
49-
+ Azure Machine Learning also supports remote tracking of experiments by configuring MLflow to point to the Azure Machine Learning workspace. By doing so, you can leverage the capabilities of Azure Machine Learning while keeping your experiments where they are.
50-
+ Lift and shift existing MLflow experiments to Azure Machine Learning. The workspace provides a centralized, secure, and scalable location to store training metrics and models.
47+
* [Track ML experiments and models running locally or in the cloud](how-to-use-mlflow-cli-runs.md) with MLflow in Azure Machine Learning.
48+
* [Track Azure Databricks ML experiments](how-to-use-mlflow-azure-databricks.md) with MLflow in Azure Machine Learning.
49+
* [Track Azure Synapse Analytics ML experiments](how-to-use-mlflow-azure-databricks.md) with MLflow in Azure Machine Learning.
5150

5251
> [!IMPORTANT]
53-
> - MLflow in R support is limited to tracking experiment's metrics and parameters on Azure Machine Learning jobs. Artifacts and models can't be tracked using the MLflow R SDK. You can save them locally and then have Azure Machine Learning to capture for you as a workaround. RStudio or Jupyter Notebooks with R kernels are not supported. View the following [R example about using the MLflow tracking client with Azure Machine Learning](https://github.com/Azure/azureml-examples/tree/main/cli/jobs/single-step/r).
54-
> - MLflow in Java support is limited to tracking experiment's metrics and parameters on Azure Machine Learning jobs. Artifacts and models can't be tracked using the MLflow Java SDK. You can save them locally and then have Azure Machine Learning to capture for you as a workaround. View the following [Java example about using the MLflow tracking client with the Azure Machine Learning](https://github.com/Azure/azureml-examples/tree/main/cli/jobs/single-step/java/iris).
52+
> - MLflow in R support is limited to tracking experiment's metrics and parameters on Azure Machine Learning jobs. RStudio or Jupyter Notebooks with R kernels are not supported. Artifacts and models can't be tracked using the MLflow R SDK. As an alternative, you can save them locally using [`mlflow_save_model.crate`](https://mlflow.org/docs/latest/R-api.html#mlflow-save-model-crate) in the `outputs` folder. Then, use Azure ML CLI or Azure ML studio for model registration. View the following [R example about using the MLflow tracking client with Azure Machine Learning](https://github.com/Azure/azureml-examples/tree/main/cli/jobs/single-step/r).
53+
> - MLflow in Java support is limited to tracking experiment's metrics and parameters on Azure Machine Learning jobs. Artifacts and models can't be tracked using the MLflow Java SDK. View the following [Java example about using the MLflow tracking client with the Azure Machine Learning](https://github.com/Azure/azureml-examples/tree/main/cli/jobs/single-step/java/iris).
54+
55+
To learn how to use MLflow to query experiments and runs in Azure Machine Learning, see [Manage experiments and runs with MLflow](how-to-track-experiments-mlflow.md)
5556

5657
## Model Registries with MLflow
5758

41 KB
Loading

0 commit comments

Comments
 (0)