Global AI Workshops
  • Welcome
  • Getting started
    • Lab 1 - Get Azure Access
    • Lab 2 - Setup Dev Environment
  • The Azure Function that can see
    • Introduction
    • Lab 1 - Train your model
    • Lab 2 - Create the Function
    • Clean up
  • Cognitive Services
    • Lab 1 - Cognitive Search
    • Lab 2 - Bot Composer
  • Azure machine learning
    • Introduction
    • Lab 1 - AML Workspace Setup
    • Lab 2 - Data
    • Lab 3 - Train your model
    • Lab 4 - Deploy to an ACI
      • Lab 4.2 - Deploy to ACI using the Azure Portal
      • Lab 4.1 - Deploy to ACI using Python
    • Lab 5 - Deploy to Managed Endpoint
    • Clean Up
Powered by GitBook
On this page
  • Get the scoring script
  • Create the scoring environment
  • Create the endpoint configuration
  • Test the endpoint
  • Recap

Was this helpful?

  1. Azure machine learning

Lab 5 - Deploy to Managed Endpoint

PreviousLab 4.1 - Deploy to ACI using PythonNextClean Up

Last updated 3 years ago

Was this helpful?

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.

# Delete the compute cluster (only needed if you have an Azue subscription)
az ml compute delete -n gpu-cluster

In this lab you are going to deploy the model in managed endpoint.

Get the scoring script

# Create a directory
mkdir deploy
cd deploy

# Download the scoring script
wget https://raw.githubusercontent.com/GlobalAICommunity/back-together-2021/main/workshop-assets/amls/score.py

Stay in the same directory

Create the scoring environment

Create an empty yml file for the environment configuration.

code conda.yml

Add the content below to the conda.yml file.

name: project_environment
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.6.2
  - pip:
    - azureml-defaults
    - torch
    - torchvision
    - pillow==5.4.1

Create the endpoint configuration

Create an empty yml file for the deployment configuration.

code deployment.yml

Add the content below to the file

$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json
name: <your-name>
type: online
auth_mode: key
traffic:
  version1: 100
deployments:
  - name: version1    
    app_insights_enabled: true
    model: azureml:SimpsonsClassification-pytorch:1
    code_configuration:
      code: 
        local_path: ./
      scoring_script: score.py
    environment: 
      name: simpsons-inference
      version: 1           
      path: .
      conda_file: file:conda.yml
      docker:
        image: mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04:20210727.v1
    instance_type: Standard_F4s_v2
    scale_settings:
      scale_type: Manual
      instance_count: 1
      min_instances: 1
      max_instances: 1

Replace: <your-name> with your unique name, like: henks-endpoint

Use the command below to create a managed endpoint

az ml endpoint create --file deployment.yml

Test the endpoint

Create a new file for the request json.

code request.json

Add the content below to the file

{
    "image":"https://raw.githubusercontent.com/hnky/dataset-lego-figures/master/_test/Bart.jpg"
}

Use the command below to invoke the endpoint!

az ml endpoint invoke -n simpsons-endpoint --request-file request.json

As a result you show see that it has seen Bar Simpson on the image.

Recap

Follow this tutorial