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/concept-mlflow-models.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,22 +11,22 @@ ms.subservice: mlops
11
11
ms.date: 09/27/2024
12
12
ms.topic: conceptual
13
13
ms.custom: cliv2, sdkv2, FY25Q1-Linter
14
-
#Customer intent: As a data scientist, I want to understand artifacts and models in MLflow so that I can enable a streamlined path to deployment.
14
+
#Customer intent: As a data scientist, I want to understand MLflow artifacts and models so I can use MLflow models to enable streamlined deployment workflows.
15
15
---
16
16
17
-
# From artifacts to models in MLflow
17
+
# Artifacts and models in MLflow
18
18
19
-
This article explains the differences between an MLflow *artifact* and an MLflow *model*, and how to transition from one to the other. The article also explains how Azure Machine Learning uses the concept of an MLflow model to enable streamlined deployment workflows.
19
+
This article explains MLflow artifacts and MLflow models, and how MLflow models differ from other artifacts. The article also explains how Azure Machine Learning uses the characteristics of an MLflow model to enable streamlined deployment workflows.
20
20
21
21
## Artifacts and models
22
22
23
-
There are fundamental differences between logging MLflow artifacts and files vs. logging MLflow models.
23
+
In MLflow, there are some fundamental differences between logging simple file artifacts and logging MLflow models.
24
24
25
25
### Artifact
26
26
27
27
An artifact is any file that's generated and captured from an experiment's run or job. An artifact could be a model serialized as a pickle file, the weights of a PyTorch or TensorFlow model, or a text file containing the coefficients of a linear regression. Some artifacts have nothing to do with the model itself but contain run configurations, preprocessing information, or sample data. Artifacts can have various formats.
28
28
29
-
You can log artifacts as follows:
29
+
The following example logs a file artifact.
30
30
31
31
```python
32
32
filename ='model.pkl'
@@ -40,7 +40,7 @@ mlflow.log_artifact(filename)
40
40
41
41
An MLflow model is an artifact, but you make stronger assumptions about this type of artifact that provide a clear *contract* between the saved files and what they mean.
42
42
43
-
You can log MLflow models by using the MLflow SDK as follows:
43
+
You can log MLflow models by using the MLflow SDK, for example:
44
44
45
45
```python
46
46
import mlflow
@@ -56,11 +56,11 @@ Logging MLflow models in Azure Machine Learning has the following advantages:
56
56
57
57
## The MLmodel format
58
58
59
-
When you log models as simple artifact files, you need to know how the model builder intended to use each of the files to load the model for inference. For MLflow models, the *MLmodel format*specifies the contract between the artifacts and what they represent. You load MLflow models by using the contract specified in the MLflow format.
59
+
For models logged as simple artifact files, you need to know what the model builder intended for each file so you can load the model for inference. You load MLflow models by using the *MLmodel format*to specify the contract between the artifacts and what they represent.
60
60
61
61
The MLmodel format stores assets in a folder that has no specific naming requirement. Among the assets is a file named *MLmodel* that's the single source of truth for how to load and use the model.
62
62
63
-
The following example shows an MLflow model folder called *credit_defaults_model* in Azure Machine Learning studio. The folder contains the *MLmodel* file among other model artifacts.
63
+
The following example shows an MLflow model folder called *credit_defaults_model* in Azure Machine Learning studio. The folder contains the *MLmodel* file and other model artifacts.
64
64
65
65
:::image type="content" source="media/concept-mlflow-models/mlflow-mlmodel.png" alt-text="A screenshot showing assets of a sample MLflow model, including the MLmodel file." lightbox="media/concept-mlflow-models/mlflow-mlmodel.png":::
66
66
@@ -90,7 +90,7 @@ signature:
90
90
}]'
91
91
```
92
92
93
-
### Model flavor
93
+
### Model flavors
94
94
95
95
Considering the large number of machine learning frameworks available, MLflow introduced the concept of *flavor* as a way to provide a unique contract for all machine learning frameworks. A flavor indicates what to expect for a given model that's created with a specific framework. For instance, TensorFlow has its own flavor, which specifies how to persist and load a TensorFlow model.
96
96
@@ -112,11 +112,9 @@ flavors:
112
112
113
113
### Model signature
114
114
115
-
An MLflow [model signature](https://www.mlflow.org/docs/latest/models.html#model-signature) is an important part of the model specification, because it serves as a data contract between the model and the server running the model. A model signature is also important for parsing and enforcing a model's input types at deployment time.
115
+
An MLflow [model signature](https://www.mlflow.org/docs/latest/models.html#model-signature) is an important part of the model specification, because it serves as a data contract between the model and the server running the model. A model signature is also important for parsing and enforcing a model's input types at deployment time. If a signature is available, MLflow enforces the input types when data is submitted to your model. For more information, see [MLflow signature enforcement](https://www.mlflow.org/docs/latest/models.html#signature-enforcement).
116
116
117
-
If a signature is available, MLflow enforces the input types when data is submitted to your model. For more information, see [MLflow signature enforcement](https://www.mlflow.org/docs/latest/models.html#signature-enforcement).
118
-
119
-
Signatures are indicated when models get logged, and are persisted in the `signature` section of the *MLmodel* file. The **Autolog** feature in MLflow automatically makes a best effort to infer signatures. However, you can log models manually if the inferred signatures aren't the ones you need. For more information, see [How to log models with signatures](https://www.mlflow.org/docs/latest/models.html#how-to-log-models-with-signatures).
117
+
Signatures are indicated at the time that models are logged, and are persisted in the `signature` section of the *MLmodel* file. The **Autolog** feature in MLflow automatically makes a best effort to infer signatures. However, you can log models manually if the inferred signatures aren't the ones you need. For more information, see [How to log models with signatures](https://www.mlflow.org/docs/latest/models.html#how-to-log-models-with-signatures).
120
118
121
119
There are two types of signatures:
122
120
@@ -144,7 +142,7 @@ signature:
144
142
145
143
Requirements for the model to run are specified in the *conda.yaml* file. MLflow can automatically detect dependencies, or you can manually indicate them by calling the `mlflow.<flavor>.log_model()` method. Calling the method can be useful if the libraries that MLflow included in your environment aren't the ones you intended to use.
146
144
147
-
The following *conda.yaml* example shows an environment used for a model that's created with the `fastai` framework:
145
+
The following *conda.yaml* example shows an environment for a model created with the `fastai` framework:
148
146
149
147
```yaml
150
148
channels:
@@ -165,29 +163,31 @@ dependencies:
165
163
name: mlflow-env
166
164
```
167
165
168
-
While an MLflow environment operates at the level of the model, an Azure Machine Learning environment operates at the workspace level for registered environments or the jobs/deployments level for anonymous environments. When you deploy MLflow models, Azure Machine Learning builds the model's environment and uses it for deployment. You can use the [Azure Machine Learning CLI](concept-v2.md) to override this behavior and deploy MLflow models using a specific Azure Machine Learning environment.
166
+
An MLflow environment operates at the level of the model, but an Azure Machine Learning environment operates at the workspace level for registered environments or the jobs/deployments level for anonymous environments. When you deploy MLflow models, Azure Machine Learning builds the model environment and uses it for deployment. You can use the [Azure Machine Learning CLI](concept-v2.md) to override this behavior and deploy MLflow models to a specific Azure Machine Learning environment.
169
167
170
168
### Predict function
171
169
172
-
All MLflow models contain a `predict` function that is called when the model is deployed by using a no-code deployment. What the `predict` function returns, such as classes, probabilities, or a forecast, depends on the framework or flavor used for training. The documentation of each flavor describes what it returns.
170
+
All MLflow models contain a `predict` function, which is called when the model is deployed by using a no-code deployment. What the `predict` function returns, for example classes, probabilities, or a forecast, depends on the framework or flavor used for training. The documentation of each flavor describes what it returns.
173
171
174
-
In same cases, you might need to customize the `predict` function to change the way inference is executed. In such cases, you need to [log models with a different behavior in the predict method](how-to-log-mlflow-models.md#logging-models-with-a-different-behavior-in-the-predict-method) or [log a custom model's flavor](how-to-log-mlflow-models.md#logging-custom-models).
172
+
You can customize the `predict` function to change the way inference is executed. You can either [log models with a different behavior](how-to-log-mlflow-models.md#logging-models-with-a-different-behavior-in-the-predict-method), or [log a custom model flavor](how-to-log-mlflow-models.md#logging-custom-models).
175
173
176
174
## Workflows for loading MLflow models
177
175
178
176
You can load MLflow models from the following locations:
179
177
180
178
- Directly from the run where the models were logged
181
-
- From the file system where they models are saved
179
+
- From the file system where the models are saved
182
180
- From the model registry where the models are registered
183
181
184
-
MLflow provides a consistent way to load these models regardless of the location.
182
+
MLflow provides a consistent way to load these models regardless of location.
185
183
186
184
There are two workflows for loading models:
187
185
188
-
- **Load back the same object and types that were logged.** You can load models using the MLflow SDK and obtain an instance of the model with types belonging to the training library. For example, an ONNX model returns a `ModelProto`, while a decision tree model trained with `scikit-learn` returns a `DecisionTreeClassifier` object. Use `mlflow.<flavor>.load_model()` to load back the same model object and types that were logged.
186
+
- **Load back the same object and types that were logged.** You can load models using the MLflow SDK and obtain an instance of the model with types belonging to the training library. For example, an Open Neural Network Exchange (ONNX) model returns a `ModelProto`, while a decision tree model trained with `scikit-learn` returns a `DecisionTreeClassifier` object. Use `mlflow.<flavor>.load_model()` to load back the same model object and types that were logged.
187
+
188
+
- **Load back a model for running inference.** You can load models using the MLflow SDK and get a wrapper that has a guaranteed `predict` function. It doesn't matter which flavor you use, because every MLflow model has a `predict` function.
189
189
190
-
- **Load back a model for running inference.** You can load models using the MLflow SDK and get a wrapper that has a guaranteed `predict` function. It doesn't matter which flavor you use, because every MLflow model has a `predict` function. MLflow guarantees that you can call this function by using arguments of type `pandas.DataFrame`, `numpy.ndarray`, or `dict[string, numpyndarray]`, depending on the model signature. MLflow handles the type conversion to the input type that the model expects. Use `mlflow.pyfunc.load_model()` to load back a model for running inference.
190
+
MLflow guarantees that you can call this function by using arguments of type `pandas.DataFrame`, `numpy.ndarray`, or `dict[string, numpyndarray]`, depending on the model signature. MLflow handles the type conversion to the input type that the model expects. Use `mlflow.pyfunc.load_model()` to load back a model for running inference.
0 commit comments