Skip to content

Commit f9613de

Browse files
committed
Freshness pass
1 parent 63551fa commit f9613de

File tree

1 file changed

+36
-45
lines changed

1 file changed

+36
-45
lines changed

articles/machine-learning/how-to-debug-managed-online-endpoints-visual-studio-code.md

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Debug online endpoints locally in VS Code (preview)
2+
title: Debug online endpoints locally in Visual Studio Code
33
titleSuffix: Azure Machine Learning
44
description: Learn how to use Visual Studio Code to test and debug online endpoints locally before deploying them to Azure.
55
services: machine-learning
@@ -8,7 +8,7 @@ ms.subservice: inferencing
88
author: dem108
99
ms.author: sehan
1010
ms.reviewer: mopeakande
11-
ms.date: 11/03/2021
11+
ms.date: 03/13/2024
1212
ms.topic: troubleshooting
1313
ms.custom: devplatv2, devx-track-azurecli, cliv2
1414
ms.devlang: azurecli
@@ -36,12 +36,12 @@ This guide focuses on local endpoints.
3636

3737
The following table provides an overview of scenarios to help you choose what works best for you.
3838

39-
| Scenario | Inference HTTP Server | Local endpoint |
39+
| Scenario | Inference HTTP server | Local endpoint |
4040
|--|--|--|
4141
| Update local Python environment, **without** Docker image rebuild | Yes | No |
4242
| Update scoring script | Yes | Yes |
4343
| Update deployment configurations (deployment, environment, code, model) | No | Yes |
44-
| VS Code Debugger integration | Yes | Yes |
44+
| VS Code debugger integration | Yes | Yes |
4545

4646
## Prerequisites
4747

@@ -52,16 +52,15 @@ This guide assumes you have the following items installed locally on your PC.
5252
- [Docker](https://docs.docker.com/engine/install/)
5353
- [VS Code](https://code.visualstudio.com/#alt-downloads)
5454
- [Azure CLI](/cli/azure/install-azure-cli)
55-
- [Azure CLI `ml` extension (v2)](how-to-configure-cli.md)
55+
- [Azure CLI ml extension (v2)](how-to-configure-cli.md)
5656

5757
For more information, see the guide on [how to prepare your system to deploy online endpoints](how-to-deploy-online-endpoints.md#prepare-your-system).
5858

59-
The examples in this article are 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 and then change directories to the `cli` directory in the repo:
59+
The examples in this article are based on code samples contained in the [azureml-examples](https://github.com/azure/azureml-examples) GitHub repository. To run the commands locally without having to copy/paste YAML and other files, clone the repo and then change directories to the *azureml-examples/cli* directory in the repo:
6060

6161
```azurecli
6262
git clone https://github.com/Azure/azureml-examples --depth 1
63-
cd azureml-examples
64-
cd cli
63+
cd azureml-examples/cli
6564
```
6665

6766
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, use the following commands. Replace the following parameters with values for your specific configuration:
@@ -80,27 +79,28 @@ az configure --defaults workspace=<workspace> group=<resource-group> location=<l
8079
```
8180

8281
# [Python](#tab/python)
82+
8383
[!INCLUDE [sdk v2](includes/machine-learning-sdk-v2.md)]
8484

8585
This guide assumes you have the following items installed locally on your PC.
8686

8787
- [Docker](https://docs.docker.com/engine/install/)
8888
- [VS Code](https://code.visualstudio.com/#alt-downloads)
8989
- [Azure CLI](/cli/azure/install-azure-cli)
90-
- [Azure CLI `ml` extension (v2)](how-to-configure-cli.md)
90+
- [Azure CLI ml extension (v2)](how-to-configure-cli.md)
9191
- [Azure Machine Learning Python SDK (v2)](https://aka.ms/sdk-v2-install)
9292

9393
For more information, see the guide on [how to prepare your system to deploy online endpoints](how-to-deploy-online-endpoints.md#prepare-your-system).
9494

95-
The examples in this article can be found in the [Debug online endpoints locally in Visual Studio Code](https://github.com/Azure/azureml-examples/blob/main/sdk/python/endpoints/online/managed/debug-online-endpoints-locally-in-visual-studio-code.ipynb) notebook within the[azureml-examples](https://github.com/azure/azureml-examples) repository. To run the code locally, clone the repo and then change directories to the notebook's parent directory `sdk/endpoints/online/managed`.
95+
The examples in this article can be found in the Jupyter notebook called [Debug online endpoints locally in Visual Studio Code](https://github.com/Azure/azureml-examples/blob/main/sdk/python/endpoints/online/managed/debug-online-endpoints-locally-in-visual-studio-code.ipynb) within the [azureml-examples](https://github.com/azure/azureml-examples) repository. To run the code locally, clone the repo and then change directories to the notebook's parent directory *sdk/endpoints/online/managed*.
9696

9797
```azurecli
9898
git clone https://github.com/Azure/azureml-examples --depth 1
9999
cd azureml-examples
100100
cd sdk/python/endpoints/online/managed
101101
```
102102

103-
Import the required modules:
103+
Open the Jupyter notebook and import the required modules:
104104

105105
```python
106106
from azure.ai.ml import MLClient
@@ -112,25 +112,25 @@ from azure.ai.ml.entities import (
112112
Environment,
113113
)
114114
from azure.identity import DefaultAzureCredential
115-
```
115+
```
116116

117-
Set up variables for the workspace and endpoint:
117+
Set up variables for the workspace and endpoint:
118118

119-
```python
119+
```python
120120
subscription_id = "<SUBSCRIPTION_ID>"
121121
resource_group = "<RESOURCE_GROUP>"
122122
workspace_name = "<AML_WORKSPACE_NAME>"
123123

124124
endpoint_name = "<ENDPOINT_NAME>"
125-
```
125+
```
126126

127-
---
127+
---
128128

129129
## Launch development container
130130

131131
# [Azure CLI](#tab/cli)
132132

133-
Azure Machine Learning local endpoints use Docker and VS Code development containers (dev container) to build and configure a local debugging environment. With dev containers, you can take advantage of VS Code features from inside a Docker container. For more information on dev containers, see [Create a development container](https://code.visualstudio.com/docs/remote/create-dev-container).
133+
Azure Machine Learning local endpoints use Docker and VS Code development containers (dev containers) to build and configure a local debugging environment. With dev containers, you can take advantage of VS Code features from inside a Docker container. For more information on dev containers, see [Create a development container](https://code.visualstudio.com/docs/remote/create-dev-container).
134134

135135
To debug online endpoints locally in VS Code, use the `--vscode-debug` flag when creating or updating and Azure Machine Learning online deployment. The following command uses a deployment example from the examples repo:
136136

@@ -144,7 +144,7 @@ az ml online-deployment create --file endpoints/online/managed/sample/blue-deplo
144144
A Docker image is built locally. Any environment configuration or model file errors are surfaced at this stage of the process.
145145

146146
> [!NOTE]
147-
> The first time you launch a new or updated dev container it can take several minutes.
147+
> The first time you launch a new or updated dev container, it can take several minutes.
148148
149149
Once the image successfully builds, your dev container opens in a VS Code window.
150150

@@ -158,22 +158,21 @@ You'll use a few VS Code extensions to debug your deployments in the dev contain
158158
> [!IMPORTANT]
159159
> Before starting your debug session, make sure that the VS Code extensions have finished installing in your dev container.
160160
161-
162161
# [Python](#tab/python)
163162

164163
Azure Machine Learning local endpoints use Docker and VS Code development containers (dev container) to build and configure a local debugging environment. With dev containers, you can take advantage of VS Code features from inside a Docker container. For more information on dev containers, see [Create a development container](https://code.visualstudio.com/docs/remote/create-dev-container).
165164

166-
Get a handle to the workspace:
165+
Get a handle to the workspace:
167166

168-
```python
167+
```python
169168
credential = DefaultAzureCredential()
170169
ml_client = MLClient(
171170
credential,
172171
subscription_id=subscription_id,
173172
resource_group_name=resource_group,
174173
workspace_name=workspace_name,
175174
)
176-
```
175+
```
177176

178177
To debug online endpoints locally in VS Code, set the `vscode-debug` and `local` flags when creating or updating an Azure Machine Learning online deployment. The following code mirrors a deployment example from the examples repo:
179178

@@ -199,41 +198,38 @@ You'll use a few VS Code extensions to debug your deployments in the dev contain
199198
> [!IMPORTANT]
200199
> Before starting your debug session, make sure that the VS Code extensions have finished installing in your dev container.
201200
202-
---
203-
204-
205-
206201
---
207202

208203
## Start debug session
209204

210205
Once your environment is set up, use the VS Code debugger to test and debug your deployment locally.
211206

212-
1. Open your scoring script in Visual Studio Code.
207+
1. Open your scoring script in VS Code.
213208

214209
> [!TIP]
215-
> The score.py script used by the endpoint deployed earlier is located at `azureml-samples/cli/endpoints/online/managed/sample/score.py` in the repository you cloned. However, the steps in this guide work with any scoring script.
210+
> The *score.py* script used by the endpoint deployed earlier is located at *azureml-samples/cli/endpoints/online/managed/sample/score.py* in the repository you cloned. However, the steps in this guide work with any scoring script.
216211
217212
1. Set a breakpoint anywhere in your scoring script.
218213

219214
- To debug startup behavior, place your breakpoint(s) inside the `init` function.
220215
- To debug scoring behavior, place your breakpoint(s) inside the `run` function.
221216

222217
1. Select the VS Code Job view.
223-
1. In the Run and Debug dropdown, select **AzureML: Debug Local Endpoint** to start debugging your endpoint locally.
218+
219+
1. In the **Run and Debug** dropdown, select **AzureML: Debug Local Endpoint** to start debugging your endpoint locally.
224220

225221
In the **Breakpoints** section of the Run view, check that:
226222

227223
- **Raised Exceptions** is **unchecked**
228224
- **Uncaught Exceptions** is **checked**
229225

230-
:::image type="content" source="media/how-to-debug-managed-online-endpoints-visual-studio-code/configure-debug-profile.png" alt-text="Configure Azure Machine Learning Debug Local Environment debug profile":::
226+
:::image type="content" source="media/how-to-debug-managed-online-endpoints-visual-studio-code/configure-debug-profile.png" alt-text="Screenshot showing how to configure Azure Machine Learning Debug Local Environment debug profile" lightbox="media/how-to-debug-managed-online-endpoints-visual-studio-code/configure-debug-profile.png":::
231227

232-
1. Select the play icon next to the Run and Debug dropdown to start your debugging session.
228+
1. Select the play icon next to the **Run and Debug** dropdown to start your debugging session.
233229

234230
At this point, any breakpoints in your `init` function are caught. Use the debug actions to step through your code. For more information on debug actions, see the [debug actions guide](https://code.visualstudio.com/Docs/editor/debugging#_debug-actions).
235231

236-
For more information on the VS Code debugger, see [Debugging in VS Code](https://code.visualstudio.com/Docs/editor/debugging)
232+
For more information on the VS Code debugger, see [Debugging in VS Code](https://code.visualstudio.com/Docs/editor/debugging).
237233

238234
## Debug your endpoint
239235

@@ -283,7 +279,6 @@ In this case, `<REQUEST-FILE>` is a JSON file that contains input data samples f
283279
284280
At this point, any breakpoints in your `run` function are caught. Use the debug actions to step through your code. For more information on debug actions, see the [debug actions guide](https://code.visualstudio.com/Docs/editor/debugging#_debug-actions).
285281
286-
287282
# [Python](#tab/python)
288283
289284
Now that your application is running in the debugger, try making a prediction to debug your scoring script.
@@ -334,9 +329,7 @@ In this case, `<REQUEST-FILE>` is a JSON file that contains input data samples f
334329
335330
At this point, any breakpoints in your `run` function are caught. Use the debug actions to step through your code. For more information on debug actions, see the [debug actions guide](https://code.visualstudio.com/Docs/editor/debugging#_debug-actions).
336331
337-
338-
---
339-
332+
---
340333
341334
## Edit your endpoint
342335
@@ -346,13 +339,13 @@ As you debug and troubleshoot your application, there are scenarios where you ne
346339
347340
To apply changes to your code:
348341
349-
1. Update your code
342+
1. Update your code.
350343
1. Restart your debug session using the `Developer: Reload Window` command in the command palette. For more information, see the [command palette documentation](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette).
351344
352345
> [!NOTE]
353346
> Since the directory containing your code and endpoint assets is mounted onto the dev container, any changes you make in the dev container are synced with your local file system.
354347
355-
For more extensive changes involving updates to your environment and endpoint configuration, use the `ml` extension `update` command. Doing so will trigger a full image rebuild with your changes.
348+
For more extensive changes involving updates to your environment and endpoint configuration, use the `ml` extension `update` command. Doing so triggers a full image rebuild with your changes.
356349
357350
```azurecli
358351
az ml online-deployment update --file <DEPLOYMENT-YAML-SPECIFICATION-FILE> --local --vscode-debug
@@ -366,23 +359,21 @@ As you debug and troubleshoot your application, there are scenarios where you ne
366359
367360
To apply changes to your code:
368361
369-
1. Update your code
362+
1. Update your code.
370363
1. Restart your debug session using the `Developer: Reload Window` command in the command palette. For more information, see the [command palette documentation](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette).
371364
372365
> [!NOTE]
373366
> Since the directory containing your code and endpoint assets is mounted onto the dev container, any changes you make in the dev container are synced with your local file system.
374367
375-
For more extensive changes involving updates to your environment and endpoint configuration, use your `MLClient`'s `online_deployments.update` module/method. Doing so will trigger a full image rebuild with your changes.
368+
For more extensive changes involving updates to your environment and endpoint configuration, use your `MLClient`'s `online_deployments.update` module/method. Doing so triggers a full image rebuild with your changes.
376369
377370
[!notebook-python[] (~/azureml-examples-main/sdk/python/endpoints/online/managed/debug-online-endpoints-locally-in-visual-studio-code.ipynb?name=edit-endpoint-1)]
378371
379372
Once the updated image is built and your development container launches, use the VS Code debugger to test and troubleshoot your updated endpoint.
380373
374+
---
381375
382-
383-
---
384-
385-
## Next steps
376+
## Related content
386377
387378
- [Deploy and score a machine learning model by using an online endpoint)](how-to-deploy-online-endpoints.md)
388-
- [Troubleshooting managed online endpoints deployment and scoring)](how-to-troubleshoot-managed-online-endpoints.md)
379+
- [Troubleshooting online endpoints deployment and scoring)](how-to-troubleshoot-managed-online-endpoints.md)

0 commit comments

Comments
 (0)