Lab 5 - Deploy to Managed Endpoint
This lab may not work in an Azure Pass Subscription.
For this lab to work, the Microsoft.PolicyInsights needs to be registered in your subscription. Follow this tutorial
1
# Delete the compute cluster (only needed if you have an Azue subscription)
2
az ml compute delete -n gpu-cluster
Copied!
In this lab you are going to deploy the model in managed endpoint.

Get the scoring script

1
# Create a directory
2
mkdir deploy
3
cd deploy
4
5
# Download the scoring script
6
wget https://raw.githubusercontent.com/GlobalAICommunity/back-together-2021/main/workshop-assets/amls/score.py
Copied!
Stay in the same directory

Create the scoring environment

Create an empty yml file for the environment configuration.
1
code conda.yml
Copied!
Add the content below to the conda.yml file.
1
name: project_environment
2
channels:
3
- conda-forge
4
- defaults
5
dependencies:
6
- python=3.6.2
7
- pip:
8
- azureml-defaults
9
- torch
10
- torchvision
11
- pillow==5.4.1
Copied!

Create the endpoint configuration

Create an empty yml file for the deployment configuration.
1
code deployment.yml
Copied!
Add the content below to the file
1
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json
2
name: <your-name>
3
type: online
4
auth_mode: key
5
traffic:
6
version1: 100
7
deployments:
8
- name: version1
9
app_insights_enabled: true
10
model: azureml:SimpsonsClassification-pytorch:1
11
code_configuration:
12
code:
13
local_path: ./
14
scoring_script: score.py
15
environment:
16
name: simpsons-inference
17
version: 1
18
path: .
19
conda_file: file:conda.yml
20
docker:
21
image: mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04:20210727.v1
22
instance_type: Standard_F4s_v2
23
scale_settings:
24
scale_type: Manual
25
instance_count: 1
26
min_instances: 1
27
max_instances: 1
Copied!
Replace: <your-name> with your unique name, like: henks-endpoint
Use the command below to create a managed endpoint
1
az ml endpoint create --file deployment.yml
Copied!

Test the endpoint

Create a new file for the request json.
1
code request.json
Copied!
Add the content below to the file
1
{
2
"image":"https://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Bart.jpg"
3
}
Copied!
Use the command below to invoke the endpoint!
1
az ml endpoint invoke -n simpsons-endpoint --request-file request.json
Copied!
As a result you show see that it has seen Bar Simpson on the image.

Recap