Skip to content

Commit c2eee04

Browse files
Merge pull request #217025 from Blackmist/endpoint-arm
revising messaging per customer & PM feedback
2 parents 32d79d0 + 7783ead commit c2eee04

File tree

1 file changed

+179
-2
lines changed

1 file changed

+179
-2
lines changed

articles/machine-learning/how-to-deploy-online-endpoints.md

Lines changed: 179 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.subservice: mlops
88
author: dem108
99
ms.author: sehan
1010
ms.reviewer: mopeakande
11-
ms.date: 10/06/2022
11+
ms.date: 11/03/2022
1212
ms.topic: how-to
1313
ms.custom: how-to, devplatv2, ignite-fall-2021, cliv2, event-tier1-build-2022, sdkv2
1414
---
@@ -59,6 +59,25 @@ The main example in this doc uses managed online endpoints for deployment. To us
5959

6060
* (Optional) To deploy locally, you must [install Docker Engine](https://docs.docker.com/engine/install/) on your local computer. We *highly recommend* this option, so it's easier to debug issues.
6161

62+
# [ARM template](#tab/arm)
63+
64+
> [!NOTE]
65+
> While the Azure CLI and CLI extension for machine learning are used in these steps, they are not the main focus. They are used more as utilities, passing templates to Azure and checking the status of template deployments.
66+
67+
[!INCLUDE [basic prereqs cli](../../includes/machine-learning-cli-prereqs.md)]
68+
69+
* Azure role-based access controls (Azure RBAC) are used to grant access to operations in Azure Machine Learning. To perform the steps in this article, your user account must be assigned the __owner__ or __contributor__ role for the Azure Machine Learning workspace, or a custom role allowing `Microsoft.MachineLearningServices/workspaces/onlineEndpoints/*`. For more information, see [Manage access to an Azure Machine Learning workspace](how-to-assign-roles.md).
70+
71+
* If you haven't already set the defaults for the Azure CLI, save your default settings. To avoid passing in the values for your subscription, workspace, and resource group multiple times, run this code:
72+
73+
```azurecli
74+
az account set --subscription <subscription ID>
75+
az configure --defaults workspace=<Azure Machine Learning workspace name> group=<resource group>
76+
```
77+
78+
> [!IMPORTANT]
79+
> The examples in this document assume that you are using the Bash shell. For example, from a Linux system or [Windows Subsystem for Linux](/windows/wsl/about).
80+
6281
---
6382

6483
## Prepare your system
@@ -142,6 +161,54 @@ The [workspace](concept-workspace.md) is the top-level resource for Azure Machin
142161
)
143162
```
144163

164+
# [ARM template](#tab/arm)
165+
166+
### Clone the sample repository
167+
168+
To follow along with this article, first clone the [samples repository (azureml-examples)](https://github.com/azure/azureml-examples). Then, run the following code to go to the samples directory:
169+
170+
```azurecli
171+
git clone --depth 1 https://github.com/Azure/azureml-examples
172+
cd azureml-examples
173+
```
174+
175+
> [!TIP]
176+
> Use `--depth 1` to clone only the latest commit to the repository, which reduces time to complete the operation.
177+
178+
### Set an endpoint name
179+
180+
To set your endpoint name, run the following command (replace `YOUR_ENDPOINT_NAME` with a unique name).
181+
182+
For Unix, run this command:
183+
184+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" ID="set_endpoint_name":::
185+
186+
> [!NOTE]
187+
> Endpoint names must be unique within an Azure region. For example, in the Azure `westus2` region, there can be only one endpoint with the name `my-endpoint`.
188+
189+
Also set the following environment variables, as they are used in the examples in this article. Replace the values with your Azure subscription ID, the Azure region where your workspace is located, the resource group that contains the workspace, and the workspace name:
190+
191+
```bash
192+
export SUBSCRIPTION_ID="your Azure subscription ID"
193+
export LOCATION="Azure region where your workspace is located"
194+
export RESOURCE_GROUP="Azure resource group that contains your workspace"
195+
export WORKSPACE="Azure Machine Learning workspace name"
196+
```
197+
198+
A couple of the template examples require you to upload files to the Azure Blob store for your workspace. The following steps will query the workspace and store this information in environment variables used in the examples:
199+
200+
1. Get an access token:
201+
202+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="get_access_token":::
203+
204+
1. Set the REST API version:
205+
206+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="api_version":::
207+
208+
1. Get the storage information:
209+
210+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="get_storage_details":::
211+
145212
---
146213

147214
## Define the endpoint and deployment
@@ -254,6 +321,10 @@ In this article, we first define names of online endpoint and deployment for deb
254321
)
255322
```
256323

324+
# [ARM template](#tab/arm)
325+
326+
The Azure Resource Manager templates [online-endpoint.json](https://github.com/Azure/azureml-examples/tree/main/arm-templates/online-endpoint.json) and [online-endpoint-deployment.json](https://github.com/Azure/azureml-examples/tree/main/arm-templates/online-endpoint-deployment.json) are used by the steps in this article.
327+
257328
---
258329

259330
### Register your model and environment separately
@@ -273,6 +344,24 @@ For more information on registering your model as an asset, see [Register your m
273344
For more information on creating an environment, see
274345
[Manage Azure Machine Learning environments with the CLI & SDK (v2)](how-to-manage-environments-v2.md#create-an-environment)
275346

347+
# [ARM template](#tab/arm)
348+
349+
1. To register the model using a template, you must first upload the model file to an Azure Blob store. The following example uses the `az storage blob upload-batch` command to upload a file to the default storage for your workspace:
350+
351+
:::code language="{language}" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="upload_model":::
352+
353+
1. After uploading the file, use the template to create a model registration. In the following example, the `modelUri` parameter contains the path to the model:
354+
355+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="create_model":::
356+
357+
1. Part of the environment is a conda file that specifies the model dependencies needed to host the model. The following example demonstrates how to read the contents of the conda file into an environment variables:
358+
359+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="read_condafile":::
360+
361+
1. The following example demonstrates how to use the template to register the environment. The contents of the conda file from the previous step are passed to the template using the `condaFile` parameter:
362+
363+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="create_environment":::
364+
276365
---
277366

278367
### Use different CPU and GPU instance types
@@ -299,6 +388,20 @@ As noted earlier, the script specified in `code_configuration.scoring_script` mu
299388
# [Python](#tab/python)
300389
As noted earlier, the script specified in `CodeConfiguration(scoring_script="score.py")` must have an `init()` function and a `run()` function. This example uses the [score.py file](https://github.com/Azure/azureml-examples/blob/main/sdk/python/endpoints/online/model-1/onlinescoring/score.py).
301390

391+
# [ARM template](#tab/arm)
392+
393+
As noted earlier, the script specified in `code_configuration.scoring_script` must have an `init()` function and a `run()` function. This example uses the [score.py file](https://github.com/Azure/azureml-examples/blob/main/cli/endpoints/online/model-1/onlinescoring/score.py).
394+
395+
When using a template for deployment, you must first upload the scoring file(s) to an Azure Blob store and then register it:
396+
397+
1. The following example uses the Azure CLI command `az storage blob upload-batch` to upload the scoring file(s):
398+
399+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="upload_code":::
400+
401+
1. The following example demonstrates hwo to register the code using a template:
402+
403+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="create_code":::
404+
302405
---
303406

304407
The `init()` function is called when the container is initialized or started. Initialization typically occurs shortly after the deployment is created or updated. Write logic here for global initialization operations like caching the model in memory (as we do in this example). The `run()` function is called for every invocation of the endpoint and should do the actual scoring and prediction. In the example, we extract the data from the JSON input, call the scikit-learn model's `predict()` method, and then return the result.
@@ -330,6 +433,10 @@ First create an endpoint. Optionally, for a local endpoint, you can skip this st
330433
ml_client.online_endpoints.begin_create_or_update(endpoint, local=True)
331434
```
332435

436+
# [ARM template](#tab/arm)
437+
438+
The template doesn't support local endpoints. See the Azure CLI or Python tabs for steps to test the endpoint locally.
439+
333440
---
334441

335442
Now, create a deployment named `blue` under the endpoint.
@@ -350,6 +457,10 @@ ml_client.online_deployments.begin_create_or_update(
350457

351458
The `local=True` flag directs the SDK to deploy the endpoint in the Docker environment.
352459

460+
# [ARM template](#tab/arm)
461+
462+
The template doesn't support local endpoints. See the Azure CLI or Python tabs for steps to test the endpoint locally.
463+
353464
---
354465

355466
> [!TIP]
@@ -390,6 +501,10 @@ The method returns [`ManagedOnlineEndpoint` entity](/python/api/azure-ai-ml/azur
390501
ManagedOnlineEndpoint({'public_network_access': None, 'provisioning_state': 'Succeeded', 'scoring_uri': 'http://localhost:49158/score', 'swagger_uri': None, 'name': 'local-10061534497697', 'description': 'this is a sample local endpoint', 'tags': {}, 'properties': {}, 'id': None, 'Resource__source_path': None, 'base_path': '/path/to/your/working/directory', 'creation_context': None, 'serialize': <msrest.serialization.Serializer object at 0x7ffb781bccd0>, 'auth_mode': 'key', 'location': 'local', 'identity': None, 'traffic': {}, 'mirror_traffic': {}, 'kind': None})
391502
```
392503

504+
# [ARM template](#tab/arm)
505+
506+
The template doesn't support local endpoints. See the Azure CLI or Python tabs for steps to test the endpoint locally.
507+
393508
---
394509

395510
The following table contains the possible values for `provisioning_state`:
@@ -431,6 +546,10 @@ endpoint = ml_client.online_endpoints.get(endpoint_name)
431546
scoring_uri = endpoint.scoring_uri
432547
```
433548

549+
# [ARM template](#tab/arm)
550+
551+
The template doesn't support local endpoints. See the Azure CLI or Python tabs for steps to test the endpoint locally.
552+
434553
---
435554

436555
### Review the logs for output from the invoke operation
@@ -453,6 +572,10 @@ ml_client.online_deployments.get_logs(
453572
)
454573
```
455574

575+
# [ARM template](#tab/arm)
576+
577+
The template doesn't support local endpoints. See the Azure CLI or Python tabs for steps to test the endpoint locally.
578+
456579
---
457580

458581
## Deploy your online endpoint to Azure
@@ -553,6 +676,16 @@ This deployment might take up to 15 minutes, depending on whether the underlying
553676
ml_client.online_endpoints.begin_create_or_update(endpoint)
554677
```
555678

679+
# [ARM template](#tab/arm)
680+
681+
1. The following example demonstrates using the template to create an online endpoint:
682+
683+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="create_endpoint":::
684+
685+
1. After the endpoint has been created, the following example demonstrates how to deploy the model to the endpoint:
686+
687+
:::code language="azurecli" source="~/azureml-examples-main/deploy-arm-templates-az-cli.sh" id="create_deployment":::
688+
556689
---
557690

558691
> [!TIP]
@@ -598,6 +731,21 @@ for endpoint in ml_client.online_endpoints.list():
598731
print(f"{endpoint.kind}\t{endpoint.location}\t{endpoint.name}")
599732
```
600733

734+
# [ARM template](#tab/arm)
735+
736+
> [!TIP]
737+
> While templates are useful for deploying resources, they can't be used to list, show, or invoke resources.
738+
739+
The `show` command contains information in `provisioning_status` for endpoint and deployment:
740+
741+
::: code language="azurecli" source="~/azureml-examples-main/cli/deploy-managed-online-endpoint.sh" ID="get_status" :::
742+
743+
You can list all the endpoints in the workspace in a table format by using the `list` command:
744+
745+
```azurecli
746+
az ml online-endpoint list --output table
747+
```
748+
601749
---
602750

603751
### Check the status of the online deployment
@@ -628,6 +776,16 @@ ml_client.online_deployments.get_logs(
628776
name="blue", endpoint_name=online_endpoint_name, lines=50, container_type="storage-initializer"
629777
)
630778
```
779+
780+
# [ARM template](#tab/arm)
781+
782+
> [!TIP]
783+
> While templates are useful for deploying resources, they can't be used to list, show, or invoke resources.
784+
785+
:::code language="azurecli" source="~/azureml-examples-main/cli/deploy-managed-online-endpoint.sh" ID="get_logs" :::
786+
787+
By default, logs are pulled from inference-server. To see the logs from storage-initializer (it mounts assets like model and code to the container), add the `--container storage-initializer` flag.
788+
631789
---
632790

633791
For more information on deployment logs, see [Get container logs](how-to-troubleshoot-online-endpoints.md#get-container-logs).
@@ -677,6 +835,17 @@ ml_client.online_endpoints.invoke(
677835
)
678836
```
679837

838+
# [ARM template](#tab/arm)
839+
840+
> [!TIP]
841+
> While templates are useful for deploying resources, they can't be used to list, show, or invoke resources.
842+
843+
You can use either the `invoke` command or a REST client of your choice to invoke the endpoint and score some data:
844+
845+
```azurecli
846+
az ml online-endpoint invoke --name $ENDPOINT_NAME --request-file cli/endpoints/online/model-1/sample-request.json
847+
```
848+
680849
---
681850

682851
### (Optional) Update the deployment
@@ -739,6 +908,10 @@ To understand how `begin_create_or_update` works:
739908

740909
The `begin_create_or_update` method also works with local deployments. Use the same method with the `local=True` flag.
741910

911+
# [ARM template](#tab/arm)
912+
913+
There currently is not an option to update the deployment using an ARM template.
914+
742915
---
743916

744917
> [!Note]
@@ -775,6 +948,10 @@ If you aren't going use the deployment, you should delete it by running the foll
775948
ml_client.online_endpoints.begin_delete(name=online_endpoint_name)
776949
```
777950

951+
# [ARM template](#tab/arm)
952+
953+
::: code language="azurecli" source="~/azureml-examples-main/cli/deploy-managed-online-endpoint.sh" ID="delete_endpoint" :::
954+
778955
---
779956

780957
## Next steps
@@ -791,4 +968,4 @@ To learn more, review these articles:
791968
- [Access Azure resources from an online endpoint with a managed identity](how-to-access-resources-from-endpoints-managed-identities.md)
792969
- [Troubleshoot online endpoints deployment](how-to-troubleshoot-online-endpoints.md)
793970
- [Enable network isolation with managed online endpoints](how-to-secure-online-endpoint.md)
794-
- [View costs for an Azure Machine Learning managed online endpoint](how-to-view-online-endpoints-costs.md)
971+
- [View costs for an Azure Machine Learning managed online endpoint](how-to-view-online-endpoints-costs.md)

0 commit comments

Comments
 (0)