Demo for MLOps with Azure Machine Learning
This repo shows some introduction examples to Azure Machine Learning and a simple MLOps implemenation for automating model training and deployment.
This gives a short, high-level overview of how this repo may be used.
data/german_credit_data.csv
and name it german_credit_dataset
(download the file to your machine and select From Local File
when creating a new Dataset)data/german_credit_data.csv
and name it german_credit_file
(use From Datastore
and point to the same file as in the prior step)models/german-credit-basic/notebooks/german-credit-local.ipynb
- Shows how to run local training inside the Compute Instance, registers the model with data linage, and calculates the model explainabilitymodels/german-credit-basic/notebooks/german-credit-amlcompute.ipynb
- Shows how to train the same model on a Compute Clustermodels/german-credit-basic/notebooks/deploy_webservices.ipynb
- Shows how to deploy the trained model to an Azure Container InstanceSSL enabled
(using the Microsoft certificate)aml-workspace-connection
pipelines/german-credit-config.yml
and adapt the values to point to your workspacepipelines/german-credit-train-and-register.yml
- Trains and registers the model automaticallypipelines/german-credit-deploy.yml
- Deploys the trained model to AKSpipelines/
runningpipelines-staged/german-credit-config-dev.yml
and pipelines-staged/german-credit-config-prod.yml
and adapt the values to point to your dev and prod workspacespipelines-staged/german-credit-rollout.yml
- Trains, registers, and deploys the model automatically to a Dev environment, once successful, the same is repeated in a Prod environmentThis repo is fully based on conventions in order to make MLOps reusable and easily scaleable.
The directory structure is as follows:
pipelines
\- german-credit-config.yml - Configuration for german credit model
\- german-credit-deploy.yml - Deployment pipeline for german credit model
\- german-credit-train-and-register.yml - Pipline for training and registering the base german credit model
models
\- model1
train.py (entry file for training)
score.py (entry file for scoring)
\- config
deployment-config-aks.yml - Deployment infrastructure definition (e.g., AKS configuration)
inference-conda.yml - Conda environement definition for inferencing/scoring
inference-config.yml - Azure Machine Learning config for inferencing
train-conda.yml - Conda environement definition for training
\- model2
...same file and folder structure...
This snipped can be used to manually showcase/test the deployed model on ACI:
import requests
import json
url = '<scoring url>'
key = '<api key>'
test_data = {
'data': [{
"Age": 20,
"Sex": "male",
"Job": 0,
"Housing": "own",
"Saving accounts": "little",
"Checking account": "little",
"Credit amount": 100,
"Duration": 48,
"Purpose": "radio/TV"
}]
}
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + key}
resp = requests.post(url, json=test_data, headers=headers)
print("Prediction (good, bad):", resp.text)
A fully documented starting template for Azure Machine Leraning with MLOps can be found here: microsoft/aml-acceleration-template. This includes model training, validation, testing, deployment, pipelines, and several other production-grade capabilties.