Skip to content

Commit 0cb2759

Browse files
Freshness.
1 parent e6d1863 commit 0cb2759

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

articles/machine-learning/how-to-convert-custom-model-to-mlflow.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
---
22
title: Convert custom models to MLflow
33
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.
55
services: machine-learning
66
author: msakande
77
ms.author: mopeakande
88
ms.reviewer: fasantia
99
ms.service: azure-machine-learning
1010
ms.subservice: mlops
11-
ms.date: 04/15/2022
11+
ms.date: 08/14/2024
1212
ms.topic: how-to
1313
ms.custom: devx-track-python, mlflow
1414
---
1515

1616
# Convert custom ML models to MLflow formatted models
1717

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.
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 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.
1919

2020
With Azure Machine Learning, MLflow models get the added benefits of:
2121

2222
- No code deployment
2323
- Portability as an open source standard format
2424
- Ability to deploy both locally and on cloud
2525

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 learn more about MLflow models see [From artifacts to models in MLflow](concept-mlflow-models.md).
26+
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).
2727

2828
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).
2929

3030
## Prerequisites
3131

32-
Only the mlflow package installed is needed to convert your custom models to an MLflow format.
32+
- Install the `mlflow` package
3333

3434
## Create a Python wrapper for your model
3535

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.
36+
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.
3837

3938
```python
4039

@@ -66,9 +65,9 @@ class SKLearnWrapper(mlflow.pyfunc.PythonModel):
6665
return self.sklearn_model.predict(data)
6766
```
6867

69-
## Create a Conda environment
68+
## Create a Conda environment
7069

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.
70+
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.
7271

7372
```python
7473

@@ -92,16 +91,16 @@ conda_env = {
9291

9392
## Load the MLFlow formatted model and test predictions
9493

95-
After 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.
94+
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.
9695

9796
```python
9897
mlflow_pyfunc_model_path = "sklearn_mlflow_pyfunc_custom"
9998
mlflow.pyfunc.save_model(path=mlflow_pyfunc_model_path, python_model=SKLearnWrapper(), conda_env=conda_env, artifacts=artifacts)
10099
```
101100

102-
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.
101+
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.
103102

104-
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.
103+
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.
105104

106105
```python
107106
loaded_model = mlflow.pyfunc.load_model(mlflow_pyfunc_model_path)
@@ -121,7 +120,7 @@ print(result)
121120

122121
## Register the MLflow formatted model
123122

124-
After you confirm 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.
123+
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.
125124

126125
```python
127126

@@ -141,7 +140,7 @@ mlflow.end_run()
141140
> [!IMPORTANT]
142141
> 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).
143142
144-
## Next steps
143+
## Related content
145144

146145
- [Deploy MLflow models to online endpoints](how-to-deploy-mlflow-models-online-endpoints.md)
147146
- [MLflow and Azure Machine Learning](concept-mlflow.md)

0 commit comments

Comments
 (0)