Run the same training on Azure Machine Learning
In this task you'll run the same training as a job on Azure Machine Learning and see where each local piece lives in Azure.
Azure Machine Learning gives each local piece a managed home: a workspace (the project), compute (serverless or clusters that start and stop), jobs (tracked training runs, using MLflow under the hood), a model registry, and endpoints for batch and online serving. Your train.py runs almost unchanged, because Azure ML speaks MLflow.
Cost: the workspace itself is free, but creating one also creates a storage account, key vault and Application Insights, which cost pennies a month. A short training job on a small serverless CPU costs a few pence. A managed online endpoint is the expensive part: you pay for its machine every hour it exists, roughly £0.20 to £0.40 an hour for a small one (Example estimate in GBP; check the Azure pricing calculator for your region). Delete it the same day.
Example. Larkfield Group moved its demand model from a data scientist's laptop to Azure ML: the same train.py became a scheduled job on serverless compute, models went into the workspace registry, and the nightly batch ran as a batch endpoint, with nothing to keep running between jobs.
Costs money. This task creates resources that are charged while they exist. Delete them as soon as you finish.
Before you start
You need: An Azure subscription you pay for, the Azure CLI with the ml extension, and the mlops folder from earlier tasks. Time: 45 minutes.
Where to look
- Azure portal
- Azure Machine Learning
- Your workspace
- Launch studio
- Jobs, Models, Endpoints
Steps
- Get a cost estimate and decide before starting: this is the only paid task in the section.Pay-as-you-go: there is no free credit.
- Add the CLI extension and create a resource group and workspace (see Commands).
- Save
job.yml,conda.ymland.amlignorefrom Commands next to train.py and the data folder, then runaz ml job create -f job.yml --web. The studio opens on the running job. - When it finishes, open the job's Metrics and Outputs + logs: the same AUC as on your computer.
- Skip the online endpoint unless you need it; if you create one, delete it as soon as you've tested it.
- Delete the resource group to stop every charge:
az group delete -n rg-mlops-lab --yes.
Commands
# Set-up (pay-as-you-go: give yourself a cost estimate first)
az extension add -n ml
az group create -n rg-mlops-lab -l uksouth
az ml workspace create -n mlw-mlops-lab -g rg-mlops-lab
az configure --defaults group=rg-mlops-lab workspace=mlw-mlops-lab
# job.yml
$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
code: .
command: python make_data.py && python train.py --min-auc 0.75
environment:
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04
conda_file: conda.yml
display_name: delivery-late-train
experiment_name: delivery-late
# conda.yml
name: train
channels: [conda-forge]
dependencies:
- python=3.12
- pip
- pip:
- mlflow
- azureml-mlflow
- scikit-learn
- pandas
# .amlignore (so the upload skips your local environment and runs)
.venv/
mlruns/
mlflow.db
# Run it, then clean up
az ml job create -f job.yml --web
az group delete -n rg-mlops-lab --yes --no-wait
Watch out for
- Cost
- Pennies for the workspace and a short job; the online endpoint costs per hour until deleted. Delete the resource group the same day.
- Security
- Use managed identities for jobs and endpoints, and keep the workspace's storage private.
- Common mistakes
- Leaving an online endpoint running overnight, and forgetting that the workspace created other billable resources.
Clean up
Delete the whole resource group: az group delete -n rg-mlops-lab --yes --no-wait.
Words to know
- Workspace
- The Azure ML resource that holds jobs, models, data and endpoints.
- Serverless compute
- Machines Azure ML starts for a job and stops afterwards.
- Job
- A tracked run of a script on Azure ML compute.
- Managed online endpoint
- A web address Azure ML runs a model behind, billed per hour.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands On