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
Batch model deployments can be used for processing tabular data, but also any other file type like images. Those deployments are supported in both MLflow and custom models. In this article, you learn how to deploy a model that classifies images according to the ImageNet taxonomy.
21
+
You can use batch model deployments for processing tabular data, but also any other file types, like images. Those deployments are supported in both MLflow and custom models. In this article, you learn how to deploy a model that classifies images according to the ImageNet taxonomy.
22
22
23
23
## Prerequisites
24
24
@@ -31,7 +31,7 @@ The model that this article works with was built using TensorFlow along with the
31
31
- It works with images of size 244x244 (tensors of `(224, 224, 3)`).
32
32
- It requires inputs to be scaled to the range `[0,1]`.
33
33
34
-
The information in this article is based on code samples contained in the [azureml-examples](https://github.com/azure/azureml-examples) repository. To run the commands locally without having to copy/paste YAML and other files, clone the repo. Change directories to `cli/endpoints/batch/deploy-models/imagenet-classifier` if you're using the Azure CLI or `sdk/python/endpoints/batch/deploy-models/imagenet-classifier` if you're using the SDK for Python.
34
+
The information in this article is based on code samples contained in the [azureml-examples](https://github.com/azure/azureml-examples) repository. To run the commands locally without having to copy/paste YAML and other files, clone the repo. Change directories to *cli/endpoints/batch/deploy-models/imagenet-classifier* if you're using the Azure CLI or *sdk/python/endpoints/batch/deploy-models/imagenet-classifier* if you're using the SDK for Python.
@@ -94,7 +94,7 @@ Create the endpoint that hosts the model:
94
94
95
95
Model deployments can only deploy registered models. You need to register the model. You can skip this step if the model you're trying to deploy is already registered.
96
96
97
-
1. Download a copy of the model:
97
+
1. Download a copy of the model.
98
98
99
99
# [Azure CLI](#tab/cli)
100
100
@@ -114,7 +114,7 @@ Model deployments can only deploy registered models. You need to register the mo
> Although images are provided in mini-batches by the deployment, this scoring script processes one image at a time. This is a common pattern because trying to load the entire batch and send it to the model at once might result in high-memory pressure on the batch executor (OOM exceptions). However, there are certain cases where doing so enables high throughput in the scoring task. This is the case for batch deployments over GPU hardware where you want to achieve high GPU utilization. For an example of a scoring script that takes advantage of this approach, see [High throughput deployments](#high-throughput-deployments).
152
+
> Although images are provided in mini-batches by the deployment, this scoring script processes one image at a time. This is a common pattern because trying to load the entire batch and send it to the model at once might result in high-memory pressure on the batch executor (OOM exceptions).
153
+
>
154
+
> There are certain cases where doing so enables high throughput in the scoring task. This is the case for batch deployments over GPU hardware where you want to achieve high GPU utilization. For a scoring script that takes advantage of this approach, see [High throughput deployments](#high-throughput-deployments).
153
155
154
156
> [!NOTE]
155
-
> If you are trying to deploy a generative model, which generates files, read how to author a scoring script as explained at[Customize outputs in batch deployments](how-to-deploy-model-custom-output.md).
157
+
> If you want to deploy a generative model, which generates files, learn how to author a scoring script:[Customize outputs in batch deployments](how-to-deploy-model-custom-output.md).
156
158
157
159
### Creating the deployment
158
160
159
161
After you create the scoring script, create a batch deployment for it. Use the following procedure:
160
162
161
163
1. Ensure that you have a compute cluster created where you can create the deployment. In this example, use a compute cluster named `gpu-cluster`. Although not required, using GPUs speeds up the processing.
162
164
163
-
1. Indicate over which environment to run the deployment. In this example, the model runs on `TensorFlow`. Azure Machine Learning already has an environment with the required software installed, so you can reuse this environment. You need to add a couple of dependencies in a `conda.yml` file.
165
+
1. Indicate over which environment to run the deployment. In this example, the model runs on `TensorFlow`. Azure Machine Learning already has an environment with the required software installed, so you can reuse this environment. You need to add a couple of dependencies in a *conda.yml* file.
164
166
165
167
# [Azure CLI](#tab/cli)
166
168
@@ -170,7 +172,7 @@ After you create the scoring script, create a batch deployment for it. Use the f
170
172
171
173
# [Python](#tab/python)
172
174
173
-
Get a reference to the environment:
175
+
Get a reference to the environment.
174
176
175
177
```python
176
178
environment = Environment(
@@ -180,15 +182,15 @@ After you create the scoring script, create a batch deployment for it. Use the f
180
182
)
181
183
```
182
184
183
-
1. Create the deployment:
185
+
1. Create the deployment.
184
186
185
187
# [Azure CLI](#tab/cli)
186
188
187
-
To create a new deployment under the created endpoint, create a `YAML` configuration like the following example. You can check the [full batch endpoint YAML schema](reference-yaml-endpoint-batch.md) for extra properties.
189
+
To create a new deployment under the created endpoint, create a `YAML` configuration like the following example. For other properties, see the [full batch endpoint YAML schema](reference-yaml-endpoint-batch.md).
1. Although you can invoke a specific deployment inside of an endpoint, you usually want to invoke the endpoint itself, and let the endpoint decide which deployment to use. Such deployment is named the *default* deployment. This approach gives you the possibility of changing the default deployment - and hence changing the model serving the deployment - without changing the contract with the user invoking the endpoint. Use the following instruction to update the default deployment:
229
+
1. Although you can invoke a specific deployment inside of an endpoint, you usually want to invoke the endpoint itself, and let the endpoint decide which deployment to use. Such deployment is called the *default* deployment.
230
+
231
+
This approach lets you change the default deployment and change the model serving the deployment without changing the contract with the user invoking the endpoint. Use the following code to update the default deployment:
228
232
229
233
# [Azure Machine Learning CLI](#tab/cli)
230
234
@@ -243,16 +247,19 @@ Your batch endpoint is ready to be used.
243
247
244
248
## Test the deployment
245
249
246
-
For testing the endpoint, use a sample of 1,000 images from the original ImageNet dataset. Batch endpoints can only process data that is located in the cloud and that is accessible from the Azure Machine Learning workspace. Upload it to an Azure Machine Learning data store. Create a data asset that can be used to invoke the endpoint for scoring. However, batch endpoints accept data that can be placed in multiple type of locations.
250
+
For testing the endpoint, use a sample of 1,000 images from the original ImageNet dataset. Batch endpoints can only process data that is located in the cloud and that is accessible from the Azure Machine Learning workspace. Upload it to an Azure Machine Learning data store. Create a data asset that can be used to invoke the endpoint for scoring.
247
251
248
-
1. Download the associated sample data:
252
+
> [!NOTE]
253
+
> Batch endpoints accept data that can be placed in multiple types of locations.
1. When the data is uploaded and ready to be used, invoke the endpoint:
311
+
1. When the data is uploaded and ready to be used, invoke the endpoint.
305
312
306
313
# [Azure CLI](#tab/cli)
307
314
@@ -326,9 +333,9 @@ For testing the endpoint, use a sample of 1,000 images from the original ImageNe
326
333
---
327
334
328
335
> [!TIP]
329
-
> You don't indicate the deployment name in the invoke operation. That's because the endpoint automatically routes the job to the default deployment. Since the endpoint only has one deployment, that one is the default one. You can target an specific deployment by indicating the argument/parameter `deployment_name`.
336
+
> You don't indicate the deployment name in the invoke operation. That's because the endpoint automatically routes the job to the default deployment. Since the endpoint only has one deployment, that one is the default. You can target an specific deployment by indicating the argument/parameter `deployment_name`.
330
337
331
-
1. A batch job starts as soon as the command returns. You can monitor the status of the job until it finishes:
338
+
1. A batch job starts as soon as the command returns. You can monitor the status of the job until it finishes.
332
339
333
340
# [Azure CLI](#tab/cli)
334
341
@@ -340,7 +347,7 @@ For testing the endpoint, use a sample of 1,000 images from the original ImageNe
340
347
ml_client.jobs.get(job.name)
341
348
```
342
349
343
-
1. After the deployment finishes, download the predictions:
350
+
1. After the deployment finishes, download the predictions.
344
351
345
352
# [Azure CLI](#tab/cli)
346
353
@@ -380,12 +387,12 @@ On those cases, you might want to do inference on the entire batch of data. That
380
387
> [!WARNING]
381
388
> Some models have a non-linear relationship with the size of the inputs in terms of the memory consumption. To avoid out-of-memory exceptions, batch again (as done in this example) or decrease the size of the batches created by the batch deployment.
382
389
383
-
1. Creating the scoring script.*code/score-by-batch/batch_driver.py*:
390
+
1. Create the scoring script *code/score-by-batch/batch_driver.py*:
- This script is constructing a tensor dataset from the mini-batch sent by the batch deployment. This dataset is preprocessed to obtain the expected tensors for the model using the `map` operation with the function `decode_img`.
388
-
- The dataset is batched again (16) send the data to the model. Use this parameter to control how much information you can load into memory and send to the model at once. If running on a GPU, you need to carefully tune this parameter to achieve the maximum usage of the GPU just before getting an OOM exception.
394
+
- This script constructs a tensor dataset from the mini-batch sent by the batch deployment. This dataset is preprocessed to obtain the expected tensors for the model using the `map` operation with the function `decode_img`.
395
+
- The dataset is batched again (16) to send the data to the model. Use this parameter to control how much information you can load into memory and send to the model at once. If running on a GPU, you need to carefully tune this parameter to achieve the maximum usage of the GPU just before getting an OOM exception.
389
396
- After predictions are computed, the tensors are converted to `numpy.ndarray`.
390
397
391
398
1. Create the deployment.
@@ -440,8 +447,8 @@ On those cases, you might want to do inference on the entire batch of data. That
440
447
MLflow models in Batch Endpoints support reading images asinput data. Since MLflow deployments don't require a scoring script, have the following considerations when using them:
>- MLflow models should expect to recieve a `np.ndarray`asinput that matches the dimensions of the input image. In order to support multiple image sizes on each batch, the batch executor invokes the MLflow model once per image file.
>- MLflow models should expect to receive a `np.ndarray`asinput that matches the dimensions of the input image. In order to support multiple image sizes on each batch, the batch executor invokes the MLflow model once per image file.
445
452
>- MLflow models are highly encouraged to include a signature. If they do, it must be of type`TensorSpec`. Inputs are reshaped to match tensor's shape if available. If no signature is available, tensors of type `np.uint8` are inferred.
446
453
>- For models that include a signature and are expected to handle variable size of images, include a signature that can guarantee it. For instance, the following signature example allows batches of 3 channeled images.
Copy file name to clipboardExpand all lines: articles/machine-learning/includes/azureml-batch-prereqs.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,29 +17,29 @@ Before following the steps in this article, make sure you have the following pre
17
17
18
18
- You need to install the following software to work with Azure Machine Learning:
19
19
20
-
# [Azure CLI](#tab/cli)
20
+
# [Azure CLI](#tab/cli)
21
21
22
-
Add the [Azure CLI](/cli/azure/)`ml`[extension for Azure Machine Learning](../how-to-configure-cli.md).
22
+
Add the [Azure CLI](/cli/azure/)`ml`[extension for Azure Machine Learning](../how-to-configure-cli.md).
23
23
24
-
```azurecli
25
-
az extension add -n ml
26
-
```
24
+
```azurecli
25
+
az extension add -n ml
26
+
```
27
27
28
-
> [!NOTE]
29
-
> Pipeline component deployments for Batch Endpoints were introduced in version 2.7 of the `ml` extension for Azure CLI. Use `az extension update --name ml` to get the last version of it.
28
+
> [!NOTE]
29
+
> Pipeline component deployments for Batch Endpoints were introduced in version 2.7 of the `ml` extension for Azure CLI. Use `az extension update --name ml` to get the last version of it.
30
30
31
-
# [Python](#tab/python)
31
+
# [Python](#tab/python)
32
32
33
-
Install the [Azure Machine Learning SDK for Python](https://aka.ms/sdk-v2-install).
33
+
Install the [Azure Machine Learning SDK for Python](https://aka.ms/sdk-v2-install).
34
34
35
-
```python
36
-
pip install azure-ai-ml
37
-
```
35
+
```python
36
+
pip install azure-ai-ml
37
+
```
38
38
39
-
> [!NOTE]
40
-
> Classes `ModelBatchDeployment` and `PipelineComponentBatchDeployment` were introduced in version 1.7.0 of the SDK. Use `pip install -U azure-ai-ml` to get the last version of it.
39
+
> [!NOTE]
40
+
> Classes `ModelBatchDeployment` and `PipelineComponentBatchDeployment` were introduced in version 1.7.0 of the SDK. Use `pip install -U azure-ai-ml` to get the last version of it.
0 commit comments