Skip to content

csiebler/mlops-demo

Repository files navigation

mlops-demo

This repo shows some introduction examples to Azure Machine Learning and a simple MLOps implemenation for automating model training and deployment.

Setup & Demo Flow

This gives a short, high-level overview of how this repo may be used.

Interactive demo part

  1. If required, create an Azure Machine Learning workspace
  2. Create a tabular dataset from 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)
  3. Create a file dataset from 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)
  4. Clone the whole repo into a Compute Instance
  5. Walk through the following notebooks
  6. For deployment to AKS, make sure to create an AKS cluster in AML that has SSL enabled (using the Microsoft certificate)

MLOps demo part

Simple MLOps pipelines

  1. Create a new project in Azure DevOps
  2. Fork this repo or import it into Azure DevOps (so that you can make changes to the repo)
  3. Create a service connection to your Azure Machine Learning workspace and use the name aml-workspace-connection
  4. Edit pipelines/german-credit-config.yml and adapt the values to point to your workspace
  5. Import the following pipelines into DevOps
  6. Run the pipelines

Staged MLOps pipelines

  1. First, get the simple pipelines from pipelines/ running
  2. Edit pipelines-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 workspaces
  3. Import the following pipeline into DevOps
  4. Run the pipeline

Conventions

This 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...

Testing

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)

Further Work

⭐ 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.