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
title: Debug with Azure Machine Learning inference server
2
+
title: Debug with the Azure Machine Learning inference server
3
3
titleSuffix: Azure Machine Learning
4
4
description: Learn how to enable local development with Azure Machine Learning inference HTTP server, and debug scoring scripts or endpoints before you deploy to the cloud.
5
5
author: msakande
@@ -15,33 +15,27 @@ ms.date: 08/21/2024
15
15
#customer intent: As a developer, I want to work with the Azure Machine Learning inference HTTP server so I can debug scoring scripts or endpoints before deployment.
16
16
---
17
17
18
-
# Debug scoring scripts with Azure Machine Learning inference HTTP server
18
+
# Debug scoring scripts by using the Azure Machine Learning inference HTTP server
19
19
20
-
The Azure Machine Learning inference HTTP server is a Python package that exposes your scoring function as an HTTP endpoint and wraps the Flask server code and dependencies into a singular package. The server is included in the [prebuilt Docker images for inference](concept-prebuilt-docker-images-inference.md) that are used when deploying a model with Azure Machine Learning. Using the package alone, you can deploy the model locally for production, and easily validate your scoring (entry) script in a local development environment. If there's a problem with the scoring script, the server returns an error and the location of the error.
20
+
The Azure Machine Learning inference HTTP server is a Python package that exposes your scoring function as an HTTP endpoint and wraps the Flask server code and dependencies into a singular package. The server is included in the [prebuilt Docker images for inference](concept-prebuilt-docker-images-inference.md) that are used when you deploy a model in Azure Machine Learning. When you use the package alone, you can deploy the model locally for production, and easily validate your scoring (entry) script in a local development environment. If there's a problem with the scoring script, the server returns an error and the location of the error.
21
21
22
-
The server can also be used to create validation gates in a continuous integration and deployment pipeline. For example, you can start the server with the candidate script and run the test suite against the local endpoint.
22
+
You can also use the server to create validation gates in a continuous integration and deployment pipeline. For example, you can start the server with the candidate script and run the test suite against the local endpoint.
23
23
24
-
This article supports developers who want to use the inference server to debug locally and describes how to use the inference server with online endpoints on Windows.
24
+
This article supports developers who want to use the inference server to debug locally. The Azure Machine Learning inference HTTP server runs on Windows and Linux based operating systems.
25
25
26
26
## Prerequisites
27
27
28
-
To use the Azure Machine Learning inference HTTP server for local debugging, your configuration must include the following components:
29
-
30
28
- Python 3.8 or later
31
29
- Anaconda
32
30
33
-
The Azure Machine Learning inference HTTP server runs on Windows and Linux based operating systems.
34
-
35
31
## Explore local debugging options for online endpoints
36
32
37
33
By debugging endpoints locally before you deploy to the cloud, you can catch errors in your code and configuration earlier. To debug endpoints locally, you have several options, including:
38
34
39
-
- The Azure Machine Learning inference HTTP server
40
-
- A [local endpoint](how-to-debug-managed-online-endpoints-visual-studio-code.md)
35
+
- The Azure Machine Learning inference HTTP server.
36
+
- A [local endpoint](how-to-debug-managed-online-endpoints-visual-studio-code.md).
41
37
42
-
This article describes how to work with the Azure Machine Learning inference HTTP server on Windows.
43
-
44
-
The following table provides an overview of scenarios to help you choose the best option:
38
+
The following table provides an overview of the support in each option for various debugging scenarios:
45
39
46
40
| Scenario | Inference HTTP server | Local endpoint |
47
41
| --- | :---: | :---: |
@@ -50,38 +44,30 @@ The following table provides an overview of scenarios to help you choose the bes
| Integrate Microsoft Visual Studio Code (VS Code) Debugger | Yes | Yes |
52
46
53
-
When you run the inference HTTP server locally, you can focus on debugging your scoring script without concern for deployment container configurations.
54
-
55
-
## Install azureml-inference-server-http package
56
-
57
-
To install the `azureml-inference-server-http` package, run the following command:
This article describes how to use the Azure Machine Learning inference HTTP server with online endpoints on Windows.
62
48
63
-
> [!NOTE]
64
-
> To avoid package conflicts, install the inference HTTP server in a virtual environment.
65
-
> You can use the `pip install virtualenv` command to enable virtual environments for your configuration.
49
+
When you run the inference HTTP server locally, you can focus on debugging your scoring script without concern for deployment container configurations.
66
50
67
51
## Debug your scoring script locally
68
52
69
53
To debug your scoring script locally, you have several options for testing the server behavior:
70
54
71
-
-Try a dummy scoring script.
55
+
-Use a dummy scoring script.
72
56
- Use Visual Studio Code to debug with the [azureml-inference-server-http](https://pypi.org/project/azureml-inference-server-http/) package.
73
-
- Run an actual scoring script, model file, and environment file from our [examples repo](https://github.com/Azure/azureml-examples).
57
+
- Run an actual scoring script, model file, and environment file from the [examples repo](https://github.com/Azure/azureml-examples).
58
+
59
+
The following sections provide information about each option.
74
60
75
-
### Test server behavior with dummy scoring script
61
+
### Use a dummy scoring script to test server behavior
76
62
77
-
1. Create a directory named _server\_quickstart_ to hold your files:
63
+
1. Create a directory named server\_quickstart to hold your files:
78
64
79
65
```bash
80
66
mkdir server_quickstart
81
67
cd server_quickstart
82
68
```
83
69
84
-
1. To avoid package conflicts, create a virtual environment, such as _myenv_, and activate it:
70
+
1. To avoid package conflicts, create a virtual environment, such as `myenv`, and activate it:
85
71
86
72
```bash
87
73
python -m virtualenv myenv
@@ -90,9 +76,6 @@ To debug your scoring script locally, you have several options for testing the s
90
76
> [!NOTE]
91
77
> On Linux, run the `source myenv/bin/activate` command to activate the virtual environment.
92
78
93
-
<!-- Reviewer: The 'source' command appears to apply to Linux only.
94
-
I found that the 'python -m virtualenv...' command (as opposed to 'python -m venv ...') both creates and activates the env. -->
95
-
96
79
After you test the server, you can run the `deactivate` command to deactivate the Python virtual environment.
97
80
98
81
1. Install the `azureml-inference-server-http` package from the [pypi](https://pypi.org/project/azureml-inference-server-http/) feed:
@@ -101,16 +84,13 @@ To debug your scoring script locally, you have several options for testing the s
1. Start the server with the `azmlinfsrv` command and set the _score.py_ file as the entry script:
111
-
112
-
<!-- Reviewer: The following command doesn't fully succeed.
113
-
I'll add a screenshot of the output in the PR comments. -->
93
+
1. Use the `azmlinfsrv` command to start the server and set the score.py file as the entry script:
114
94
115
95
```bash
116
96
azmlinfsrv --entry_script score.py
@@ -119,9 +99,7 @@ To debug your scoring script locally, you have several options for testing the s
119
99
> [!NOTE]
120
100
> The server is hosted on 0.0.0.0, which means it listens to all IP addresses of the hosting machine.
121
101
122
-
1. Send a scoring request to the server by using the `curl` utility:
123
-
124
-
<!-- Reviewer: Because the previous command doesn't fully succeed, I can't verify the output. -->
102
+
1. Use the `curl` utility to send a scoring request to the server:
125
103
126
104
```bash
127
105
curl -p 127.0.0.1:5001/score
@@ -133,121 +111,130 @@ To debug your scoring script locally, you have several options for testing the s
133
111
{"message": "Hello, World!"}
134
112
```
135
113
136
-
1. After testing, select Ctrl + C to terminate the server.
114
+
1. After testing, select **Ctrl**+**C** to stop the server.
137
115
138
-
Now you can modify the scoring script file (_score.py_) and test your changes by running the server again with the `azmlinfsrv --entry_script score.py` command.
116
+
You can modify the score.py scoring script file and test your changes by using the `azmlinfsrv --entry_script score.py` command to run the server again.
139
117
140
118
### Integrate with Visual Studio Code
141
119
142
-
To use VS Code and the [Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for debugging with the [azureml-inference-server-http](https://pypi.org/project/azureml-inference-server-http/) package, you can use the [Launch and Attach modes](https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations).
143
-
144
-
- For **Launch mode**, set up the _launch.json_ file in VS Code and start the Azure Machine Learning inference HTTP server within VS Code:
145
-
146
-
1. Start VS Code and open the folder containing the script (_score.py_).
120
+
In VS Code, you can use the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python) for debugging with the [azureml-inference-server-http](https://pypi.org/project/azureml-inference-server-http/) package. VS Code offers two modes for debugging: [launch and attach](https://code.visualstudio.com/docs/editor/debugging#_launch-versus-attach-configurations).
147
121
148
-
1. Add the following configuration to the _launch.json_ file for that workspace in VS Code:
122
+
Before you use either mode, install the `azureml-inference-server-http` package by running the following command:
1. Start the debugging session in VS Code by selecting **Run** > **Start Debugging** or use the keyboard shortcut F5.
128
+
> [!NOTE]
129
+
> To avoid package conflicts, install the inference HTTP server in a virtual environment. You can use the `pip install virtualenv` command to turn on virtual environments for your configuration.
130
+
131
+
#### Launch mode
132
+
133
+
For launch mode, take the following steps to set up the VS Code launch.json configuration file and start the Azure Machine Learning inference HTTP server within VS Code:
134
+
135
+
1. Start VS Code and open the folder that contains the score.py script.
136
+
137
+
1. For that workspace in VS Code, add the following configuration to the launch.json file:
- For **Attach mode**, start the Azure Machine Learning inference HTTP server in a command window, and use VS Code with the Python Extension to attach to the process:
157
+
1. Start the debugging session in VS Code by selecting **Run** > **Start Debugging** or by selecting **F5**.
173
158
174
-
> [!NOTE]
175
-
> For Linux, first install the `gdb` package by running the `sudo apt-get install -y gdb` command.
159
+
#### Attach mode
176
160
177
-
1. Add the following configuration to the _launch.json_ file for that workspace in VS Code:
178
-
179
-
**launch.json**
161
+
For attach mode, take the following steps to use VS Code with the Python extension to attach to the Azure Machine Learning inference HTTP server process:
180
162
181
-
```json
182
-
{
183
-
"version": "0.2.0",
184
-
"configurations": [
185
-
{
186
-
"name": "Python: Attach using Process Id",
187
-
"type": "python",
188
-
"request": "attach",
189
-
"processId": "${command:pickProcess}",
190
-
"justMyCode": true
191
-
}
192
-
]
193
-
}
194
-
```
163
+
> [!NOTE]
164
+
> For Linux, first install the `gdb` package by running the `sudo apt-get install -y gdb` command.
165
+
166
+
1. Start VS Code and open the folder that contains the score.py script.
167
+
168
+
1. For that workspace in VS Code, add the following configuration to the launch.json file:
169
+
170
+
```json
171
+
{
172
+
"version": "0.2.0",
173
+
"configurations": [
174
+
{
175
+
"name": "Python: Attach using Process Id",
176
+
"type": "debugpy",
177
+
"request": "attach",
178
+
"processId": "${command:pickProcess}",
179
+
"justMyCode": true
180
+
}
181
+
]
182
+
}
183
+
```
195
184
196
-
1. In a command window, start the inference HTTP server by using the `azmlinfsrv --entry_script score.py` command.
185
+
1. In a command window, start the inference HTTP server by running the `azmlinfsrv --entry_script score.py` command.
197
186
198
-
1. Start the debugging session in VS Code:
187
+
1. Take the following steps to start the debugging session in VS Code:
199
188
200
-
1. Select **Run** > **Start Debugging** or use the keyboard shortcut F5.
189
+
1. Select **Run** > **Start Debugging**, or select **F5**.
201
190
202
-
1. In the command window, view the logs from the inference server and locate the process ID of the `azmlinfsrv` command (not the `gunicorn`):
191
+
1. In the command window, search the logs from the inference server to locate the process ID of the `azmlinfsrv`process, not the `gunicorn` process:
203
192
204
-
:::image type="content" source="./media/how-to-inference-server-http/debug-attach-pid.png" border="false" alt-text="Screenshot that shows a command window displaying logs from the inference HTTP server and the process ID of the azmlinfsrv command highlighted.":::
193
+
:::image type="content" source="./media/how-to-inference-server-http/debug-attach-pid.png" border="false" alt-text="Screenshot of a command window that shows inference HTTP server logs. In one log statement, the process ID of the azmlinfsrv command is highlighted.":::
205
194
206
-
1. In the VS Code Debugger, enter the process ID of the `azmlinfsrv` command.
195
+
1. In the VS Code debugger, enter the process ID of the `azmlinfsrv`process.
207
196
208
-
If you don't see the VS Code process picker, you can manually enter the process ID in the `processId` field of the _launch.json_ file for that workspace.
197
+
If you don't see the VS Code process picker, manually enter the process ID in the `processId` field of the launch.json file for the workspace.
209
198
210
-
For both modes, you can set [breakpoints](https://code.visualstudio.com/docs/editor/debugging#_breakpoints) and debug the script step by step.
199
+
For launch and attach modes, you can set [breakpoints](https://code.visualstudio.com/docs/editor/debugging#_breakpoints) and debug the script step by step.
211
200
212
201
### Use an end-to-end example
213
202
214
203
The following procedure runs the server locally with [sample files](https://github.com/Azure/azureml-examples/tree/main/cli/endpoints/online/model-1) (scoring script, model file, and environment) from the Azure Machine Learning example repository. For more examples of how to use these sample files, see [Deploy and score a machine learning model by using an online endpoint](how-to-deploy-online-endpoints.md).
215
204
216
-
1. Clone the sample repository:
205
+
1. Clone the sample repository and go to the folder that contains the relevant sample files:
1.Create and activate a virtual environment with [conda](https://conda.io/projects/conda/en/latest/user-guide/getting-started.html):
212
+
1.Use [conda](https://conda.io/projects/conda/en/latest/user-guide/getting-started.html) to create and activate a virtual environment:
224
213
225
-
In this example, the `azureml-inference-server-http` package is automatically installed. The package is included as a dependent library of the `azureml-defaults` package in the _conda.yaml_ file:
214
+
In this example, the `azureml-inference-server-http` package is automatically installed. The package is included as a dependent library of the `azureml-defaults` package in the conda.yaml file:
1. Run the inference HTTP server by specifying the scoring script and model file:
227
+
1. Run the inference HTTP server by specifying the scoring script and model file.
241
228
242
-
The model directory specified in the `model_dir` parameter is defined by using the `AZUREML_MODEL_DIR` variable and retrieved in the scoring script.
229
+
The model directory specified in the `model_dir` parameter is defined by using the `AZUREML_MODEL_DIR` variable and retrieved in the scoring script.
243
230
244
-
In this case, you specify the current directory_./_ because the subdirectory is specified in the scoring script as _model/sklearn\_regression\_model.pkl_.
231
+
In this case, you use the current directory, `./`, as the `model_dir` value, because the scoring script specifies the subdirectory as `model/sklearn\_regression\_model.pkl`.
When the server launches and successfully invokes the scoring script, the example [startup log](#view-startup-logs) opens. Otherwise, the log shows error messages.
237
+
When the server starts and successfully invokes the scoring script, the example [startup log](#view-startup-logs) opens. Otherwise, the log shows error messages.
0 commit comments