This repository provides example code for a YouTube video on local deployment to Azure Machine Learning. You can see all of the Azure ML videos I've created using this YouTube playlist. The video for this repository is entitled Troubleshooting Azure ML deployments locally.
This data I used to train the accompanying model comes from the Chicago Parking Ticket database, courtesy of Daniel Hutmacher. I sampled 1,000,000 records from it and the file I used is available in CSV format.
You can see how I trained the model in my Getting Beyond the Basics with Azure Machine Learning repository.
Because this is intended as a learning experience, I purposefully included several ways for this script to fail, so you can see what sorts of error messages and problems you are likely to experience during development.
This repo assumes you have the following already installed on your machine:
- Python (preferably the Anaconda distribution), with
pip
installed:conda install -c anaconda pip
- The Azure CLI
- The Azure ML Azure CLI extension:
az extension add -n ml
- Pip packages:
pip install azure-ai-ml
,pip install azure-identity
- Docker Desktop or some other Docker container service
- Visual Studio Code
Before you run the code, make sure your console has you logged into Azure via CLI:
az login
Note that you must be logged into az cli
with an account which has access to the subscription, resource group, and workspace.
In deployment.py
, you will need to fill in your subscription ID, resource group name, and workspace name on lines 11-13. This is not a recommended practices for deployment scripts you would check into source control, but will work fine for a local demonstration.
Other than lines 11-13, the deployment code should be runnable as-is. The endpoint and deployment operations are also idempotent, meaning that you should be able to re-run the commands without getting an error, regardless of whether you already have the endpoint and deployment set up on your machine or not.
There are four major failure modes we cover in this repository:
- You cannot use curated Azure ML environments for a local deployment. You can only use a Docker container image to which you have direct access (either because it is publicly available or because you have built the container image and hosted it in a repository to which you have access).
- Local deployments may not access the Azure ML model registry. You must use a model file.
- Your scoring script must include
init()
andrun()
endpoints. - The
init()
andrun()
endpoints must behave correctly.
The score_model_local.py
file represents a valid working example of a scoring script for an Azure ML managed online endpoint. Note that it has decorators from the InferenceSchema library because I used this example in a demonstration video connecting Power BI to Azure Machine Learning.
The score_model_remote.py
file represents what a scoring script would look like for a remote deployment. This script will not work for local deployments.