Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Azure Machine Learning Engineering

You're reading from   Azure Machine Learning Engineering Deploy, fine-tune, and optimize ML models using Microsoft Azure

Arrow left icon
Product type Paperback
Published in Jan 2023
Publisher Packt
ISBN-13 9781803239309
Length 362 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (4):
Arrow left icon
Balamurugan Balakreshnan Balamurugan Balakreshnan
Author Profile Icon Balamurugan Balakreshnan
Balamurugan Balakreshnan
Dennis Michael Sawyers Dennis Michael Sawyers
Author Profile Icon Dennis Michael Sawyers
Dennis Michael Sawyers
Sina Fakhraee Ph.D Sina Fakhraee Ph.D
Author Profile Icon Sina Fakhraee Ph.D
Sina Fakhraee Ph.D
Megan Masanz Megan Masanz
Author Profile Icon Megan Masanz
Megan Masanz
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1: Training and Tuning Models with the Azure Machine Learning Service
2. Chapter 1: Introducing the Azure Machine Learning Service FREE CHAPTER 3. Chapter 2: Working with Data in AMLS 4. Chapter 3: Training Machine Learning Models in AMLS 5. Chapter 4: Tuning Your Models with AMLS 6. Chapter 5: Azure Automated Machine Learning 7. Part 2: Deploying and Explaining Models in AMLS
8. Chapter 6: Deploying ML Models for Real-Time Inferencing 9. Chapter 7: Deploying ML Models for Batch Scoring 10. Chapter 8: Responsible AI 11. Chapter 9: Productionizing Your Workload with MLOps 12. Part 3: Productionizing Your Workload with MLOps
13. Chapter 10: Using Deep Learning in Azure Machine Learning 14. Chapter 11: Using Distributed Training in AMLS 15. Index 16. Other Books You May Enjoy

Creating a compute for writing code

In this section, you will create a compute instance to begin your development. Each subsection will demonstrate how to create these resources in your AMLS workspace following different methods.

Creating a compute instance through the AMLS GUI

The most straightforward way to create a compute instance is through AMLS. Compute instances come in many sizes and you should adjust them to accommodate the size of your data. A good rule of thumb is that you should have 20 times the amount of RAM as the size of your data in CSV format, or 2 times the amount of RAM as the size of your data in a pandas DataFrame, the most popular Python data structure for data science. This is because, when you read in a CSV file as a pandas DataFrame, it expands the data by up to a factor of 10.

The compute name must be unique within a given Azure region, so you will need to make sure that the name of your compute resources is unique or the deployment will fail.

Now, let’s create a compute instance – a single VM-type compute that can be used for development. Each compute instance is assigned to a single user in the workspace for them to develop.

To create a compute instance, follow these steps:

  1. Log in to the AMLS workspace.
  2. Click on Compute in the left-hand menu.
  3. Click on New.

A new tab will open to configure our compute instance. The following screenshot showcases the creation of a compute instance:

Figure 1.28 – Selecting the VM type and region

Figure 1.28 – Selecting the VM type and region

Under Configure required settings, shown in Figure 1.28, let’s execute the following steps:

  1. You need to provide a name for your compute instance. Let’s name the compute instance amldevinstance. Note that the name of the compute instance will need to be unique for a given Azure region. Given that this name will likely already be used, in practice, you can provide a prefix or suffix to your compute name to ensure its uniqueness.
  2. Set Virtual machine type to CPU. GPU can also be selected for high-power deep learning models. Now, set Virtual machine size. The size allocation will display the nodes based on the quota available.
  3. Pick a VM size from the list of available CPUs.
  4. Click on Next: Advanced Settings.
  5. Turn on Enable SSH access if you want to use the compute instance from a remote machine. The Enable virtual network option is available to connect to a private network connected to a corporate network. An option to assign the compute to another user (Assign to another user) is also available. If there is any shell script to provision in the startup, please use the Provision with setup script option:
Figure 1.29 – Configure Settings

Figure 1.29 – Configure Settings

Now that we have the basic configurations provided for the compute, we can move to the next section on scheduling a time at which to shut down the instance to save money.

Adding a schedule to a compute instance

In the previous version of the AML service, data scientists had to manually spin up and shut down compute instances. Unsurprisingly, this led users to incur large bills when they forgot to shut them down over weekends and vacations. Microsoft added the ability to automatically start up and shut down compute instances in order to alleviate this problem. We recommend setting the shutdown schedule to just after your normal working hours conclude.

From Figure 1.29, click on the Add Schedule button to bring up the ability to set a start-up or shutdown automatic schedule.

Here’s the Startup and shutdown schedule window for the compute instance:

Figure 1.30 – Scheduling a shutdown for the compute instance

Figure 1.30 – Scheduling a shutdown for the compute instance

As shown in Figure 1.30, setting a schedule for the automatic shutdown of the compute will save on cost. Once scheduled, the system will automatically shut down to save money.

After setting your schedule, click on Create and wait for the instance to create. Once the instance has been created, it will automatically start and the compute instance page will be displayed.

Creating a compute instance through the Azure CLI

One major advantage of creating a compute instance with code is the ability to save your configuration file for later use.

Launch your command-line interpreter based on your OS (for example, CMD or Windows PS), connect the Azure CLI to your Azure subscription, and create a compute instance noting the name of the compute instance must be unique within an Azure Region by running the following commands:

az login
az ml compute create --name computeinstance01 --size STANDARD_D3_V2 --type ComputeInstance--resource-group my-resource-group --workspace-name my-workspace

Just as you created an AMLS workspace through the Azure CLI, you have now used it to create a compute instance. The next section will cover details on how to use ARM templates to create a compute instance.

Creating a compute instance with ARM templates

Upon creating your AMLS workspace with an ARM template, you can also instantiate compute instances at the same time, specifying their type, size, and schedule. This is an excellent strategy for large organizations that want to tightly control their compute instance configurations. It’s also great for teams who are looking to create multiple compute instances in one step. In order to do so, follow these steps:

  1. The ARM template can be downloaded from GitHub and is found here: https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.machinelearningservices/machine-learning-compute-create-computeinstance/azuredeploy.json.

The template creates a compute instance for you.

The example template has three required parameters:

  • workspaceName, which is the deployment location.
  • computeName, which is the name of the compute instance to create.
  • objectId, which is the object ID of the person to which to assign the compute instance. In your case, it will be yourself.

To get your object ID, you can run the following command:

az ad signed-in-user show
  1. To deploy your template, you must deploy it into a workspace that has already been created in a resource group that already exists. Be sure to replace objectId with the object ID you found using the az ad signed-in-user show command. Make sure your command prompt is in the location at which you downloaded the azuredeploy.json file, and run the following command:
    az deployment group create --name "exampledeployment" --resource-group "aml-dev-rg" --template-file "azuredeploy.json" --parameters workspaceName="aml-ws" computeName="devamlcompute" objectId="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" schedules="{'computeStartStop': [{'action': 'Stop','triggerType': 'Cron','cron': {'startTime': '2022-07-06T23:41:45','timeZone': 'Central Standard Time','expression': '00 20 * * 1,2,3,4,5'}}]}"

Tip

In order to create compute instances for users other than yourself, use the create on behalf option and specify a user ID.

Now you know how to create compute instances using the GUI, the Azure CLI, and ARM templates. You also know how to schedule startup and shutdown times for your compute instance, and are ready to use it to develop code, which will be the focus of the next section.

You have been reading a chapter from
Azure Machine Learning Engineering
Published in: Jan 2023
Publisher: Packt
ISBN-13: 9781803239309
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime