You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/how-to-convert-custom-model-to-mlflow.md
+24-25Lines changed: 24 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,40 +1,40 @@
1
1
---
2
2
title: Convert custom models to MLflow
3
3
titleSuffix: Azure Machine Learning
4
-
description: Convert custom models to MLflow model format for no code deployment with endpoints.
4
+
description: Convert custom models to MLflow model format for no code deployment with endpoints in Azure Machine Learning.
5
5
services: machine-learning
6
6
author: msakande
7
7
ms.author: mopeakande
8
8
ms.reviewer: fasantia
9
9
ms.service: azure-machine-learning
10
10
ms.subservice: mlops
11
-
ms.date: 04/15/2022
11
+
ms.date: 08/16/2024
12
12
ms.topic: how-to
13
13
ms.custom: devx-track-python, mlflow
14
+
#customer intent: As a data scientist, I want to convert a model to an MLflow format to use the benefits of MLflow.
14
15
---
15
16
16
17
# Convert custom ML models to MLflow formatted models
17
18
18
-
In this article, learn how to convert your custom ML model into MLflow format. [MLflow](https://www.mlflow.org) is an open-source library for managing the lifecycle of your machine learning experiments. In some cases, you might use a machine learning framework without its built-in MLflow model flavor support. Due to this lack of built-in MLflow model flavor, you cannot log or register the model with MLflow model fluent APIs. To resolve this, you can convert your model to an MLflow format where you can leverage the following benefits of Azure Machine Learning and MLflow models.
19
+
In this article, learn how to convert your custom ML model into MLflow format. [MLflow](https://www.mlflow.org) is an open-source library for managing the lifecycle of your machine learning experiments. In some cases, you might use a machine learning framework without its built-in MLflow model flavor support. Due to this lack of built-in MLflow model flavor, you can't log or register the model with MLflow model fluent APIs. To resolve this issue, you can convert your model to an MLflow format where you can apply the following benefits of Azure Machine Learning and MLflow models.
19
20
20
-
With Azure Machine Learning, MLflow models get the added benefits of,
21
+
With Azure Machine Learning, MLflow models get the added benefits of:
21
22
22
-
* No code deployment
23
-
* Portability as an open source standard format
24
-
* Ability to deploy both locally and on cloud
23
+
- No code deployment
24
+
- Portability as an open source standard format
25
+
- Ability to deploy both locally and on cloud
25
26
26
-
MLflow provides support for a variety of [machine learning frameworks](https://mlflow.org/docs/latest/models.html#built-in-model-flavors) (scikit-learn, Keras, Pytorch, and more); however, it might not cover every use case. For example, you may want to create an MLflow model with a framework that MLflow does not natively support or you may want to change the way your model does pre-processing or post-processing when running jobs. To know more about MLflow models read[From artifacts to models in MLflow](concept-mlflow-models.md).
27
+
MLflow provides support for various [machine learning frameworks](https://mlflow.org/docs/latest/models.html#built-in-model-flavors), such as scikit-learn, Keras, and Pytorch. MLflow might not cover every use case. For example, you might want to create an MLflow model with a framework that MLflow doesn't natively support. You might want to change the way your model does preprocessing or post-processing when running jobs. To learn more about MLflow models, see[From artifacts to models in MLflow](concept-mlflow-models.md).
27
28
28
-
If you didn't train your model with MLFlow and want to use Azure Machine Learning's MLflow no-code deployment offering, you need to convert your custom model to MLFLow. Learn more about [custom Python models and MLflow](https://mlflow.org/docs/latest/models.html#custom-python-models).
29
+
If you didn't train your model with MLFlow and want to use Azure Machine Learning's MLflow no-code deployment offering, you need to convert your custom model to MLFLow. For more information, see [Custom Python Models](https://mlflow.org/docs/latest/models.html#custom-python-models).
29
30
30
31
## Prerequisites
31
-
32
-
Only the mlflow package installed is needed to convert your custom models to an MLflow format.
32
+
33
+
- Install the `mlflow` package
33
34
34
35
## Create a Python wrapper for your model
35
36
36
-
Before you can convert your model to an MLflow supported format, you need to first create a Python wrapper for your model.
37
-
The following code demonstrates how to create a Python wrapper for an `sklearn` model.
37
+
Before you can convert your model to an MLflow supported format, you need to create a Python wrapper for your model. The following code demonstrates how to create a Python wrapper for an `sklearn` model.
38
38
39
39
```python
40
40
@@ -66,9 +66,9 @@ class SKLearnWrapper(mlflow.pyfunc.PythonModel):
66
66
returnself.sklearn_model.predict(data)
67
67
```
68
68
69
-
## Create a Conda environment
69
+
## Create a Conda environment
70
70
71
-
Next, you need to create Conda environment for the new MLflow Model that contains all necessary dependencies. If not indicated, the environment is inferred from the current installation. If not, it can be specified.
71
+
Next, create Conda environment for the new MLflow Model that contains all necessary dependencies. If not indicated, the environment is inferred from the current installation. If not, it can be specified.
72
72
73
73
```python
74
74
@@ -90,19 +90,18 @@ conda_env = {
90
90
}
91
91
```
92
92
93
-
## Load the MLFlow formatted model and test predictions
93
+
## Load the MLflow formatted model and test predictions
94
94
95
-
Once your environment is ready, you can pass the SKlearnWrapper, the Conda environment, and your newly created artifacts dictionary to the mlflow.pyfunc.save_model() method. Doing so saves the model to your disk.
95
+
After your environment is ready, pass the `SKlearnWrapper`, the Conda environment, and your newly created artifacts dictionary to the `mlflow.pyfunc.save_model()` method. Doing so saves the model to your disk.
To ensure your newly saved MLflow formatted model didn't change during the save, you can load your model and print out a test prediction to compare your original model.
102
+
To ensure that your newly saved MLflow formatted model didn't change during the save, load your model and print a test prediction to compare your original model.
104
103
105
-
The following code prints a test prediction from the mlflow formatted model and a test prediction from the sklearn model that's saved to your disk for comparison.
104
+
The following code prints a test prediction from the mlflow formatted model and a test prediction from the sklearn model. It saves the test predictions to your disk for comparison.
Once you've confirmed that your model saved correctly, you can create a test run, so you can register and save your MLflow formatted model to your model registry.
124
+
After you confirm that your model saved correctly, you can create a test run. Register and save your MLflow formatted model to your model registry.
126
125
127
126
```python
128
127
@@ -140,9 +139,9 @@ mlflow.end_run()
140
139
```
141
140
142
141
> [!IMPORTANT]
143
-
> In some cases, you might use a machine learning framework without its built-in MLflow model flavor support. For instance, the `vaderSentiment` library is a standard natural language processing (NLP) library used for sentiment analysis. Since it lacks a built-in MLflow model flavor, you cannot log or register the model with MLflow model fluent APIs. See an example on [how to save, log and register a model that doesn't have a supported built-in MLflow model flavor](https://mlflow.org/docs/latest/model-registry.html#registering-an-unsupported-machine-learning-model).
142
+
> In some cases, you might use a machine learning framework without its built-in MLflow model flavor support. For instance, the `vaderSentiment` library is a standard natural language processing (NLP) library used for sentiment analysis. Since it lacks a built-in MLflow model flavor, you cannot log or register the model with MLflow model fluent APIs. For an example on how to save, log and register a model that doesn't have a supported built-in MLflow model flavor, see [Registering an Unsupported Machine Learning Model](https://mlflow.org/docs/latest/model-registry.html#registering-an-unsupported-machine-learning-model).
144
143
145
-
## Next steps
144
+
## Related content
146
145
147
-
*[No-code deployment for Mlflow models](how-to-deploy-mlflow-models-online-endpoints.md)
148
-
* Learn more about[MLflow and Azure Machine Learning](concept-mlflow.md)
146
+
-[Deploy MLflow models to online endpoints](how-to-deploy-mlflow-models-online-endpoints.md)
147
+
-[MLflow and Azure Machine Learning](concept-mlflow.md)
0 commit comments