Skip to content

bstollnitz/aml_command_sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to train and deploy in Azure ML, using the Python SDK

This project shows how to train a Fashion MNIST model with an Azure ML job, and how to deploy it using an online managed endpoint. It uses the Azure ML Python SDK API, and MLflow for tracking and model representation.

Blog post

To learn more about the code in this repo, check out the accompanying blog post: https://bea.stollnitz.com/blog/aml-command/

Setup

  • You need to have an Azure subscription. You can get a free subscription to try it out.
  • Create a resource group.
  • Create a new machine learning workspace by following the "Create the workspace" section of the documentation. Keep in mind that you'll be creating a "machine learning workspace" Azure resource, not a "workspace" Azure resource, which is entirely different!
  • Install the Azure CLI by following the instructions in the documentation.
  • Install and activate the conda environment by executing the following commands:
conda env create -f environment.yml
conda activate aml_command_sdk
  • Within VS Code, go to the Command Palette clicking "Ctrl + Shift + P," type "Python: Select Interpreter," and select the environment that matches the name of this project.
  • In a terminal window, log in to Azure by executing az login --use-device-code.
  • Add a config.json file to the root of your project (or somewhere in the parent folder hierarchy) containing your Azure subscription ID, resource group, and workspace:
{
    "subscription_id": "<YOUR_SUBSCRIPTION_ID>",
    "resource_group": "<YOUR_RESOURCE_GROUP>",
    "workspace_name": "<YOUR_WORKSPACE>"
}

Train and predict locally

  • Under "Run and Debug" on VS Code's left navigation, choose the "Train locally" run configuration and press F5.
  • You can analyze the metrics logged in the "mlruns" directory with the following command:
mlflow ui
  • Navigate to the root of this repo in your terminal.
  • Make a local prediction using the trained mlflow model. You can use either csv or json files:
cd aml_command_sdk
mlflow models predict --model-uri "model" --input-path "test_data/images.csv" --content-type csv --env-manager local
mlflow models predict --model-uri "model" --input-path "test_data/images.json" --content-type json --env-manager local

Train and deploy in the cloud

Create and run the job, which outputs a model

Select the run configuration "Train in the cloud" and press F5 to train in the cloud.

Create and invoke the endpoint for the model

Select the run configuration "Create endpoint" and press F5 to create an endpoint in the cloud and invoke it.

Clean up the endpoint

Once you're done working with the endpoint, you can clean it up to avoid getting charged by selecting the "Delete endpoint" run configuration and pressing F5.

Related resources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages