Skip to content

Commit 3ce8efd

Browse files
committed
changes
1 parent 2966fa6 commit 3ce8efd

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ ms.subservice: mlops
1111
ms.date: 09/27/2024
1212
ms.topic: conceptual
1313
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.
1515
---
1616

17-
# From artifacts to models in MLflow
17+
# Artifacts and models in MLflow
1818

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

2121
## Artifacts and models
2222

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

2525
### Artifact
2626

2727
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.
2828

29-
You can log artifacts as follows:
29+
The following example logs a file artifact.
3030

3131
```python
3232
filename = 'model.pkl'
@@ -40,7 +40,7 @@ mlflow.log_artifact(filename)
4040

4141
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.
4242

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:
4444

4545
```python
4646
import mlflow
@@ -56,11 +56,11 @@ Logging MLflow models in Azure Machine Learning has the following advantages:
5656

5757
## The MLmodel format
5858

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

6161
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.
6262

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

6565
:::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":::
6666

@@ -90,7 +90,7 @@ signature:
9090
}]'
9191
```
9292
93-
### Model flavor
93+
### Model flavors
9494
9595
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.
9696
@@ -112,11 +112,9 @@ flavors:
112112

113113
### Model signature
114114

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).
116116

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).
120118

121119
There are two types of signatures:
122120

@@ -144,7 +142,7 @@ signature:
144142

145143
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.
146144

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:
148146

149147
```yaml
150148
channels:
@@ -165,29 +163,31 @@ dependencies:
165163
name: mlflow-env
166164
```
167165

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

170168
### Predict function
171169

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

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).
175173

176174
## Workflows for loading MLflow models
177175

178176
You can load MLflow models from the following locations:
179177

180178
- 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
182180
- From the model registry where the models are registered
183181

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

186184
There are two workflows for loading models:
187185

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

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

192192
## Related content
193193

-23.4 KB
Loading

0 commit comments

Comments
 (0)