Skip to content

Commit 78112c5

Browse files
committed
Update code and text
1 parent 7227d99 commit 78112c5

File tree

3 files changed

+70
-35
lines changed

3 files changed

+70
-35
lines changed

articles/machine-learning/how-to-deploy-custom-container.md

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ This article focuses on serving a TensorFlow model with TensorFlow (TF) Serving.
4848

4949
* 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.
5050

51-
## Download source code
51+
## Download the source code
5252

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

5555
# [Azure CLI](#tab/cli)
5656

@@ -63,7 +63,7 @@ cd azureml-examples/cli
6363

6464
```azurecli
6565
git clone https://github.com/Azure/azureml-examples --depth 1
66-
cd azureml-examples/cli
66+
cd azureml-examples/sdk/python
6767
```
6868

6969
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.
110110

111111
# [Azure CLI](#tab/cli)
112112

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
116114

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

119117
:::code language="yaml" source="~/azureml-examples-main/cli/endpoints/online/custom-container/tfserving/half-plus-two/tfserving-endpoint.yml":::
120118

121-
__tfserving-deployment.yml__
119+
To configure your deployment, you can create a YAML file named tfserving-deployment.yml that contains the following lines:
122120

123-
:::code language="yaml" source="~/azureml-examples-main/cli/endpoints/online/custom-container//tfserving/half-plus-two/tfserving-deployment.yml":::
121+
```yml
122+
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
123+
name: tfserving-deployment
124+
endpoint_name: tfserving-endpoint
125+
model:
126+
name: tfserving-mounted
127+
version: <model-version>
128+
path: ./half_plus_two
129+
environment_variables:
130+
MODEL_BASE_PATH: /var/azureml-app/azureml-models/tfserving-mounted/<model-version>
131+
MODEL_NAME: half_plus_two
132+
environment:
133+
#name: tfserving
134+
#version: 1
135+
image: docker.io/tensorflow/serving:latest
136+
inference_config:
137+
liveness_route:
138+
port: 8501
139+
path: /v1/models/half_plus_two
140+
readiness_route:
141+
port: 8501
142+
path: /v1/models/half_plus_two
143+
scoring_route:
144+
port: 8501
145+
path: /v1/models/half_plus_two:predict
146+
instance_type: Standard_DS3_v2
147+
instance_count: 1
148+
```
124149
125150
# [Python SDK](#tab/python)
126151
@@ -251,17 +276,20 @@ The liveness and readiness routes will be determined by the API server of your c
251276
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.
252277
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`.
253278

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*.
255282

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

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`
259287

260288
:::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.":::
261289

262290
# [Azure CLI](#tab/cli)
263291

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

266294
```yaml
267295
model:
@@ -272,26 +300,28 @@ model:
272300
273301
# [Python SDK](#tab/python)
274302
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.
276304

277305
```python
278306
model = Model(name="tfserving-mounted", version="1", path="half_plus_two")
279307
```
280308

281309
---
282310

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

285313
:::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.":::
286314

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

289317
> [!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.
291321

292322
# [Azure CLI](#tab/cli)
293323

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

296326
```YAML
297327
name: tfserving-deployment
@@ -301,12 +331,14 @@ model:
301331
version: 1
302332
path: ./half_plus_two
303333
model_mount_path: /var/tfserving-model-mount
304-
.....
334+
environment_variables:
335+
MODEL_BASE_PATH: /var/tfserving-model-mount
336+
...
305337
```
306338

307339
# [Python SDK](#tab/python)
308340

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

311343
```python
312344
blue_deployment = ManagedOnlineDeployment(
@@ -315,41 +347,43 @@ blue_deployment = ManagedOnlineDeployment(
315347
model=model,
316348
environment=env,
317349
model_mount_path="/var/tfserving-model-mount",
350+
environment_variables={
351+
"MODEL_BASE_PATH": "/var/tfserving-model-mount",
318352
...
319353
)
320354
```
321355

322356
---
323357

324-
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:
325359

326360
:::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.":::
327361

328362
### Create your endpoint and deployment
329363

330364
# [Azure CLI](#tab/cli)
331365

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

334368
```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
336370
```
337371

338-
Creating a deployment might take a few minutes.
372+
Create your deployment. This step might run for a few minutes.
339373

340374
```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
342376
```
343377

344378
# [Python SDK](#tab/python)
345379

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

348382
```python
349383
ml_client.begin_create_or_update(endpoint)
350384
```
351385

352-
Create the deployment by running:
386+
Create the deployment by running the following code:
353387

354388
```python
355389
ml_client.begin_create_or_update(blue_deployment)
@@ -359,24 +393,25 @@ ml_client.begin_create_or_update(blue_deployment)
359393

360394
### Invoke the endpoint
361395

362-
Once your deployment completes, see if you can make a scoring request to the deployed endpoint.
396+
After your deployment is complete, make a scoring request to the deployed endpoint.
363397

364398
# [Azure CLI](#tab/cli)
365399

366400
:::code language="azurecli" source="~/azureml-examples-main/cli/deploy-custom-container-tfserving-half-plus-two.sh" id="invoke_endpoint":::
367401

368402
# [Python SDK](#tab/python)
369403

370-
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
374409

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

377412
```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.
414+
response = ml_client.online_endpoints.invoke(
380415
endpoint_name=online_endpoint_name,
381416
deployment_name="blue",
382417
request_file="sample-request.json",
1.02 KB
Loading
202 Bytes
Loading

0 commit comments

Comments
 (0)