mirror of
https://github.com/Azure/MachineLearningNotebooks.git
synced 2025-12-20 01:27:06 -05:00
237 lines
9.1 KiB
Plaintext
237 lines
9.1 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Copyright (c) Microsoft Corporation. All rights reserved.\n",
|
|
"\n",
|
|
"Licensed under the MIT License."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 00. Installation and configuration\n",
|
|
"This notebook configures your library of notebooks to connect to an Azure Machine Learning Workspace. In this case, a library contains all of the notebooks in the current folder and any nested folders. You can configure this notebook to use an existing workspace or create a new workspace.\n",
|
|
"\n",
|
|
"## What is an Azure ML Workspace and why do I need one?\n",
|
|
"\n",
|
|
"An AML Workspace is an Azure resource that organizes and coordinates the actions of many other Azure resources to assist in executing and sharing machine learning workflows. In particular, an AML Workspace coordinates storage, databases, and compute resources providing added functionality for machine learning experimentation, operationalization, and the monitoring of operationalized models."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Prerequisites"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 1. Access Azure Subscription\n",
|
|
"\n",
|
|
"In order to create an AML Workspace, first you need access to an Azure Subscription. You can [create your own](https://azure.microsoft.com/en-us/free/) or get your existing subscription information from the [Azure portal](https://portal.azure.com).\n",
|
|
"\n",
|
|
"### 2. If you're running on your own local environment, install Azure ML SDK and other libraries\n",
|
|
"\n",
|
|
"If you are running in your own environment, follow [SDK installation instructions](https://docs.microsoft.com/azure/machine-learning/service/how-to-configure-environment). If you are running in Azure Notebooks or another Microsoft managed environment, the SDK is already installed.\n",
|
|
"\n",
|
|
"Also install following libraries to your environment. Many of the example notebooks depend on them\n",
|
|
"\n",
|
|
"```\n",
|
|
"(myenv) $ conda install -y matplotlib tqdm scikit-learn\n",
|
|
"```\n",
|
|
"\n",
|
|
"Once installation is complete, check the Azure ML SDK version:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"tags": [
|
|
"install"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import azureml.core\n",
|
|
"\n",
|
|
"print(\"SDK Version:\", azureml.core.VERSION)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 3. Make sure your subscription is registered to use ACI\n",
|
|
"Azure Machine Learning makes use of Azure Container Instance (ACI). You need to ensure your subscription has been registered to use ACI in order be able to deploy a dev/test web service. If you have run through the quickstart experience you have already performed this step. Otherwise you will need to use the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) and execute the following commands.\n",
|
|
"\n",
|
|
"```shell\n",
|
|
"# check to see if ACI is already registered\n",
|
|
"(myenv) $ az provider show -n Microsoft.ContainerInstance -o table\n",
|
|
"\n",
|
|
"# if ACI is not registered, run this command.\n",
|
|
"# note you need to be the subscription owner in order to execute this command successfully.\n",
|
|
"(myenv) $ az provider register -n Microsoft.ContainerInstance\n",
|
|
"```"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Set up your Azure Machine Learning workspace\n",
|
|
"\n",
|
|
"### Option 1: You have workspace already\n",
|
|
"If you ran the Azure Machine Learning [quickstart](https://docs.microsoft.com/en-us/azure/machine-learning/service/quickstart-get-started) in Azure Notebooks, you already have a configured workspace! You can go to your Azure Machine Learning Getting Started library, view *config.json* file, and copy-paste the values for subscription ID, resource group and workspace name below.\n",
|
|
"\n",
|
|
"If you have a workspace created another way, [these instructions](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-configure-environment#create-workspace-configuration-file) describe how to get your subscription and workspace information.\n",
|
|
"\n",
|
|
"If this cell succeeds, you're done configuring this library! Otherwise continue to follow the instructions in the rest of the notebook."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from azureml.core import Workspace\n",
|
|
"\n",
|
|
"subscription_id ='<subscription-id>'\n",
|
|
"resource_group ='<resource-group>'\n",
|
|
"workspace_name = '<workspace-name>'\n",
|
|
"\n",
|
|
"try:\n",
|
|
" ws = Workspace(subscription_id = subscription_id, resource_group = resource_group, workspace_name = workspace_name)\n",
|
|
" ws.write_config()\n",
|
|
" print('Workspace configuration succeeded. You are all set!')\n",
|
|
"except:\n",
|
|
" print('Workspace not found. Run the cells below.')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### Option 2: You don't have workspace yet\n",
|
|
"\n",
|
|
"\n",
|
|
"#### Requirements\n",
|
|
"\n",
|
|
"Inside your Azure subscription, you will need access to a _resource group_, which organizes Azure resources and provides a default region for the resources in a group. You can see what resource groups to which you have access, or create a new one in the [Azure portal](https://portal.azure.com). If you don't have a resource group, the create workspace command will create one for you using the name you provide.\n",
|
|
"\n",
|
|
"To create or access an Azure ML Workspace, you will need to import the AML library and the following information:\n",
|
|
"* A name for your workspace\n",
|
|
"* Your subscription id\n",
|
|
"* The resource group name\n",
|
|
"\n",
|
|
"**Note**: As with other Azure services, there are limits on certain resources (for eg. BatchAI cluster size) associated with the Azure Machine Learning service. Please read [this article](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-quotas) on the default limits and how to request more quota."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Supported Azure Regions\n",
|
|
"Specify a region where your workspace will be located from the list of [Azure Machine Learning regions](https://linktoregions)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"workspace_region = \"eastus2\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"subscription_id = os.environ.get(\"SUBSCRIPTION_ID\", subscription_id)\n",
|
|
"resource_group = os.environ.get(\"RESOURCE_GROUP\", resource_group)\n",
|
|
"workspace_name = os.environ.get(\"WORKSPACE_NAME\", workspace_name)\n",
|
|
"workspace_region = os.environ.get(\"WORKSPACE_REGION\", workspace_region)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Create the workspace\n",
|
|
"This cell will create an AML workspace for you in a subscription provided you have the correct permissions.\n",
|
|
"\n",
|
|
"This will fail when:\n",
|
|
"1. You do not have permission to create a workspace in the resource group\n",
|
|
"2. You do not have permission to create a resource group if it's non-existing.\n",
|
|
"2. You are not a subscription owner or contributor and no Azure ML workspaces have ever been created in this subscription\n",
|
|
"\n",
|
|
"If workspace creation fails, please work with your IT admin to provide you with the appropriate permissions or to provision the required resources."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"tags": [
|
|
"create workspace"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# import the Workspace class and check the azureml SDK version\n",
|
|
"from azureml.core import Workspace\n",
|
|
"\n",
|
|
"ws = Workspace.create(name = workspace_name,\n",
|
|
" subscription_id = subscription_id,\n",
|
|
" resource_group = resource_group, \n",
|
|
" location = workspace_region,\n",
|
|
" create_resource_group = True,\n",
|
|
" exist_ok = True)\n",
|
|
"ws.get_details()\n",
|
|
"ws.write_config()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Success!\n",
|
|
"Great, you are ready to move on to the rest of the sample notebooks."
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3.6",
|
|
"language": "python",
|
|
"name": "python36"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.6.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|