Designing and Implementing Data Science Solutions on Microsoft Azure — Part 2
Machine Learning Operationalization (ML Ops)
DevOps is a combination of best practices for team collaboration and operational automation that helps drive efficiency in creating, deploying, and managing software solutions at enterprise scale. Often, data scientists and machine learning specialists work in relative isolation from the software developers who integrate their models into applications and the system administrators who manage the deployed application infrastructure, but by adopting some DevOps principles, these disparate teams can coordinate activities to create an effective overall solution.
Azure Machine Learning provides multiple capabilities that an organization can leverage for ML Ops, and integrates with more general DevOps tools such as Azure DevOps and GitHub. You’ll explore these capabilities in more depth in the remainder of this course.
Azure Machine Learning Workspaces
A workspace is a context for the experiments, data, compute targets, and other assets associated with a machine learning workload.
Workspaces for Machine Learning Assets
A workspace defines the boundary for a set of related machine learning assets. You can use workspaces to group machine learning assets based on projects, deployment environments (for example, test and production), teams, or some other organizing principle. The assets in a workspace include:
- Compute targets for development, training, and deployment.
- Data for experimentation and model training.
- Notebooks containing shared code and documentation.
- Experiments, including run history with logged metrics and outputs.
- Pipelines that define orchestrated multi-step processes.
- Models that you have trained.
The Azure resources created alongside a workspace include:
- A storage account — used to store files used by the workspace as well as data for experiments and model training.
- An Application Insights instance, used to monitor predictive services in the workspace.
- An Azure Key Vault instance, used to manage secrets such as authentication keys and credentials used by the workspace.
- A container registry, created as-needed to manage containers for deployed models.
Creating a Workspace
You can create a workspace in any of the following ways:
- In the Microsoft Azure portal, create a new Machine Learning resource, specifying the subscription, resource group and workspace name.
Use the Azure Machine Learning Python SDK to run code that creates a workspace. For example:
Use the Azure Command Line Interface (CLI) with the Azure Machine Learning CLI extension. For example, you could use the following command (which assumes a resource group named aml-resources has already been created):
Create an Azure resource Manager (ARM) template. For more information the ARM template format for an Azure Machine Learning workspace, see the Azure Machine Learning documentation.
Use the Azure Machine Learning REST interface, see the Azure Machine Learning documentation.
Access Controls and Permissions
As with any cloud resource, you need to ensure that only authorized users can access and work with assets in an Azure Machine Learning workspace.
Azure Machine Learning studio
You can manage the assets in your Azure Machine Learning workspace in the Azure portal, but as this is a general interface for managing all kinds of resources in Azure, data scientists and other users involved in machine learning operations may prefer to use a more focused, dedicated interface.
Azure Machine Learning studio is a web-based tool for managing an Azure Machine Learning workspace. It enables you to create, manage, and view all of the assets in your workspace and provides the following graphical tools:
- Automated ML: A wizard interface that enables you to train a model using a combination of algorithms and data preprocessing techniques to find the best model for your data.
- Designer: A drag and drop interface for “no code” machine learning model development.
To use Azure Machine Learning studio, use a a web browser to navigate to https://ml.azure.com and sign in using credentials associated with your Azure subscription. You can then select the subscription and workspace you want to manage.
The Azure Machine Learning SDK for Python
While graphical interfaces like Azure Machine Learning studio make it easy to create and manage machine learning assets, it is often advantageous to use a code-based approach to managing resources. By writing scripts to create and manage resources, you can:
- Automate asset creation and configuration to make it repeatable.
- Ensure consistency for resources that must be replicated in multiple environments (for example, development, test, and production)
- Incorporate machine learning asset configuration into developer operations (DevOps) workflows, such as continuous integration / continuous deployment (CI/CD) pipelines.
Azure Machine Learning provides software development kits (SDKs) for Python and R, which you can use to create, manage, and use assets in an Azure Machine Learning workspace
you can install the Azure Machine Learning SDK for Python by using the “pip” package management utility, as shown in the following code sample:
Connecting to a Workspace
After installing the SDK package in your Python environment, you can write code to connect to your workspace and perform machine learning operations. The easiest way to connect to a workspace is to use a workspace configuration file, which includes the Azure subscription, resource group, and workspace details as shown here:
Tip: You can download a configuration file for a workspace from the Overview page of its blade in the Azure portal or from Azure Machine Learning studio.
To connect to the workspace using the configuration file, you can use the from_config method of the Workspace class in the SDK, as shown here:
By default, the from_config method looks for a file named config.json in the folder containing the Python code file, but you can specify another path if necessary.
As an alternative to using a configuration file, you can use the get method of the Workspace class with explicitly specified subscription, resource group, and workspace details as shown here — though the configuration file technique is generally preferred due to its greater flexibility when using multiple scripts:
Working with the Workspace Class
The Workspace class is the starting point for most code operations. For example, you can use its compute_targets attribute to retrieve a dictionary object containing the compute targets defined in the workspace, like this:
The Azure Machine Learning CLI Extension
The Azure command-line interface (CLI) is a cross-platform command-line tool for managing Azure resources. The Azure Machine Learning CLI extension is an additional package that provides commands for working with Azure Machine Learning.
Installing the Azure Machine Learning CLI Extension
To install the Azure Machine Learning CLI extension, you must first install the Azure CLI. See the full installation instructions for all supported platforms for more details.
After installing the Azure CLI, you can add the Azure Machine Learning CLI extension by running the following command:
Using the Azure Machine Learning CLI Extension
To use the Azure Machine Learning CLI extension, run the az ml command with the appropriate parameters for the action you want to perform. For example, to list the compute targets in a workspace, run the following command:
Note: In the code sample above, the -g parameter specifies the name of the resource group in which the Azure Machine Learning workspace specified in the -w parameter is defined. These parameters are shortened aliases for –resource-group and –workspace-name.
The Azure Machine Learning Extension for Visual Studio Code
Visual Studio Code is a lightweight code editing environment for Microsoft Windows, Apple macOS, and Linux. It provides a visual interface for many kinds of code, including Microsoft C#, Javascript, Python and others; as well as intellisense and syntax formatting for common data formats such as JSON and XML.
Visual Studio Code’s flexibility is based on the ability to install modular extensions that add syntax checking, debugging, and visual management interfaces for specific workloads. For example, the Microsoft Python extension adds support for writing and running Python code in scripts or notebooks within the Visual Studio Code interface.
Compute Instances
Azure Machine Learning includes the ability to create Compute Instances in a workspace to provide a development environment that is managed with all of the other assets in the workspace.
Compute Instances include Jupyter Notebook and JupyterLab installations that you can use to write and run code that uses the Azure Machine Learning SDK to work with assets in your workspace.
You can choose a VM image that provides the compute specification you need, from small CPU-only VMs to large GPU-enabled workstations. Because the VMs are hosted in Azure, you only pay for the compute resources when they are running; so you can create a VM to suit your needs, and stop it when your workload has completed to minimize costs.
You can store notebooks independently in workspace storage, and open them in any VM.
I tried to explain the continuation of Module 1 in titles. The next article will continue with Module 2.
See you soon 🙂
Stay healthy :)
Best regards,
Erdem