mirror of
https://github.com/Azure/MachineLearningNotebooks.git
synced 2025-12-20 01:27:06 -05:00
Compare commits
1 Commits
master
...
release_up
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfd92b0bc9 |
@@ -103,7 +103,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import azureml.core\n",
|
"import azureml.core\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ dependencies:
|
|||||||
|
|
||||||
- pip:
|
- pip:
|
||||||
# Required packages for AzureML execution, history, and data preparation.
|
# Required packages for AzureML execution, history, and data preparation.
|
||||||
- azureml-widgets~=1.21.0
|
- azureml-widgets~=1.22.0
|
||||||
- pytorch-transformers==1.0.0
|
- pytorch-transformers==1.0.0
|
||||||
- spacy==2.1.8
|
- spacy==2.1.8
|
||||||
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
|
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
|
||||||
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.21.0/validated_win32_requirements.txt [--no-deps]
|
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.22.0/validated_win32_requirements.txt [--no-deps]
|
||||||
|
- PyJWT < 2.0.0
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ dependencies:
|
|||||||
|
|
||||||
- pip:
|
- pip:
|
||||||
# Required packages for AzureML execution, history, and data preparation.
|
# Required packages for AzureML execution, history, and data preparation.
|
||||||
- azureml-widgets~=1.21.0
|
- azureml-widgets~=1.22.0
|
||||||
- pytorch-transformers==1.0.0
|
- pytorch-transformers==1.0.0
|
||||||
- spacy==2.1.8
|
- spacy==2.1.8
|
||||||
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
|
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
|
||||||
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.21.0/validated_linux_requirements.txt [--no-deps]
|
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.22.0/validated_linux_requirements.txt [--no-deps]
|
||||||
|
- PyJWT < 2.0.0
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,9 @@ dependencies:
|
|||||||
|
|
||||||
- pip:
|
- pip:
|
||||||
# Required packages for AzureML execution, history, and data preparation.
|
# Required packages for AzureML execution, history, and data preparation.
|
||||||
- azureml-widgets~=1.21.0
|
- azureml-widgets~=1.22.0
|
||||||
- pytorch-transformers==1.0.0
|
- pytorch-transformers==1.0.0
|
||||||
- spacy==2.1.8
|
- spacy==2.1.8
|
||||||
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
|
- https://aka.ms/automl-resources/packages/en_core_web_sm-2.1.0.tar.gz
|
||||||
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.21.0/validated_darwin_requirements.txt [--no-deps]
|
- -r https://automlcesdkdataresources.blob.core.windows.net/validated-requirements/1.22.0/validated_darwin_requirements.txt [--no-deps]
|
||||||
|
- PyJWT < 2.0.0
|
||||||
|
|||||||
@@ -105,7 +105,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,4 +18,3 @@ dependencies:
|
|||||||
- azureml-sdk
|
- azureml-sdk
|
||||||
- azureml-widgets
|
- azureml-widgets
|
||||||
- azureml-explain-model
|
- azureml-explain-model
|
||||||
- PyJWT < 2.0.0
|
|
||||||
|
|||||||
@@ -19,4 +19,3 @@ dependencies:
|
|||||||
- azureml-sdk
|
- azureml-sdk
|
||||||
- azureml-widgets
|
- azureml-widgets
|
||||||
- azureml-explain-model
|
- azureml-explain-model
|
||||||
- PyJWT < 2.0.0
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -113,7 +113,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -205,6 +205,10 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"dataset = Dataset.Tabular.from_delimited_files(path = [(datastore, 'dataset/bike-no.csv')]).with_timestamp_columns(fine_grain_timestamp=time_column_name) \n",
|
"dataset = Dataset.Tabular.from_delimited_files(path = [(datastore, 'dataset/bike-no.csv')]).with_timestamp_columns(fine_grain_timestamp=time_column_name) \n",
|
||||||
|
"\n",
|
||||||
|
"# Drop the columns 'casual' and 'registered' as these columns are a breakdown of the total and therefore a leak.\n",
|
||||||
|
"dataset = dataset.drop_columns(columns=['casual', 'registered'])\n",
|
||||||
|
"\n",
|
||||||
"dataset.take(5).to_pandas_dataframe().reset_index(drop=True)"
|
"dataset.take(5).to_pandas_dataframe().reset_index(drop=True)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -251,7 +255,6 @@
|
|||||||
"|**forecast_horizon**|The forecast horizon is how many periods forward you would like to forecast. This integer horizon is in units of the timeseries frequency (e.g. daily, weekly).|\n",
|
"|**forecast_horizon**|The forecast horizon is how many periods forward you would like to forecast. This integer horizon is in units of the timeseries frequency (e.g. daily, weekly).|\n",
|
||||||
"|**country_or_region_for_holidays**|The country/region used to generate holiday features. These should be ISO 3166 two-letter country/region codes (i.e. 'US', 'GB').|\n",
|
"|**country_or_region_for_holidays**|The country/region used to generate holiday features. These should be ISO 3166 two-letter country/region codes (i.e. 'US', 'GB').|\n",
|
||||||
"|**target_lags**|The target_lags specifies how far back we will construct the lags of the target variable.|\n",
|
"|**target_lags**|The target_lags specifies how far back we will construct the lags of the target variable.|\n",
|
||||||
"|**drop_column_names**|Name(s) of columns to drop prior to modeling|\n",
|
|
||||||
"|**freq**|Forecast frequency. This optional parameter represents the period with which the forecast is desired, for example, daily, weekly, yearly, etc. Use this parameter for the correction of time series containing irregular data points or for padding of short time series. The frequency needs to be a pandas offset alias. Please refer to [pandas documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects) for more information."
|
"|**freq**|Forecast frequency. This optional parameter represents the period with which the forecast is desired, for example, daily, weekly, yearly, etc. Use this parameter for the correction of time series containing irregular data points or for padding of short time series. The frequency needs to be a pandas offset alias. Please refer to [pandas documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#dateoffset-objects) for more information."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -315,8 +318,7 @@
|
|||||||
" time_column_name=time_column_name,\n",
|
" time_column_name=time_column_name,\n",
|
||||||
" forecast_horizon=forecast_horizon,\n",
|
" forecast_horizon=forecast_horizon,\n",
|
||||||
" country_or_region_for_holidays='US', # set country_or_region will trigger holiday featurizer\n",
|
" country_or_region_for_holidays='US', # set country_or_region will trigger holiday featurizer\n",
|
||||||
" target_lags='auto', # use heuristic based lag setting \n",
|
" target_lags='auto' # use heuristic based lag setting \n",
|
||||||
" drop_column_names=['casual', 'registered'] # these columns are a breakdown of the total and therefore a leak\n",
|
|
||||||
")\n",
|
")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"automl_config = AutoMLConfig(task='forecasting', \n",
|
"automl_config = AutoMLConfig(task='forecasting', \n",
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -94,7 +94,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -82,7 +82,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -169,6 +169,10 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"time_column_name = 'WeekStarting'\n",
|
"time_column_name = 'WeekStarting'\n",
|
||||||
"data = pd.read_csv(\"dominicks_OJ.csv\", parse_dates=[time_column_name])\n",
|
"data = pd.read_csv(\"dominicks_OJ.csv\", parse_dates=[time_column_name])\n",
|
||||||
|
"\n",
|
||||||
|
"# Drop the columns 'logQuantity' as it is a leaky feature.\n",
|
||||||
|
"data.drop('logQuantity', axis=1, inplace=True)\n",
|
||||||
|
"\n",
|
||||||
"data.head()"
|
"data.head()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -343,7 +347,6 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"featurization_config = FeaturizationConfig()\n",
|
"featurization_config = FeaturizationConfig()\n",
|
||||||
"featurization_config.drop_columns = ['logQuantity'] # 'logQuantity' is a leaky feature, so we remove it.\n",
|
|
||||||
"# Force the CPWVOL5 feature to be numeric type.\n",
|
"# Force the CPWVOL5 feature to be numeric type.\n",
|
||||||
"featurization_config.add_column_purpose('CPWVOL5', 'Numeric')\n",
|
"featurization_config.add_column_purpose('CPWVOL5', 'Numeric')\n",
|
||||||
"# Fill missing values in the target column, Quantity, with zeros.\n",
|
"# Fill missing values in the target column, Quantity, with zeros.\n",
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Create trained model\n",
|
"## Create trained model\n",
|
||||||
"\n",
|
"\n",
|
||||||
"For this example, we will train a small model on scikit-learn's [diabetes dataset](https://scikit-learn.org/stable/datasets/index.html#diabetes-dataset). "
|
"For this example, we will train a small model on scikit-learn's [diabetes dataset](https://scikit-learn.org/stable/datasets/toy_dataset.html#diabetes-dataset). "
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -382,13 +382,111 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"## Update Service\n",
|
"## Update Service\n",
|
||||||
"\n",
|
"\n",
|
||||||
"If you want to change your model(s), Conda dependencies, or deployment configuration, call `update()` to rebuild the Docker image.\n",
|
"If you want to change your model(s), Conda dependencies or deployment configuration, call `update()` to rebuild the Docker image.\n"
|
||||||
"\n",
|
]
|
||||||
"```python\n",
|
},
|
||||||
"local_service.update(models=[SomeOtherModelObject],\n",
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"local_service.update(models=[model],\n",
|
||||||
" inference_config=inference_config,\n",
|
" inference_config=inference_config,\n",
|
||||||
" deployment_config=local_config)\n",
|
" deployment_config=deployment_config)\n"
|
||||||
"```"
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Deploy model to AKS cluster based on the LocalWebservice's configuration."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# This is a one time setup for AKS Cluster. You can reuse this cluster for multiple deployments after it has been created. If you delete the cluster or the resource group that contains it, then you would have to recreate it.\n",
|
||||||
|
"from azureml.core.compute import AksCompute, ComputeTarget\n",
|
||||||
|
"from azureml.core.compute_target import ComputeTargetException\n",
|
||||||
|
"\n",
|
||||||
|
"# Choose a name for your AKS cluster\n",
|
||||||
|
"aks_name = 'my-aks-9' \n",
|
||||||
|
"\n",
|
||||||
|
"# Verify the cluster does not exist already\n",
|
||||||
|
"try:\n",
|
||||||
|
" aks_target = ComputeTarget(workspace=ws, name=aks_name)\n",
|
||||||
|
" print('Found existing cluster, use it.')\n",
|
||||||
|
"except ComputeTargetException:\n",
|
||||||
|
" # Use the default configuration (can also provide parameters to customize)\n",
|
||||||
|
" prov_config = AksCompute.provisioning_configuration()\n",
|
||||||
|
"\n",
|
||||||
|
" # Create the cluster\n",
|
||||||
|
" aks_target = ComputeTarget.create(workspace = ws, \n",
|
||||||
|
" name = aks_name, \n",
|
||||||
|
" provisioning_configuration = prov_config)\n",
|
||||||
|
"\n",
|
||||||
|
"if aks_target.get_status() != \"Succeeded\":\n",
|
||||||
|
" aks_target.wait_for_completion(show_output=True)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core.webservice import AksWebservice\n",
|
||||||
|
"# Set the web service configuration (using default here)\n",
|
||||||
|
"aks_config = AksWebservice.deploy_configuration()\n",
|
||||||
|
"\n",
|
||||||
|
"# # Enable token auth and disable (key) auth on the webservice\n",
|
||||||
|
"# aks_config = AksWebservice.deploy_configuration(token_auth_enabled=True, auth_enabled=False)\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"%%time\n",
|
||||||
|
"aks_service_name ='aks-service-1'\n",
|
||||||
|
"\n",
|
||||||
|
"aks_service = local_service.deploy_to_cloud(name=aks_service_name,\n",
|
||||||
|
" deployment_config=aks_config,\n",
|
||||||
|
" deployment_target=aks_target)\n",
|
||||||
|
"\n",
|
||||||
|
"aks_service.wait_for_deployment(show_output = True)\n",
|
||||||
|
"print(aks_service.state)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Test aks service\n",
|
||||||
|
"\n",
|
||||||
|
"sample_input = json.dumps({\n",
|
||||||
|
" 'data': dataset_x[0:2].tolist()\n",
|
||||||
|
"})\n",
|
||||||
|
"\n",
|
||||||
|
"aks_service.run(sample_input)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Delete the service if not needed.\n",
|
||||||
|
"aks_service.delete()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,16 +70,16 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"import urllib.request\n",
|
"import urllib.request\n",
|
||||||
"\n",
|
"\n",
|
||||||
"onnx_model_url = \"https://www.cntk.ai/OnnxModels/emotion_ferplus/opset_7/emotion_ferplus.tar.gz\"\n",
|
"onnx_model_url = \"https://github.com/onnx/models/blob/master/vision/body_analysis/emotion_ferplus/model/emotion-ferplus-7.tar.gz?raw=true\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"urllib.request.urlretrieve(onnx_model_url, filename=\"emotion_ferplus.tar.gz\")\n",
|
"urllib.request.urlretrieve(onnx_model_url, filename=\"emotion-ferplus-7.tar.gz\")\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# the ! magic command tells our jupyter notebook kernel to run the following line of \n",
|
"# the ! magic command tells our jupyter notebook kernel to run the following line of \n",
|
||||||
"# code from the command line instead of the notebook kernel\n",
|
"# code from the command line instead of the notebook kernel\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# We use tar and xvcf to unzip the files we just retrieved from the ONNX model zoo\n",
|
"# We use tar and xvcf to unzip the files we just retrieved from the ONNX model zoo\n",
|
||||||
"\n",
|
"\n",
|
||||||
"!tar xvzf emotion_ferplus.tar.gz"
|
"!tar xvzf emotion-ferplus-7.tar.gz"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -570,7 +570,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"plt.figure(figsize = (16, 6), frameon=False)\n",
|
"plt.figure(figsize = (16, 6))\n",
|
||||||
"plt.subplot(1, 8, 1)\n",
|
"plt.subplot(1, 8, 1)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.text(x = 0, y = -30, s = \"True Label: \", fontsize = 13, color = 'black')\n",
|
"plt.text(x = 0, y = -30, s = \"True Label: \", fontsize = 13, color = 'black')\n",
|
||||||
|
|||||||
@@ -70,9 +70,9 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"import urllib.request\n",
|
"import urllib.request\n",
|
||||||
"\n",
|
"\n",
|
||||||
"onnx_model_url = \"https://www.cntk.ai/OnnxModels/mnist/opset_7/mnist.tar.gz\"\n",
|
"onnx_model_url = \"https://github.com/onnx/models/blob/master/vision/classification/mnist/model/mnist-7.tar.gz?raw=true\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"urllib.request.urlretrieve(onnx_model_url, filename=\"mnist.tar.gz\")"
|
"urllib.request.urlretrieve(onnx_model_url, filename=\"mnist-7.tar.gz\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -86,7 +86,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"# We use tar and xvcf to unzip the files we just retrieved from the ONNX model zoo\n",
|
"# We use tar and xvcf to unzip the files we just retrieved from the ONNX model zoo\n",
|
||||||
"\n",
|
"\n",
|
||||||
"!tar xvzf mnist.tar.gz"
|
"!tar xvzf mnist-7.tar.gz"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -521,7 +521,7 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"plt.figure(figsize = (16, 6), frameon=False)\n",
|
"plt.figure(figsize = (16, 6))\n",
|
||||||
"plt.subplot(1, 8, 1)\n",
|
"plt.subplot(1, 8, 1)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"plt.text(x = 0, y = -30, s = \"True Label: \", fontsize = 13, color = 'black')\n",
|
"plt.text(x = 0, y = -30, s = \"True Label: \", fontsize = 13, color = 'black')\n",
|
||||||
@@ -684,18 +684,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"A convolution layer is a set of filters. Each filter is defined by a weight (**W**) matrix, and bias ($b$).\n",
|
"A convolution layer is a set of filters. Each filter is defined by a weight (**W**) matrix, and bias ($b$).\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"These filters are scanned across the image performing the dot product between the weights and corresponding input value ($x$). The bias value is added to the output of the dot product and the resulting sum is optionally mapped through an activation function."
|
||||||
"\n",
|
|
||||||
"These filters are scanned across the image performing the dot product between the weights and corresponding input value ($x$). The bias value is added to the output of the dot product and the resulting sum is optionally mapped through an activation function. This process is illustrated in the following animation."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"Image(url=\"https://www.cntk.ai/jup/cntk103d_conv2d_final.gif\", width= 200)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -707,24 +696,6 @@
|
|||||||
"The MNIST model from the ONNX Model Zoo uses maxpooling to update the weights in its convolutions, summarized by the graphic below. You can see the entire workflow of our pre-trained model in the following image, with our input images and our output probabilities of each of our 10 labels. If you're interested in exploring the logic behind creating a Deep Learning model further, please look at the [training tutorial for our ONNX MNIST Convolutional Neural Network](https://github.com/Microsoft/CNTK/blob/master/Tutorials/CNTK_103D_MNIST_ConvolutionalNeuralNetwork.ipynb). "
|
"The MNIST model from the ONNX Model Zoo uses maxpooling to update the weights in its convolutions, summarized by the graphic below. You can see the entire workflow of our pre-trained model in the following image, with our input images and our output probabilities of each of our 10 labels. If you're interested in exploring the logic behind creating a Deep Learning model further, please look at the [training tutorial for our ONNX MNIST Convolutional Neural Network](https://github.com/Microsoft/CNTK/blob/master/Tutorials/CNTK_103D_MNIST_ConvolutionalNeuralNetwork.ipynb). "
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"#### Max-Pooling for Convolutional Neural Nets\n",
|
|
||||||
"\n",
|
|
||||||
""
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"#### Pre-Trained Model Architecture\n",
|
|
||||||
"\n",
|
|
||||||
""
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": null,
|
"execution_count": null,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ These notebooks below are designed to go in sequence.
|
|||||||
4. [aml-pipelines-data-transfer.ipynb](https://aka.ms/pl-data-trans): This notebook shows how you transfer data between supported datastores.
|
4. [aml-pipelines-data-transfer.ipynb](https://aka.ms/pl-data-trans): This notebook shows how you transfer data between supported datastores.
|
||||||
5. [aml-pipelines-use-databricks-as-compute-target.ipynb](https://aka.ms/pl-databricks): This notebooks shows how you can use Pipelines to send your compute payload to Azure Databricks.
|
5. [aml-pipelines-use-databricks-as-compute-target.ipynb](https://aka.ms/pl-databricks): This notebooks shows how you can use Pipelines to send your compute payload to Azure Databricks.
|
||||||
6. [aml-pipelines-use-adla-as-compute-target.ipynb](https://aka.ms/pl-adla): This notebook shows how you can use Azure Data Lake Analytics (ADLA) as a compute target.
|
6. [aml-pipelines-use-adla-as-compute-target.ipynb](https://aka.ms/pl-adla): This notebook shows how you can use Azure Data Lake Analytics (ADLA) as a compute target.
|
||||||
7. [aml-pipelines-how-to-use-estimatorstep.ipynb](https://aka.ms/pl-estimator): This notebook shows how to use the EstimatorStep.
|
7. [aml-pipelines-with-commandstep.ipynb](aml-pipelines-with-commandstep.ipynb): This notebook shows how to use the CommandStep.
|
||||||
8. [aml-pipelines-parameter-tuning-with-hyperdrive.ipynb](https://aka.ms/pl-hyperdrive): HyperDriveStep in Pipelines shows how you can do hyper parameter tuning using Pipelines.
|
8. [aml-pipelines-parameter-tuning-with-hyperdrive.ipynb](https://aka.ms/pl-hyperdrive): HyperDriveStep in Pipelines shows how you can do hyper parameter tuning using Pipelines.
|
||||||
9. [aml-pipelines-how-to-use-azurebatch-to-run-a-windows-executable.ipynb](https://aka.ms/pl-azbatch): AzureBatchStep can be used to run your custom code in AzureBatch cluster.
|
9. [aml-pipelines-how-to-use-azurebatch-to-run-a-windows-executable.ipynb](https://aka.ms/pl-azbatch): AzureBatchStep can be used to run your custom code in AzureBatch cluster.
|
||||||
10. [aml-pipelines-setup-schedule-for-a-published-pipeline.ipynb](https://aka.ms/pl-schedule): Once you publish a Pipeline, you can schedule it to trigger based on an interval or on data change in a defined datastore.
|
10. [aml-pipelines-setup-schedule-for-a-published-pipeline.ipynb](https://aka.ms/pl-schedule): Once you publish a Pipeline, you can schedule it to trigger based on an interval or on data change in a defined datastore.
|
||||||
@@ -19,5 +19,6 @@ These notebooks below are designed to go in sequence.
|
|||||||
14. [aml-pipelines-how-to-use-pipeline-drafts.ipynb](http://aka.ms/pl-pl-draft): This notebook shows how to use Pipeline Drafts. Pipeline Drafts are mutable pipelines which can be used to submit runs and create Published Pipelines.
|
14. [aml-pipelines-how-to-use-pipeline-drafts.ipynb](http://aka.ms/pl-pl-draft): This notebook shows how to use Pipeline Drafts. Pipeline Drafts are mutable pipelines which can be used to submit runs and create Published Pipelines.
|
||||||
15. [aml-pipelines-hot-to-use-modulestep.ipynb](https://aka.ms/pl-modulestep): This notebook shows how to define Module, ModuleVersion and how to use them in an AML Pipeline using ModuleStep.
|
15. [aml-pipelines-hot-to-use-modulestep.ipynb](https://aka.ms/pl-modulestep): This notebook shows how to define Module, ModuleVersion and how to use them in an AML Pipeline using ModuleStep.
|
||||||
16. [aml-pipelines-with-notebook-runner-step.ipynb](https://aka.ms/pl-nbrstep): This notebook shows how you can run another notebook as a step in Azure Machine Learning Pipeline.
|
16. [aml-pipelines-with-notebook-runner-step.ipynb](https://aka.ms/pl-nbrstep): This notebook shows how you can run another notebook as a step in Azure Machine Learning Pipeline.
|
||||||
|
17. [aml-pipelines-with-commandstep-r.ipynb](aml-pipelines-with-commandstep-r.ipynb): This notebook shows how to use CommandStep to run R scripts.
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
"# Azure Machine Learning Pipeline with DataTransferStep\n",
|
"# Azure Machine Learning Pipeline with DataTransferStep\n",
|
||||||
"This notebook is used to demonstrate the use of DataTransferStep in an Azure Machine Learning Pipeline.\n",
|
"This notebook is used to demonstrate the use of DataTransferStep in an Azure Machine Learning Pipeline.\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
"> **Note:** In Azure Machine Learning, you can write output data directly to Azure Blob Storage, Azure Data Lake Storage Gen 1, Azure Data Lake Storage Gen 2, Azure FileShare without going through extra DataTransferStep. Learn how to use [OutputFileDatasetConfig](https://docs.microsoft.com/python/api/azureml-core/azureml.data.output_dataset_config.outputfiledatasetconfig?view=azure-ml-py) to achieve that with sample notebooks [here](https://aka.ms/pipeline-with-dataset).**\n",
|
||||||
|
"\n",
|
||||||
"In certain cases, you will need to transfer data from one data location to another. For example, your data may be in Azure SQL Database and you may want to move it to Azure Data Lake storage. Or, your data is in an ADLS account and you want to make it available in the Blob storage. The built-in **DataTransferStep** class helps you transfer data in these situations.\n",
|
"In certain cases, you will need to transfer data from one data location to another. For example, your data may be in Azure SQL Database and you may want to move it to Azure Data Lake storage. Or, your data is in an ADLS account and you want to make it available in the Blob storage. The built-in **DataTransferStep** class helps you transfer data in these situations.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"The below examples show how to move data between different storage types supported in Azure Machine Learning.\n",
|
"The below examples show how to move data between different storage types supported in Azure Machine Learning.\n",
|
||||||
|
|||||||
@@ -41,14 +41,14 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import azureml.core\n",
|
"import azureml.core\n",
|
||||||
"from azureml.core import Workspace, Datastore, Experiment, Dataset\n",
|
"from azureml.core import Workspace, Datastore, Experiment, Dataset\n",
|
||||||
|
"from azureml.data import OutputFileDatasetConfig\n",
|
||||||
"from azureml.core.compute import AmlCompute\n",
|
"from azureml.core.compute import AmlCompute\n",
|
||||||
"from azureml.core.compute import ComputeTarget\n",
|
"from azureml.core.compute import ComputeTarget\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# Check core SDK version number\n",
|
"# Check core SDK version number\n",
|
||||||
"print(\"SDK version:\", azureml.core.VERSION)\n",
|
"print(\"SDK version:\", azureml.core.VERSION)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"from azureml.data.data_reference import DataReference\n",
|
"from azureml.pipeline.core import Pipeline\n",
|
||||||
"from azureml.pipeline.core import Pipeline, PipelineData\n",
|
|
||||||
"from azureml.pipeline.steps import PythonScriptStep\n",
|
"from azureml.pipeline.steps import PythonScriptStep\n",
|
||||||
"from azureml.pipeline.core.graph import PipelineParameter\n",
|
"from azureml.pipeline.core.graph import PipelineParameter\n",
|
||||||
"\n",
|
"\n",
|
||||||
@@ -140,9 +140,9 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Define intermediate data using PipelineData\n",
|
"# Define intermediate data using OutputFileDatasetConfig\n",
|
||||||
"processed_data1 = PipelineData(\"processed_data1\",datastore=def_blob_store)\n",
|
"processed_data1 = OutputFileDatasetConfig(name=\"processed_data1\")\n",
|
||||||
"print(\"PipelineData object created\")"
|
"print(\"Output dataset object created\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -170,9 +170,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"trainStep = PythonScriptStep(\n",
|
"trainStep = PythonScriptStep(\n",
|
||||||
" script_name=\"train.py\", \n",
|
" script_name=\"train.py\", \n",
|
||||||
" arguments=[\"--input_data\", blob_input_data, \"--output_train\", processed_data1],\n",
|
" arguments=[\"--input_data\", blob_input_data.as_mount(), \"--output_train\", processed_data1],\n",
|
||||||
" inputs=[blob_input_data],\n",
|
|
||||||
" outputs=[processed_data1],\n",
|
|
||||||
" compute_target=aml_compute, \n",
|
" compute_target=aml_compute, \n",
|
||||||
" source_directory=source_directory\n",
|
" source_directory=source_directory\n",
|
||||||
")\n",
|
")\n",
|
||||||
@@ -195,16 +193,14 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# extractStep to use the intermediate data produced by step4\n",
|
"# extractStep to use the intermediate data produced by trainStep\n",
|
||||||
"# This step also produces an output processed_data2\n",
|
"# This step also produces an output processed_data2\n",
|
||||||
"processed_data2 = PipelineData(\"processed_data2\", datastore=def_blob_store)\n",
|
"processed_data2 = OutputFileDatasetConfig(name=\"processed_data2\")\n",
|
||||||
"source_directory = \"publish_run_extract\"\n",
|
"source_directory = \"publish_run_extract\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"extractStep = PythonScriptStep(\n",
|
"extractStep = PythonScriptStep(\n",
|
||||||
" script_name=\"extract.py\",\n",
|
" script_name=\"extract.py\",\n",
|
||||||
" arguments=[\"--input_extract\", processed_data1, \"--output_extract\", processed_data2],\n",
|
" arguments=[\"--input_extract\", processed_data1.as_input(), \"--output_extract\", processed_data2],\n",
|
||||||
" inputs=[processed_data1],\n",
|
|
||||||
" outputs=[processed_data2],\n",
|
|
||||||
" compute_target=aml_compute, \n",
|
" compute_target=aml_compute, \n",
|
||||||
" source_directory=source_directory)\n",
|
" source_directory=source_directory)\n",
|
||||||
"print(\"extractStep created\")"
|
"print(\"extractStep created\")"
|
||||||
@@ -256,15 +252,17 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# Now define step6 that takes two inputs (both intermediate data), and produce an output\n",
|
"# Now define compareStep that takes two inputs (both intermediate data), and produce an output\n",
|
||||||
"processed_data3 = PipelineData(\"processed_data3\", datastore=def_blob_store)\n",
|
"processed_data3 = OutputFileDatasetConfig(name=\"processed_data3\")\n",
|
||||||
|
"\n",
|
||||||
|
"# You can register the output as dataset after job completion\n",
|
||||||
|
"processed_data3 = processed_data3.register_on_complete(\"compare_result\")\n",
|
||||||
|
"\n",
|
||||||
"source_directory = \"publish_run_compare\"\n",
|
"source_directory = \"publish_run_compare\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"compareStep = PythonScriptStep(\n",
|
"compareStep = PythonScriptStep(\n",
|
||||||
" script_name=\"compare.py\",\n",
|
" script_name=\"compare.py\",\n",
|
||||||
" arguments=[\"--compare_data1\", processed_data1, \"--compare_data2\", processed_data2, \"--output_compare\", processed_data3, \"--pipeline_param\", pipeline_param],\n",
|
" arguments=[\"--compare_data1\", processed_data1.as_input(), \"--compare_data2\", processed_data2.as_input(), \"--output_compare\", processed_data3, \"--pipeline_param\", pipeline_param], \n",
|
||||||
" inputs=[processed_data1, processed_data2],\n",
|
|
||||||
" outputs=[processed_data3], \n",
|
|
||||||
" compute_target=aml_compute, \n",
|
" compute_target=aml_compute, \n",
|
||||||
" source_directory=source_directory)\n",
|
" source_directory=source_directory)\n",
|
||||||
"print(\"compareStep created\")"
|
"print(\"compareStep created\")"
|
||||||
|
|||||||
@@ -0,0 +1,343 @@
|
|||||||
|
{
|
||||||
|
"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": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"# How to use CommandStep in Azure ML Pipelines\n",
|
||||||
|
"\n",
|
||||||
|
"This notebook shows how to use the CommandStep with Azure Machine Learning Pipelines for running R scripts in a pipeline.\n",
|
||||||
|
"\n",
|
||||||
|
"The example shows training a model in R to predict probability of fatality for vehicle crashes.\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"## Prerequisite:\n",
|
||||||
|
"* Understand the [architecture and terms](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture) introduced by Azure Machine Learning\n",
|
||||||
|
"* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [configuration notebook](https://aka.ms/pl-config) to:\n",
|
||||||
|
" * install the Azure ML SDK\n",
|
||||||
|
" * create a workspace and its configuration file (`config.json`)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Let's get started. First let's import some Python libraries."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import azureml.core\n",
|
||||||
|
"# check core SDK version number\n",
|
||||||
|
"print(\"Azure ML SDK Version: \", azureml.core.VERSION)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Initialize workspace\n",
|
||||||
|
"Initialize a [Workspace](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#workspace) object from the existing workspace you created in the Prerequisites step. `Workspace.from_config()` creates a workspace object from the details stored in `config.json`."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core import Workspace\n",
|
||||||
|
"ws = Workspace.from_config()\n",
|
||||||
|
"print('Workspace name: ' + ws.name, \n",
|
||||||
|
" 'Azure region: ' + ws.location, \n",
|
||||||
|
" 'Subscription id: ' + ws.subscription_id, \n",
|
||||||
|
" 'Resource group: ' + ws.resource_group, sep = '\\n')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Create or Attach existing AmlCompute\n",
|
||||||
|
"You will need to create a [compute target](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture#compute-target) for training your model. In this tutorial, you create `AmlCompute` as your training compute resource."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"If we could not find the cluster with the given name, then we will create a new cluster here. We will create an `AmlCompute` cluster of `STANDARD_D2_V2` CPU VMs. This process is broken down into 3 steps:\n",
|
||||||
|
"1. create the configuration (this step is local and only takes a second)\n",
|
||||||
|
"2. create the cluster (this step will take about **20 seconds**)\n",
|
||||||
|
"3. provision the VMs to bring the cluster to the initial size (of 1 in this case). This step will take about **3-5 minutes** and is providing only sparse output in the process. Please make sure to wait until the call returns before moving to the next cell"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core.compute import ComputeTarget, AmlCompute\n",
|
||||||
|
"from azureml.core.compute_target import ComputeTargetException\n",
|
||||||
|
"\n",
|
||||||
|
"# choose a name for your cluster\n",
|
||||||
|
"cluster_name = \"cpu-cluster\"\n",
|
||||||
|
"\n",
|
||||||
|
"try:\n",
|
||||||
|
" compute_target = ComputeTarget(workspace=ws, name=cluster_name)\n",
|
||||||
|
" print('Found existing compute target')\n",
|
||||||
|
"except ComputeTargetException:\n",
|
||||||
|
" print('Creating a new compute target...')\n",
|
||||||
|
" compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_D2_V2', max_nodes=4)\n",
|
||||||
|
"\n",
|
||||||
|
" # create the cluster\n",
|
||||||
|
" compute_target = ComputeTarget.create(ws, cluster_name, compute_config)\n",
|
||||||
|
"\n",
|
||||||
|
" # can poll for a minimum number of nodes and for a specific timeout. \n",
|
||||||
|
" # if no min node count is provided it uses the scale settings for the cluster\n",
|
||||||
|
" compute_target.wait_for_completion(show_output=True, min_node_count=None, timeout_in_minutes=20)\n",
|
||||||
|
"\n",
|
||||||
|
"# use get_status() to get a detailed status for the current cluster. \n",
|
||||||
|
"print(compute_target.get_status().serialize())"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Now that you have created the compute target, let's see what the workspace's `compute_targets` property returns. You should now see one entry named 'cpu-cluster' of type `AmlCompute`."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Create a CommandStep\n",
|
||||||
|
"CommandStep adds a step to run a command in a Pipeline. For the full set of configurable options see the CommandStep [reference docs](https://docs.microsoft.com/python/api/azureml-pipeline-steps/azureml.pipeline.steps.commandstep?view=azure-ml-py).\n",
|
||||||
|
"\n",
|
||||||
|
"- **name:** Name of the step\n",
|
||||||
|
"- **runconfig:** ScriptRunConfig object. You can configure a ScriptRunConfig object as you would for a standalone non-pipeline run and pass it in to this parameter. If using this option, you do not have to specify the `command`, `source_directory`, `compute_target` parameters of the CommandStep constructor as they are already defined in your ScriptRunConfig.\n",
|
||||||
|
"- **runconfig_pipeline_params:** Override runconfig properties at runtime using key-value pairs each with name of the runconfig property and PipelineParameter for that property\n",
|
||||||
|
"- **command:** The command to run or path of the executable/script relative to `source_directory`. It is required unless the `runconfig` parameter is specified. It can be specified with string arguments in a single string or with input/output/PipelineParameter in a list.\n",
|
||||||
|
"- **source_directory:** A folder containing the script and other resources used in the step.\n",
|
||||||
|
"- **compute_target:** Compute target to use \n",
|
||||||
|
"- **allow_reuse:** Whether the step should reuse previous results when run with the same settings/inputs. If this is false, a new run will always be generated for this step during pipeline execution.\n",
|
||||||
|
"- **version:** Optional version tag to denote a change in functionality for the step\n",
|
||||||
|
"\n",
|
||||||
|
"> The best practice is to use separate folders for scripts and its dependent files for each step and specify that folder as the `source_directory` for the step. This helps reduce the size of the snapshot created for the step (only the specific folder is snapshotted). Since changes in any files in the `source_directory` would trigger a re-upload of the snapshot, this helps keep the reuse of the step when there are no changes in the `source_directory` of the step."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### Configure environment\n",
|
||||||
|
"\n",
|
||||||
|
"Configure the environment for the train step. In this example we will create an environment from the Dockerfile we have included.\n",
|
||||||
|
"\n",
|
||||||
|
"> Azure ML currently requires Python as an implicit dependency, so Python must installed in your image even if your training script does not have this dependency."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core import Environment\n",
|
||||||
|
"import os\n",
|
||||||
|
"\n",
|
||||||
|
"src_dir = 'commandstep_r'\n",
|
||||||
|
"\n",
|
||||||
|
"env = Environment.from_dockerfile(name='r_env', dockerfile=os.path.join(src_dir, 'Dockerfile'))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### Configure input training dataset\n",
|
||||||
|
"\n",
|
||||||
|
"This tutorial uses data from the US National Highway Traffic Safety Administration. This dataset includes data from over 25,000 car crashes in the US, with variables you can use to predict the likelihood of a fatality. We have included an Rdata file that includes the accidents data for analysis.\n",
|
||||||
|
"\n",
|
||||||
|
"Here we use the workspace's default datastore to upload the training data file (**accidents.Rd**); in practice you can use any datastore you want."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"datastore = ws.get_default_datastore()\n",
|
||||||
|
"data_ref = datastore.upload_files(files=[os.path.join(src_dir, 'accidents.Rd')], target_path='accidentdata')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Now create a FileDataset from the data, which will be used as an input to the train step."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core import Dataset\n",
|
||||||
|
"dataset = Dataset.File.from_files(datastore.path('accidentdata'))\n",
|
||||||
|
"dataset"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Now create a ScriptRunConfig that configures the training run. Note that in the `command` we include the input dataset for the training data.\n",
|
||||||
|
"\n",
|
||||||
|
"> For detailed guidance on how to move data in pipelines for input and output data, see the documentation [Moving data into and between ML pipelines](https://docs.microsoft.com/azure/machine-learning/how-to-move-data-in-out-of-pipelines)."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core import ScriptRunConfig\n",
|
||||||
|
"\n",
|
||||||
|
"train_config = ScriptRunConfig(source_directory=src_dir,\n",
|
||||||
|
" command=['Rscript accidents.R --data_folder', dataset.as_mount(), '--output_folder outputs'],\n",
|
||||||
|
" compute_target=compute_target,\n",
|
||||||
|
" environment=env)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Now create a CommandStep and pass in the ScriptRunConfig object to the `runconfig` parameter."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.pipeline.steps import CommandStep\n",
|
||||||
|
"\n",
|
||||||
|
"train = CommandStep(name='train', runconfig=train_config)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Build and Submit the Pipeline"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.pipeline.core import Pipeline\n",
|
||||||
|
"from azureml.core import Experiment\n",
|
||||||
|
"\n",
|
||||||
|
"pipeline = Pipeline(workspace=ws, steps=[train])\n",
|
||||||
|
"pipeline_run = Experiment(ws, 'r-commandstep-pipeline').submit(pipeline)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## View Run Details"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.widgets import RunDetails\n",
|
||||||
|
"RunDetails(pipeline_run).show()"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "minxia"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"category": "tutorial",
|
||||||
|
"compute": [
|
||||||
|
"AML Compute"
|
||||||
|
],
|
||||||
|
"datasets": [
|
||||||
|
"Custom"
|
||||||
|
],
|
||||||
|
"deployment": [
|
||||||
|
"None"
|
||||||
|
],
|
||||||
|
"exclude_from_index": false,
|
||||||
|
"framework": [
|
||||||
|
"Azure ML"
|
||||||
|
],
|
||||||
|
"friendly_name": "Azure Machine Learning Pipeline with CommandStep for R",
|
||||||
|
"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.7.7"
|
||||||
|
},
|
||||||
|
"order_index": 7,
|
||||||
|
"star_tag": [
|
||||||
|
"None"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"None"
|
||||||
|
],
|
||||||
|
"task": "Demonstrates the use of CommandStep for running R scripts"
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 2
|
||||||
|
}
|
||||||
@@ -20,15 +20,15 @@
|
|||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# How to use EstimatorStep in AML Pipeline\n",
|
"# How to use CommandStep in Azure ML Pipelines\n",
|
||||||
"\n",
|
"\n",
|
||||||
"This notebook shows how to use the EstimatorStep with Azure Machine Learning Pipelines. Estimator is a convenient object in Azure Machine Learning that wraps run configuration information to help simplify the tasks of specifying how a script is executed.\n",
|
"This notebook shows how to use the CommandStep with Azure Machine Learning Pipelines for running commands in steps. The example shows running distributed TensorFlow training from within a pipeline.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"## Prerequisite:\n",
|
"## Prerequisite:\n",
|
||||||
"* Understand the [architecture and terms](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture) introduced by Azure Machine Learning\n",
|
"* Understand the [architecture and terms](https://docs.microsoft.com/azure/machine-learning/service/concept-azure-machine-learning-architecture) introduced by Azure Machine Learning\n",
|
||||||
"* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [configuration notebook](https://aka.ms/pl-config) to:\n",
|
"* If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the [configuration notebook](https://aka.ms/pl-config) to:\n",
|
||||||
" * install the AML SDK\n",
|
" * install the Azure ML SDK\n",
|
||||||
" * create a workspace and its configuration file (`config.json`)"
|
" * create a workspace and its configuration file (`config.json`)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -100,75 +100,57 @@
|
|||||||
"from azureml.core.compute_target import ComputeTargetException\n",
|
"from azureml.core.compute_target import ComputeTargetException\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# choose a name for your cluster\n",
|
"# choose a name for your cluster\n",
|
||||||
"cluster_name = \"amlcomp\"\n",
|
"cluster_name = \"gpu-cluster\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"try:\n",
|
"try:\n",
|
||||||
" cpu_cluster = ComputeTarget(workspace=ws, name=cluster_name)\n",
|
" gpu_cluster = ComputeTarget(workspace=ws, name=cluster_name)\n",
|
||||||
" print('Found existing compute target')\n",
|
" print('Found existing compute target')\n",
|
||||||
"except ComputeTargetException:\n",
|
"except ComputeTargetException:\n",
|
||||||
" print('Creating a new compute target...')\n",
|
" print('Creating a new compute target...')\n",
|
||||||
" compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_NC6', max_nodes=4)\n",
|
" compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_NC6', max_nodes=4)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # create the cluster\n",
|
" # create the cluster\n",
|
||||||
" cpu_cluster = ComputeTarget.create(ws, cluster_name, compute_config)\n",
|
" gpu_cluster = ComputeTarget.create(ws, cluster_name, compute_config)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" # can poll for a minimum number of nodes and for a specific timeout. \n",
|
" # can poll for a minimum number of nodes and for a specific timeout. \n",
|
||||||
" # if no min node count is provided it uses the scale settings for the cluster\n",
|
" # if no min node count is provided it uses the scale settings for the cluster\n",
|
||||||
" cpu_cluster.wait_for_completion(show_output=True, min_node_count=None, timeout_in_minutes=20)\n",
|
" gpu_cluster.wait_for_completion(show_output=True, min_node_count=None, timeout_in_minutes=20)\n",
|
||||||
"\n",
|
"\n",
|
||||||
"# use get_status() to get a detailed status for the current cluster. \n",
|
"# use get_status() to get a detailed status for the current cluster. \n",
|
||||||
"print(cpu_cluster.get_status().serialize())"
|
"print(gpu_cluster.get_status().serialize())"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Now that you have created the compute target, let's see what the workspace's `compute_targets` property returns. You should now see one entry named 'cpu-cluster' of type `AmlCompute`."
|
"Now that you have created the compute target, let's see what the workspace's `compute_targets` property returns. You should now see one entry named 'gpu-cluster' of type `AmlCompute`."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Use a simple script\n",
|
"## Create a CommandStep\n",
|
||||||
"We have already created a simple \"hello world\" script. This is the script that we will submit through the estimator pattern. It prints a hello-world message, and if Azure ML SDK is installed, it will also logs an array of values ([Fibonacci numbers](https://en.wikipedia.org/wiki/Fibonacci_number))."
|
"CommandStep adds a step to run a command in a Pipeline. For the full set of configurable options see the CommandStep [reference docs](https://docs.microsoft.com/python/api/azureml-pipeline-steps/azureml.pipeline.steps.commandstep?view=azure-ml-py).\n",
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## Build an Estimator object\n",
|
|
||||||
"Estimator by default will attempt to use Docker-based execution. You can also enable Docker and let estimator pick the default CPU image supplied by Azure ML for execution. You can target an AmlCompute cluster (or any other supported compute target types). You can also customize the conda environment by adding conda and/or pip packages.\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"> Note: The arguments to the entry script used in the Estimator object should be specified as *list* using\n",
|
"- **name:** Name of the step\n",
|
||||||
" 'estimator_entry_script_arguments' parameter when instantiating EstimatorStep. Estimator object's parameter\n",
|
"- **runconfig:** ScriptRunConfig object. You can configure a ScriptRunConfig object as you would for a standalone non-pipeline run and pass it in to this parameter. If using this option, you do not have to specify the `command`, `source_directory`, `compute_target` parameters of the CommandStep constructor as they are already defined in your ScriptRunConfig.\n",
|
||||||
" 'script_params' accepts a dictionary. However 'estimator_entry_script_arguments' parameter expects arguments as\n",
|
"- **runconfig_pipeline_params:** Override runconfig properties at runtime using key-value pairs each with name of the runconfig property and PipelineParameter for that property\n",
|
||||||
" a list.\n",
|
"- **command:** The command to run or path of the executable/script relative to `source_directory`. It is required unless the `runconfig` parameter is specified. It can be specified with string arguments in a single string or with input/output/PipelineParameter in a list.\n",
|
||||||
|
"- **source_directory:** A folder containing the script and other resources used in the step.\n",
|
||||||
|
"- **compute_target:** Compute target to use \n",
|
||||||
|
"- **allow_reuse:** Whether the step should reuse previous results when run with the same settings/inputs. If this is false, a new run will always be generated for this step during pipeline execution.\n",
|
||||||
|
"- **version:** Optional version tag to denote a change in functionality for the step\n",
|
||||||
"\n",
|
"\n",
|
||||||
"> Estimator object initialization involves specifying a list of data input and output.\n",
|
|
||||||
" In Pipelines, a step can take another step's output as input. So when creating an EstimatorStep.\n",
|
|
||||||
" \n",
|
|
||||||
"> The best practice is to use separate folders for scripts and its dependent files for each step and specify that folder as the `source_directory` for the step. This helps reduce the size of the snapshot created for the step (only the specific folder is snapshotted). Since changes in any files in the `source_directory` would trigger a re-upload of the snapshot, this helps keep the reuse of the step when there are no changes in the `source_directory` of the step."
|
"> The best practice is to use separate folders for scripts and its dependent files for each step and specify that folder as the `source_directory` for the step. This helps reduce the size of the snapshot created for the step (only the specific folder is snapshotted). Since changes in any files in the `source_directory` would trigger a re-upload of the snapshot, this helps keep the reuse of the step when there are no changes in the `source_directory` of the step."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "markdown",
|
||||||
"execution_count": null,
|
"metadata": {},
|
||||||
"metadata": {
|
|
||||||
"tags": [
|
|
||||||
"datareference-remarks-sample"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
"source": [
|
||||||
"from azureml.core import Datastore\n",
|
"First define the environment that you want to step to run in. This example users a curated TensorFlow environment, but in practice you can configure any environment you want."
|
||||||
"\n",
|
|
||||||
"def_blob_store = Datastore(ws, \"workspaceblobstore\")\n",
|
|
||||||
"\n",
|
|
||||||
"#upload input data to workspaceblobstore\n",
|
|
||||||
"def_blob_store.upload_files(files=['20news.pkl'], target_path='20newsgroups', overwrite=True)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -177,46 +159,46 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from azureml.core import Dataset\n",
|
"from azureml.core import Environment\n",
|
||||||
"from azureml.data import OutputFileDatasetConfig\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"# create dataset to be used as the input to estimator step\n",
|
"tf_env = Environment.get(ws, name='AzureML-TensorFlow-2.3-GPU')"
|
||||||
"input_data = Dataset.File.from_files(def_blob_store.path('20newsgroups/20news.pkl'))\n",
|
|
||||||
"\n",
|
|
||||||
"# OutputFileDatasetConfig by default write output to the default workspaceblobstore\n",
|
|
||||||
"output = OutputFileDatasetConfig()\n",
|
|
||||||
"\n",
|
|
||||||
"source_directory = 'estimator_train'"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"from azureml.train.estimator import Estimator\n",
|
|
||||||
"\n",
|
|
||||||
"est = Estimator(source_directory=source_directory, \n",
|
|
||||||
" compute_target=cpu_cluster, \n",
|
|
||||||
" entry_script='dummy_train.py', \n",
|
|
||||||
" conda_packages=['scikit-learn'])"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Create an EstimatorStep\n",
|
"This example will first create a ScriptRunConfig object that configures the training job. Since we are running a distributed job, specify the `distributed_job_config` parameter. If you are just running a single-node job, omit that parameter.\n",
|
||||||
"[EstimatorStep](https://docs.microsoft.com/en-us/python/api/azureml-pipeline-steps/azureml.pipeline.steps.estimator_step.estimatorstep?view=azure-ml-py) adds a step to run Estimator in a Pipeline.\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"- **name:** Name of the step\n",
|
"> If you have an input dataset you want to use in this step, you can specify that as part of the command. For example, if you have a FileDataset object called `dataset` and a `--data-dir` script argument, you can do the following: `command=['python train.py --epochs 30 --data-dir', dataset.as_mount()]`.\n",
|
||||||
"- **estimator:** Estimator object\n",
|
"\n",
|
||||||
"- **estimator_entry_script_arguments:** A list of command-line arguments\n",
|
"> For detailed guidance on how to move data in pipelines for input and output data, see the documentation [Moving data into and between ML pipelines](https://docs.microsoft.com/azure/machine-learning/how-to-move-data-in-out-of-pipelines)."
|
||||||
"- **runconfig_pipeline_params:** Override runconfig properties at runtime using key-value pairs each with name of the runconfig property and PipelineParameter for that property\n",
|
]
|
||||||
"- **compute_target:** Compute target to use \n",
|
},
|
||||||
"- **allow_reuse:** Whether the step should reuse previous results when run with the same settings/inputs. If this is false, a new run will always be generated for this step during pipeline execution.\n",
|
{
|
||||||
"- **version:** Optional version tag to denote a change in functionality for the step"
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core import ScriptRunConfig\n",
|
||||||
|
"from azureml.core.runconfig import MpiConfiguration\n",
|
||||||
|
"\n",
|
||||||
|
"src_dir = 'commandstep_train'\n",
|
||||||
|
"distr_config = MpiConfiguration(node_count=2) # you can also specify the process_count_per_node parameter for multi-process-per-node training\n",
|
||||||
|
"\n",
|
||||||
|
"src = ScriptRunConfig(source_directory=src_dir,\n",
|
||||||
|
" command=['python train.py --epochs 30'],\n",
|
||||||
|
" compute_target=gpu_cluster,\n",
|
||||||
|
" environment=tf_env,\n",
|
||||||
|
" distributed_job_config=distr_config)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Now create a CommandStep and pass in the ScriptRunConfig object to the `runconfig` parameter."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -229,20 +211,16 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from azureml.pipeline.steps import EstimatorStep\n",
|
"from azureml.pipeline.steps import CommandStep\n",
|
||||||
"\n",
|
"\n",
|
||||||
"est_step = EstimatorStep(name=\"Estimator_Train\", \n",
|
"train = CommandStep(name='train-mnist', runconfig=src)"
|
||||||
" estimator=est, \n",
|
|
||||||
" estimator_entry_script_arguments=[\"--datadir\", input_data.as_mount(), \"--output\", output],\n",
|
|
||||||
" runconfig_pipeline_params=None, \n",
|
|
||||||
" compute_target=cpu_cluster)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"## Build and Submit the Experiment"
|
"## Build and Submit the Pipeline"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -253,8 +231,9 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from azureml.pipeline.core import Pipeline\n",
|
"from azureml.pipeline.core import Pipeline\n",
|
||||||
"from azureml.core import Experiment\n",
|
"from azureml.core import Experiment\n",
|
||||||
"pipeline = Pipeline(workspace=ws, steps=[est_step])\n",
|
"\n",
|
||||||
"pipeline_run = Experiment(ws, 'Estimator_sample').submit(pipeline)"
|
"pipeline = Pipeline(workspace=ws, steps=[train])\n",
|
||||||
|
"pipeline_run = Experiment(ws, 'train-commandstep-pipeline').submit(pipeline)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -295,7 +274,7 @@
|
|||||||
"framework": [
|
"framework": [
|
||||||
"Azure ML"
|
"Azure ML"
|
||||||
],
|
],
|
||||||
"friendly_name": "Azure Machine Learning Pipeline with EstimatorStep",
|
"friendly_name": "Azure Machine Learning Pipeline with CommandStep",
|
||||||
"kernelspec": {
|
"kernelspec": {
|
||||||
"display_name": "Python 3.6",
|
"display_name": "Python 3.6",
|
||||||
"language": "python",
|
"language": "python",
|
||||||
@@ -311,7 +290,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.6.7"
|
"version": "3.7.7"
|
||||||
},
|
},
|
||||||
"order_index": 7,
|
"order_index": 7,
|
||||||
"star_tag": [
|
"star_tag": [
|
||||||
@@ -320,7 +299,7 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"None"
|
"None"
|
||||||
],
|
],
|
||||||
"task": "Demonstrates the use of EstimatorStep"
|
"task": "Demonstrates the use of CommandStep"
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
"nbformat_minor": 2
|
"nbformat_minor": 2
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
FROM rocker/tidyverse:4.0.0-ubuntu18.04
|
||||||
|
|
||||||
|
# Install python
|
||||||
|
RUN apt-get update -qq && \
|
||||||
|
apt-get install -y python3
|
||||||
|
|
||||||
|
# Create link for python
|
||||||
|
RUN ln -f /usr/bin/python3 /usr/bin/python
|
||||||
|
|
||||||
|
# Install additional R packages
|
||||||
|
RUN R -e "install.packages(c('optparse'), repos = 'https://cloud.r-project.org/')"
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#' Copyright(c) Microsoft Corporation.
|
||||||
|
#' Licensed under the MIT license.
|
||||||
|
|
||||||
|
library(optparse)
|
||||||
|
|
||||||
|
options <- list(
|
||||||
|
make_option(c("-d", "--data_folder")),
|
||||||
|
make_option(c("--output_folder"))
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
opt_parser <- OptionParser(option_list = options)
|
||||||
|
opt <- parse_args(opt_parser)
|
||||||
|
|
||||||
|
paste(opt$data_folder)
|
||||||
|
|
||||||
|
accidents <- readRDS(file.path(opt$data_folder, "accidents.Rd"))
|
||||||
|
summary(accidents)
|
||||||
|
|
||||||
|
mod <- glm(dead ~ dvcat + seatbelt + frontal + sex + ageOFocc + yearVeh + airbag + occRole, family=binomial, data=accidents)
|
||||||
|
summary(mod)
|
||||||
|
predictions <- factor(ifelse(predict(mod)>0.1, "dead","alive"))
|
||||||
|
accuracy <- mean(predictions == accidents$dead)
|
||||||
|
|
||||||
|
# make directory for output dir
|
||||||
|
output_dir = opt$output_folder
|
||||||
|
if (!dir.exists(output_dir)){
|
||||||
|
dir.create(output_dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
# save model
|
||||||
|
model_path = file.path(output_dir, "model.rds")
|
||||||
|
saveRDS(mod, file = model_path)
|
||||||
|
message("Model saved")
|
||||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
|||||||
|
channels:
|
||||||
|
- conda-forge
|
||||||
|
dependencies:
|
||||||
|
- python=3.7
|
||||||
|
- pip:
|
||||||
|
- azureml-defaults
|
||||||
|
- tensorflow-gpu==2.3.0
|
||||||
|
- horovod==0.19.5
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
# Copyright 2019 Uber Technologies, Inc. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# Script adapted from: https://github.com/horovod/horovod/blob/master/examples/tensorflow2_keras_mnist.py
|
||||||
|
# ==============================================================================
|
||||||
|
|
||||||
|
import tensorflow as tf
|
||||||
|
import horovod.tensorflow.keras as hvd
|
||||||
|
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--learning-rate", "-lr", type=float, default=0.001)
|
||||||
|
parser.add_argument("--epochs", type=int, default=24)
|
||||||
|
parser.add_argument("--steps-per-epoch", type=int, default=500)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Horovod: initialize Horovod.
|
||||||
|
hvd.init()
|
||||||
|
|
||||||
|
# Horovod: pin GPU to be used to process local rank (one GPU per process)
|
||||||
|
gpus = tf.config.experimental.list_physical_devices("GPU")
|
||||||
|
for gpu in gpus:
|
||||||
|
tf.config.experimental.set_memory_growth(gpu, True)
|
||||||
|
if gpus:
|
||||||
|
tf.config.experimental.set_visible_devices(gpus[hvd.local_rank()], "GPU")
|
||||||
|
|
||||||
|
(mnist_images, mnist_labels), _ = tf.keras.datasets.mnist.load_data(
|
||||||
|
path="mnist-%d.npz" % hvd.rank()
|
||||||
|
)
|
||||||
|
|
||||||
|
dataset = tf.data.Dataset.from_tensor_slices(
|
||||||
|
(
|
||||||
|
tf.cast(mnist_images[..., tf.newaxis] / 255.0, tf.float32),
|
||||||
|
tf.cast(mnist_labels, tf.int64),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
dataset = dataset.repeat().shuffle(10000).batch(128)
|
||||||
|
|
||||||
|
mnist_model = tf.keras.Sequential(
|
||||||
|
[
|
||||||
|
tf.keras.layers.Conv2D(32, [3, 3], activation="relu"),
|
||||||
|
tf.keras.layers.Conv2D(64, [3, 3], activation="relu"),
|
||||||
|
tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
|
||||||
|
tf.keras.layers.Dropout(0.25),
|
||||||
|
tf.keras.layers.Flatten(),
|
||||||
|
tf.keras.layers.Dense(128, activation="relu"),
|
||||||
|
tf.keras.layers.Dropout(0.5),
|
||||||
|
tf.keras.layers.Dense(10, activation="softmax"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Horovod: adjust learning rate based on number of GPUs.
|
||||||
|
scaled_lr = args.learning_rate * hvd.size()
|
||||||
|
opt = tf.optimizers.Adam(scaled_lr)
|
||||||
|
|
||||||
|
# Horovod: add Horovod DistributedOptimizer.
|
||||||
|
opt = hvd.DistributedOptimizer(opt)
|
||||||
|
|
||||||
|
# Horovod: Specify `experimental_run_tf_function=False` to ensure TensorFlow
|
||||||
|
# uses hvd.DistributedOptimizer() to compute gradients.
|
||||||
|
mnist_model.compile(
|
||||||
|
loss=tf.losses.SparseCategoricalCrossentropy(),
|
||||||
|
optimizer=opt,
|
||||||
|
metrics=["accuracy"],
|
||||||
|
experimental_run_tf_function=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
callbacks = [
|
||||||
|
# Horovod: broadcast initial variable states from rank 0 to all other processes.
|
||||||
|
# This is necessary to ensure consistent initialization of all workers when
|
||||||
|
# training is started with random weights or restored from a checkpoint.
|
||||||
|
hvd.callbacks.BroadcastGlobalVariablesCallback(0),
|
||||||
|
# Horovod: average metrics among workers at the end of every epoch.
|
||||||
|
#
|
||||||
|
# Note: This callback must be in the list before the ReduceLROnPlateau,
|
||||||
|
# TensorBoard or other metrics-based callbacks.
|
||||||
|
hvd.callbacks.MetricAverageCallback(),
|
||||||
|
# Horovod: using `lr = 1.0 * hvd.size()` from the very beginning leads to worse final
|
||||||
|
# accuracy. Scale the learning rate `lr = 1.0` ---> `lr = 1.0 * hvd.size()` during
|
||||||
|
# the first three epochs. See https://arxiv.org/abs/1706.02677 for details.
|
||||||
|
hvd.callbacks.LearningRateWarmupCallback(
|
||||||
|
warmup_epochs=3, initial_lr=scaled_lr, verbose=1
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Horovod: save checkpoints only on worker 0 to prevent other workers from corrupting them.
|
||||||
|
if hvd.rank() == 0:
|
||||||
|
output_dir = "./outputs"
|
||||||
|
os.makedirs(output_dir, exist_ok=True)
|
||||||
|
callbacks.append(
|
||||||
|
tf.keras.callbacks.ModelCheckpoint(
|
||||||
|
os.path.join(output_dir, "checkpoint-{epoch}.h5")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Horovod: write logs on worker 0.
|
||||||
|
verbose = 1 if hvd.rank() == 0 else 0
|
||||||
|
|
||||||
|
# Train the model.
|
||||||
|
# Horovod: adjust number of steps based on number of GPUs.
|
||||||
|
mnist_model.fit(
|
||||||
|
dataset,
|
||||||
|
steps_per_epoch=args.steps_per_epoch // hvd.size(),
|
||||||
|
callbacks=callbacks,
|
||||||
|
epochs=args.epochs,
|
||||||
|
verbose=verbose,
|
||||||
|
)
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
# Licensed under the MIT License.
|
|
||||||
import argparse
|
|
||||||
import os
|
|
||||||
|
|
||||||
print("*********************************************************")
|
|
||||||
print("Hello Azure ML!")
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('--datadir', type=str, help="data directory")
|
|
||||||
parser.add_argument('--output', type=str, help="output")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
print("Argument 1: %s" % args.datadir)
|
|
||||||
print("Argument 2: %s" % args.output)
|
|
||||||
|
|
||||||
if not (args.output is None):
|
|
||||||
os.makedirs(args.output, exist_ok=True)
|
|
||||||
print("%s created" % args.output)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from azureml.core import Run
|
|
||||||
run = Run.get_context()
|
|
||||||
print("Log Fibonacci numbers.")
|
|
||||||
run.log_list('Fibonacci numbers', [0, 1, 1, 2, 3, 5, 8, 13, 21, 34])
|
|
||||||
run.complete()
|
|
||||||
except:
|
|
||||||
print("Warning: you need to install Azure ML SDK in order to log metrics.")
|
|
||||||
|
|
||||||
print("*********************************************************")
|
|
||||||
@@ -22,3 +22,6 @@ print("Argument 4: %s" % args.pipeline_param)
|
|||||||
if not (args.output_compare is None):
|
if not (args.output_compare is None):
|
||||||
os.makedirs(args.output_compare, exist_ok=True)
|
os.makedirs(args.output_compare, exist_ok=True)
|
||||||
print("%s created" % args.output_compare)
|
print("%s created" % args.output_compare)
|
||||||
|
|
||||||
|
with open(os.path.join(args.output_compare, 'compare.txt'), 'w') as fw:
|
||||||
|
fw.write('here is the compare result')
|
||||||
|
|||||||
@@ -19,3 +19,8 @@ print("Argument 2: %s" % args.output_extract)
|
|||||||
if not (args.output_extract is None):
|
if not (args.output_extract is None):
|
||||||
os.makedirs(args.output_extract, exist_ok=True)
|
os.makedirs(args.output_extract, exist_ok=True)
|
||||||
print("%s created" % args.output_extract)
|
print("%s created" % args.output_extract)
|
||||||
|
|
||||||
|
with open(os.path.join(args.input_extract, '20news.pkl'), 'rb') as f:
|
||||||
|
content = f.read()
|
||||||
|
with open(os.path.join(args.output_extract, '20news.pkl'), 'wb') as fw:
|
||||||
|
fw.write(content)
|
||||||
|
|||||||
@@ -20,3 +20,8 @@ print("Argument 2: %s" % args.output_train)
|
|||||||
if not (args.output_train is None):
|
if not (args.output_train is None):
|
||||||
os.makedirs(args.output_train, exist_ok=True)
|
os.makedirs(args.output_train, exist_ok=True)
|
||||||
print("%s created" % args.output_train)
|
print("%s created" % args.output_train)
|
||||||
|
|
||||||
|
with open(os.path.join(args.input_data, '20news.pkl'), 'rb') as f:
|
||||||
|
content = f.read()
|
||||||
|
with open(os.path.join(args.output_train, '20news.pkl'), 'wb') as fw:
|
||||||
|
fw.write(content)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
" 2. Azure CLI Authentication\n",
|
" 2. Azure CLI Authentication\n",
|
||||||
" 3. Managed Service Identity (MSI) Authentication\n",
|
" 3. Managed Service Identity (MSI) Authentication\n",
|
||||||
" 4. Service Principal Authentication\n",
|
" 4. Service Principal Authentication\n",
|
||||||
|
" 5. Token Authentication\n",
|
||||||
" \n",
|
" \n",
|
||||||
"The interactive authentication is suitable for local experimentation on your own computer. Azure CLI authentication is suitable if you are already using Azure CLI for managing Azure resources, and want to sign in only once. The MSI and Service Principal authentication are suitable for automated workflows, for example as part of Azure Devops build."
|
"The interactive authentication is suitable for local experimentation on your own computer. Azure CLI authentication is suitable if you are already using Azure CLI for managing Azure resources, and want to sign in only once. The MSI and Service Principal authentication are suitable for automated workflows, for example as part of Azure Devops build."
|
||||||
]
|
]
|
||||||
@@ -319,6 +320,66 @@
|
|||||||
"See [Register an application with the Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app) quickstart for more details about application registrations. "
|
"See [Register an application with the Microsoft identity platform](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app) quickstart for more details about application registrations. "
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### Token Authentication\n",
|
||||||
|
"\n",
|
||||||
|
"When token generation and its refresh needs to be outside on AML SDK, we recommend using Token Authentication. It can be used for getting token for AML or ARM audience. Thus giving more granular control over token generated.\n",
|
||||||
|
"\n",
|
||||||
|
"This authentication class requires users to provide method `get_token_for_audience` which will be called to retrieve the token based on the audience passed.\n",
|
||||||
|
"\n",
|
||||||
|
"Audience that is passed to `get_token_for_audience` can be ARM or AML. Exact value that will be passed as audience will depend on cloud and type for audience."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from azureml.core.authentication import TokenAuthentication, Audience\n",
|
||||||
|
"\n",
|
||||||
|
"# This is a sample method to retrieve token and will be passed to TokenAuthentication\n",
|
||||||
|
"def get_token_for_audience(audience):\n",
|
||||||
|
" from adal import AuthenticationContext\n",
|
||||||
|
" client_id = \"my-client-id\"\n",
|
||||||
|
" client_secret = \"my-client-secret\"\n",
|
||||||
|
" tenant_id = \"my-tenant-id\"\n",
|
||||||
|
" auth_context = AuthenticationContext(\"https://login.microsoftonline.com/{}\".format(tenant_id))\n",
|
||||||
|
" resp = auth_context.acquire_token_with_client_credentials(audience,client_id,client_secret)\n",
|
||||||
|
" token = resp[\"accessToken\"]\n",
|
||||||
|
" return token\n",
|
||||||
|
"\n",
|
||||||
|
"\n",
|
||||||
|
"token_auth = TokenAuthentication(get_token_for_audience=get_token_for_audience)\n",
|
||||||
|
"\n",
|
||||||
|
"ws = Workspace(\n",
|
||||||
|
" subscription_id=\"my-subscription-id\",\n",
|
||||||
|
" resource_group=\"my-ml-rg\",\n",
|
||||||
|
" workspace_name=\"my-ml-workspace\",\n",
|
||||||
|
" auth=token_auth\n",
|
||||||
|
" )\n",
|
||||||
|
"\n",
|
||||||
|
"print(\"Found workspace {} at location {}\".format(ws.name, ws.location))\n",
|
||||||
|
"\n",
|
||||||
|
"token_aml_audience = token_auth.get_token(Audience.aml)\n",
|
||||||
|
"token_arm_audience = token_auth.get_token(Audience.arm)\n",
|
||||||
|
"\n",
|
||||||
|
"# Value of audience pass to `get_token_for_audience` can be retrieved as follows:\n",
|
||||||
|
"# aud_aml_val = token_auth.get_aml_resource_id() # For AML\n",
|
||||||
|
"# aud_arm_val = token_auth._cloud_type.endpoints.active_directory_resource_id # For ARM\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Token authentication object can be used to retrieve token for either AML or ARM audience,\n",
|
||||||
|
"which can be used by other clients to authenticate to AML or ARM"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
@@ -350,7 +411,7 @@
|
|||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"import os, uuid\n",
|
"import uuid\n",
|
||||||
"\n",
|
"\n",
|
||||||
"local_secret = os.environ.get(\"LOCAL_SECRET\", default = str(uuid.uuid4())) # Use random UUID as a substitute for real secret.\n",
|
"local_secret = os.environ.get(\"LOCAL_SECRET\", default = str(uuid.uuid4())) # Use random UUID as a substitute for real secret.\n",
|
||||||
"keyvault = ws.get_default_keyvault()\n",
|
"keyvault = ws.get_default_keyvault()\n",
|
||||||
|
|||||||
@@ -100,7 +100,7 @@
|
|||||||
"\n",
|
"\n",
|
||||||
"# Check core SDK version number\n",
|
"# Check core SDK version number\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(\"This notebook was created using SDK version 1.21.0, you are currently running version\", azureml.core.VERSION)"
|
"print(\"This notebook was created using SDK version 1.22.0, you are currently running version\", azureml.core.VERSION)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ Follow these sample notebooks to learn:
|
|||||||
3. [Train on remote VM](train-on-remote-vm): train a model using a remote Azure VM as compute target.
|
3. [Train on remote VM](train-on-remote-vm): train a model using a remote Azure VM as compute target.
|
||||||
4. [Train on ML Compute](train-on-amlcompute): train a model using an ML Compute cluster as compute target.
|
4. [Train on ML Compute](train-on-amlcompute): train a model using an ML Compute cluster as compute target.
|
||||||
5. [Train in an HDI Spark cluster](train-in-spark): train a Spark ML model using an HDInsight Spark cluster as compute target.
|
5. [Train in an HDI Spark cluster](train-in-spark): train a Spark ML model using an HDInsight Spark cluster as compute target.
|
||||||
6. [Train and hyperparameter tune on Iris Dataset with Scikit-learn](train-hyperparameter-tune-deploy-with-sklearn): train a model using the Scikit-learn estimator and tune hyperparameters with Hyperdrive.
|
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
3
index.md
3
index.md
@@ -30,7 +30,6 @@ Machine Learning notebook samples and encourage efficient retrieval of topics an
|
|||||||
| :star:[Azure Machine Learning Pipeline with DataTranferStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.ipynb) | Demonstrates the use of DataTranferStep | Custom | ADF | None | Azure ML | None |
|
| :star:[Azure Machine Learning Pipeline with DataTranferStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-data-transfer.ipynb) | Demonstrates the use of DataTranferStep | Custom | ADF | None | Azure ML | None |
|
||||||
| [Getting Started with Azure Machine Learning Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-getting-started.ipynb) | Getting Started notebook for ANML Pipelines | Custom | AML Compute | None | Azure ML | None |
|
| [Getting Started with Azure Machine Learning Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-getting-started.ipynb) | Getting Started notebook for ANML Pipelines | Custom | AML Compute | None | Azure ML | None |
|
||||||
| [Azure Machine Learning Pipeline with AzureBatchStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-azurebatch-to-run-a-windows-executable.ipynb) | Demonstrates the use of AzureBatchStep | Custom | Azure Batch | None | Azure ML | None |
|
| [Azure Machine Learning Pipeline with AzureBatchStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-azurebatch-to-run-a-windows-executable.ipynb) | Demonstrates the use of AzureBatchStep | Custom | Azure Batch | None | Azure ML | None |
|
||||||
| [Azure Machine Learning Pipeline with EstimatorStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-estimatorstep.ipynb) | Demonstrates the use of EstimatorStep | Custom | AML Compute | None | Azure ML | None |
|
|
||||||
| :star:[How to use ModuleStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-modulestep.ipynb) | Demonstrates the use of ModuleStep | Custom | AML Compute | None | Azure ML | None |
|
| :star:[How to use ModuleStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-modulestep.ipynb) | Demonstrates the use of ModuleStep | Custom | AML Compute | None | Azure ML | None |
|
||||||
| :star:[How to use Pipeline Drafts to create a Published Pipeline](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-pipeline-drafts.ipynb) | Demonstrates the use of Pipeline Drafts | Custom | AML Compute | None | Azure ML | None |
|
| :star:[How to use Pipeline Drafts to create a Published Pipeline](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-pipeline-drafts.ipynb) | Demonstrates the use of Pipeline Drafts | Custom | AML Compute | None | Azure ML | None |
|
||||||
| :star:[Azure Machine Learning Pipeline with HyperDriveStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.ipynb) | Demonstrates the use of HyperDriveStep | Custom | AML Compute | None | Azure ML | None |
|
| :star:[Azure Machine Learning Pipeline with HyperDriveStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-parameter-tuning-with-hyperdrive.ipynb) | Demonstrates the use of HyperDriveStep | Custom | AML Compute | None | Azure ML | None |
|
||||||
@@ -43,6 +42,8 @@ Machine Learning notebook samples and encourage efficient retrieval of topics an
|
|||||||
| :star:[How to use DatabricksStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-use-databricks-as-compute-target.ipynb) | Demonstrates the use of DatabricksStep | Custom | Azure Databricks | None | Azure ML, Azure Databricks | None |
|
| :star:[How to use DatabricksStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-use-databricks-as-compute-target.ipynb) | Demonstrates the use of DatabricksStep | Custom | Azure Databricks | None | Azure ML, Azure Databricks | None |
|
||||||
| :star:[How to use KustoStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-use-kusto-as-compute-target.ipynb) | Demonstrates the use of KustoStep | Custom | Kusto | None | Azure ML, Kusto | None |
|
| :star:[How to use KustoStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-use-kusto-as-compute-target.ipynb) | Demonstrates the use of KustoStep | Custom | Kusto | None | Azure ML, Kusto | None |
|
||||||
| :star:[How to use AutoMLStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-automated-machine-learning-step.ipynb) | Demonstrates the use of AutoMLStep | Custom | AML Compute | None | Automated Machine Learning | None |
|
| :star:[How to use AutoMLStep with AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-automated-machine-learning-step.ipynb) | Demonstrates the use of AutoMLStep | Custom | AML Compute | None | Automated Machine Learning | None |
|
||||||
|
| [Azure Machine Learning Pipeline with CommandStep for R](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep-r.ipynb) | Demonstrates the use of CommandStep for running R scripts | Custom | AML Compute | None | Azure ML | None |
|
||||||
|
| [Azure Machine Learning Pipeline with CommandStep](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-commandstep.ipynb) | Demonstrates the use of CommandStep | Custom | AML Compute | None | Azure ML | None |
|
||||||
| :star:[Azure Machine Learning Pipelines with Data Dependency](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-data-dependency-steps.ipynb) | Demonstrates how to construct a Pipeline with data dependency between steps | Custom | AML Compute | None | Azure ML | None |
|
| :star:[Azure Machine Learning Pipelines with Data Dependency](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-data-dependency-steps.ipynb) | Demonstrates how to construct a Pipeline with data dependency between steps | Custom | AML Compute | None | Azure ML | None |
|
||||||
| [How to use run a notebook as a step in AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-notebook-runner-step.ipynb) | Demonstrates the use of NotebookRunnerStep | Custom | AML Compute | None | Azure ML | None |
|
| [How to use run a notebook as a step in AML Pipelines](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-with-notebook-runner-step.ipynb) | Demonstrates the use of NotebookRunnerStep | Custom | AML Compute | None | Azure ML | None |
|
||||||
| [Use MLflow with Azure Machine Learning to Train and Deploy Keras Image Classifier](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-keras-auto-logging/train-and-deploy-keras-auto-logging.ipynb) | Use MLflow with Azure Machine Learning to Train and Deploy Keras Image Classifier, leveraging MLflow auto logging | MNIST | Local, AML Compute | Azure Container Instance | Keras | mlflow, keras |
|
| [Use MLflow with Azure Machine Learning to Train and Deploy Keras Image Classifier](https://github.com/Azure/MachineLearningNotebooks/blob/master//how-to-use-azureml/ml-frameworks/using-mlflow/train-and-deploy-keras-auto-logging/train-and-deploy-keras-auto-logging.ipynb) | Use MLflow with Azure Machine Learning to Train and Deploy Keras Image Classifier, leveraging MLflow auto logging | MNIST | Local, AML Compute | Azure Container Instance | Keras | mlflow, keras |
|
||||||
|
|||||||
@@ -102,7 +102,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"import azureml.core\n",
|
"import azureml.core\n",
|
||||||
"\n",
|
"\n",
|
||||||
"print(\"This notebook was created using version 1.21.0 of the Azure ML SDK\")\n",
|
"print(\"This notebook was created using version 1.22.0 of the Azure ML SDK\")\n",
|
||||||
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
"print(\"You are currently using version\", azureml.core.VERSION, \"of the Azure ML SDK\")"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -581,7 +581,7 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from azureml.pipeline.core.run import PipelineRun\n",
|
"from azureml.pipeline.core.run import PipelineRun\n",
|
||||||
"\n",
|
"\n",
|
||||||
"published_pipeline_run = PipelineRun(ws.experiments[\"batch_scoring\"], run_id)"
|
"published_pipeline_run = PipelineRun(ws.experiments[\"Tutorial-Batch-Scoring\"], run_id)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user