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-deploy-custom-container.md
+70-35Lines changed: 70 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,9 +48,9 @@ This article focuses on serving a TensorFlow model with TensorFlow (TF) Serving.
48
48
49
49
* To deploy locally, you must have [Docker engine](https://docs.docker.com/engine/install/) running locally. This step is **highly recommended**. It helps you debug issues.
50
50
51
-
## Download source code
51
+
## Download the source code
52
52
53
-
To follow along with this tutorial, clone the source code from GitHub.
53
+
To follow along with the steps in this article, clone the source code from GitHub.
See also [the example notebook](https://github.com/Azure/azureml-examples/blob/main/sdk/python/endpoints/online/custom-container/online-endpoints-custom-container.ipynb), but note that `3. Test locally` section in the notebook assumes that it runs under the `azureml-examples/sdk` directory.
@@ -110,17 +110,42 @@ Next, deploy your online endpoint to Azure.
110
110
111
111
# [Azure CLI](#tab/cli)
112
112
113
-
### Create a YAML file for your endpoint and deployment
114
-
115
-
You can configure your cloud deployment using YAML. Take a look at the sample YAML for this example:
113
+
### Create YAML files for your endpoint and deployment
116
114
117
-
__tfserving-endpoint.yml__
115
+
You can configure your cloud deployment by using YAML. For instance, to configure your endpoint, you can create a YAML file named tfserving-endpoint.yml that contains the following lines:
@@ -251,17 +276,20 @@ The liveness and readiness routes will be determined by the API server of your c
251
276
The API server you choose would provide a way to receive the payload to work on. In the context of machine learning inferencing, a server would receive the input data via a specific route. Identify this route for your API server as you test the container locally in earlier step, and specify it when you define the deployment to create.
252
277
Note that the successful creation of the deployment will update the scoring_uri parameter of the endpoint as well, which you can verify with `az ml online-endpoint show -n <name> --query scoring_uri`.
253
278
254
-
#### Locating the mounted model
279
+
#### Locate the mounted model
280
+
281
+
When you deploy a model as an online endpoint, Azure Machine Learning *mounts* your model to your endpoint. When the model is mounted, you can deploy new versions of the model without having to create a new Docker image. By default, a model registered with the name *my-model* and version *1* is located on the following path inside your deployed container: */var/azureml-app/azureml-models/my-model/1*.
255
282
256
-
When you deploy a model as an online endpoint, Azure Machine Learning _mounts_ your model to your endpoint. Model mounting allows you to deploy new versions of the model without having to create a new Docker image. By default, a model registered with the name *foo* and version *1* would be located at the following path inside of your deployed container: */var/azureml-app/azureml-models/foo/1*
283
+
For example, consider the following setup:
257
284
258
-
For example, if you have a directory structure of */azureml-examples/cli/endpoints/online/custom-container* on your local machine, where the model is named *half_plus_two*:
285
+
- A directory structure on your local machine of /azureml-examples/cli/endpoints/online/custom-container
286
+
- A model name of `half_plus_two`
259
287
260
288
:::image type="content" source="./media/how-to-deploy-custom-container/local-directory-structure.png" alt-text="Diagram showing a tree view of the local directory structure.":::
261
289
262
290
# [Azure CLI](#tab/cli)
263
291
264
-
And *tfserving-deployment.yml*contains:
292
+
Suppose your tfserving-deployment.yml file contains the following lines in its `model` section. Note that in this section, the `name` value refers to the name that you use to register the model in Azure Machine Learning.
265
293
266
294
```yaml
267
295
model:
@@ -272,26 +300,28 @@ model:
272
300
273
301
# [Python SDK](#tab/python)
274
302
275
-
And `Model` class contains:
303
+
Suppose you use the following code to create a `Model` class. Note that in this code, the `name` value refers to the name that you use to register the model in Azure Machine Learning.
276
304
277
305
```python
278
306
model = Model(name="tfserving-mounted", version="1", path="half_plus_two")
279
307
```
280
308
281
309
---
282
310
283
-
Then your model will be located under */var/azureml-app/azureml-models/tfserving-deployment/1* in your deployment:
311
+
In this case, when you create a deployment, your model is located under the following folder: /var/azureml-app/azureml-models/tfserving-mounted/1.
284
312
285
313
:::image type="content" source="./media/how-to-deploy-custom-container/deployment-location.png" alt-text="Diagram showing a tree view of the deployment directory structure.":::
286
314
287
-
You can optionally configure your `model_mount_path`. It lets you change the path where the model is mounted.
315
+
You can optionally configure your `model_mount_path` value. By adjusting this setting, you can change the path where the model is mounted.
288
316
289
317
> [!IMPORTANT]
290
-
> The `model_mount_path` must be a valid absolute path in Linux (the OS of the container image).
318
+
> The `model_mount_path` value must be a valid absolute path in Linux (the OS of the container image).
319
+
320
+
When you change the value of `model_mount_path`, you also need to update the `MODEL_BASE_PATH` environment variable. Set `MODEL_BASE_PATH` to the same value as `model_mount_path` to avoid a failed deployment due to an error about the base path not being found.
291
321
292
322
# [Azure CLI](#tab/cli)
293
323
294
-
For example, you can have `model_mount_path` parameter in your *tfserving-deployment.yml*:
324
+
For example, you can add the `model_mount_path` parameter to your tfserving-deployment.yml file. You can also update the `MODEL_BASE_PATH` value in that file:
295
325
296
326
```YAML
297
327
name: tfserving-deployment
@@ -301,12 +331,14 @@ model:
301
331
version: 1
302
332
path: ./half_plus_two
303
333
model_mount_path: /var/tfserving-model-mount
304
-
.....
334
+
environment_variables:
335
+
MODEL_BASE_PATH: /var/tfserving-model-mount
336
+
...
305
337
```
306
338
307
339
# [Python SDK](#tab/python)
308
340
309
-
For example, you can have `model_mount_path` parameter in your `ManagedOnlineDeployment` class:
341
+
For example, you can add the `model_mount_path` parameter to your `ManagedOnlineDeployment` class. You can also update the `MODEL_BASE_PATH` value in that code:
Then your model is located at */var/tfserving-model-mount/tfserving-deployment/1* in your deployment. Note that it's no longer under *azureml-app/azureml-models*, but under the mount path you specified:
358
+
Then in your deployment, your model is located at /var/tfserving-model-mount/tfserving-mounted/1. It's no longer under azureml-app/azureml-models, but under the mount path that you specify:
325
359
326
360
:::image type="content" source="./media/how-to-deploy-custom-container/mount-path-deployment-location.png" alt-text="Diagram showing a tree view of the deployment directory structure when using mount_model_path.":::
327
361
328
362
### Create your endpoint and deployment
329
363
330
364
# [Azure CLI](#tab/cli)
331
365
332
-
Now that you understand how the YAML was constructed, create your endpoint.
366
+
Now that you understand how the YAML file is constructed, create your endpoint.
333
367
334
368
```azurecli
335
-
az ml online-endpoint create --name tfserving-endpoint -f endpoints/online/custom-container/tfserving-endpoint.yml
369
+
az ml online-endpoint create --name tfserving-endpoint -f endpoints/online/custom-container/tfserving/half-plus-two/tfserving-endpoint.yml
336
370
```
337
371
338
-
Creating a deploymentmight take a few minutes.
372
+
Create your deployment. This step might run for a few minutes.
339
373
340
374
```azurecli
341
-
az ml online-deployment create --name tfserving-deployment -f endpoints/online/custom-container/tfserving-deployment.yml --all-traffic
375
+
az ml online-deployment create --name tfserving-deployment -f endpoints/online/custom-container/tfserving/half-plus-two/tfserving-deployment.yml --all-traffic
342
376
```
343
377
344
378
# [Python SDK](#tab/python)
345
379
346
-
Using the `MLClient` created earlier, create the endpoint in the workspace. This command starts the endpoint creation and returns a confirmation response while the endpoint creation continues.
380
+
Use the instance of `MLClient` that you created earlier to create the endpoint in the workspace. This code starts the endpoint creation and returns a confirmation response while the endpoint creation continues.
347
381
348
382
```python
349
383
ml_client.begin_create_or_update(endpoint)
350
384
```
351
385
352
-
Create the deployment by running:
386
+
Create the deployment by running the following code:
Using the `MLClient` created earlier, you get a handle to the endpoint. The endpoint can be invoked using the `invoke` command with the following parameters:
371
-
- `endpoint_name`- Name of the endpoint
372
-
- `request_file`- File with request data
373
-
- `deployment_name`- Name of the specific deployment to test in an endpoint
404
+
Use the instance of `MLClient` that you created earlier to get a handle to the endpoint. Then use the `invoke` method and the following parameters to invoke the endpoint:
405
+
406
+
- `endpoint_name`: The name of the endpoint
407
+
- `request_file`: The file that contains the request data
408
+
- `deployment_name`: The name of the deployment to test in the endpoint
374
409
375
-
Send a sample request using a JSON file. The sample JSON is in the [example repository](https://github.com/Azure/azureml-examples/tree/main/sdk/python/endpoints/online/custom-container).
410
+
For the request data, you can use a sample JSON file from the [example repository](https://github.com/Azure/azureml-examples/tree/main/sdk/python/endpoints/online/custom-container).
376
411
377
412
```python
378
-
# test the blue deployment with some sample data
379
-
ml_client.online_endpoints.invoke(
413
+
# Test the blue deployment by using some sample data.
0 commit comments