serverless samples (#2260)
* serverless samples * Update cli-automl-classification-task-bankmarketing-serverless.yml * Create automl-classification-task-bankmarketing-serverless.ipynb * Update automl-classification-task-bankmarketing-serverless.ipynb * Update automl-classification-task-bankmarketing-serverless.ipynb * Update automl-classification-task-bankmarketing-serverless.ipynb * Update automl-classification-task-bankmarketing-serverless.ipynb * Create pipeline-serverless.yml * Create pipeline_with_components_from_yaml_serverless.ipynb * Update pipeline_with_components_from_yaml_serverless.ipynb * Update pipeline_with_components_from_yaml_serverless.ipynb * add metadata to notebook cell * Update azureml-in-a-day.ipynb * Update azureml-in-a-day.ipynb * Update azureml-in-a-day.ipynb * Update e2e-ml-workflow.ipynb * Update e2e-ml-workflow.ipynb * Update quickstart.ipynb * Update quickstart.ipynb * Update quickstart.ipynb * Update quickstart.ipynb * Update quickstart.ipynb * Update quickstart.ipynb * Update quickstart.ipynb * Update train-model.ipynb * Update train-model.ipynb * Update train-model.ipynb * Update pipeline.ipynb * Update pipeline.ipynb * Update pipeline.ipynb * Update quickstart.ipynb * Update pipeline.ipynb * Update pipeline.ipynb * Update quickstart.ipynb * Update train-model.ipynb * Update train-model.ipynb * Update train-model.ipynb * Update cli-automl-classification-task-bankmarketing-serverless.yml * Update pipeline-serverless.yml * Update hello-code.yml * Update hello-data-uri-folder.yml * Update hello-dataset.yml * Update hello-git.yml * Update hello-interactive.yml * Update hello-iris-datastore-file.yml * Update hello-iris-datastore-folder.yml * Update hello-iris-file.yml * Update hello-iris-folder.yml * Update hello-iris-literal.yml * Update hello-mlflow.yml * Update hello-model-as-input.yml * Update hello-model-as-output.yml * Update hello-notebook.yml * Create hello-pipeline-abc-serverless.yml * Update hello-pipeline-abc-serverless.yml * Create hello-pipeline-customize-output-file-serverless.yml * Update hello-pipeline-customize-output-file-serverless.yml * Create hello-pipeline-customize-output-folder-serverless.yml * Update hello-pipeline-customize-output-file-serverless.yml * Update hello-pipeline-customize-output-folder-serverless.yml * Create hello-pipeline-default-artifacts-serverless.yml * Update hello-pipeline-default-artifacts-serverless.yml * Update hello-pipeline-default-artifacts-serverless.yml * Create hello-pipeline-io-serverless.yml * Update hello-pipeline-io-serverless.yml * Create hello-pipeline-settings-serverless.yml * Update hello-pipeline-settings-serverless.yml * Create hello-pipeline-serverless.yml * Update hello-pipeline-serverless.yml * Update hello-pipeline-serverless.yml * Update hello-world.yml * Update hello-world-output.yml * Update hello-world-output-data.yml * Update hello-world-org.yml * Update hello-world-input.yml * Update hello-world-env-var.yml * Update automl-classification-task-bankmarketing-serverless.ipynb * Update automl-classification-task-bankmarketing-serverless.ipynb * Update automl-classification-task-bankmarketing-serverless.ipynb * Update cli-automl-classification-task-bankmarketing-serverless.yml * Update auto-ml-forecasting-github-dau.ipynb * Update auto-ml-forecasting-github-dau.ipynb * Update auto-ml-forecasting-github-dau.ipynb * Update auto-ml-forecasting-github-dau.ipynb * Update auto-ml-forecasting-github-dau.ipynb * Update auto-ml-forecasting-github-dau.ipynb * Update cli-automl-forecasting-task-github-dau.yml * Update cli-automl-forecasting-orange-juice-sales.yml * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update hello-sweep.yml * Update train-model.ipynb * Update e2e-ml-workflow.ipynb * Update hello-automl-job-basic.yml * Update auto-ml-forecasting-github-dau.ipynb * Update auto-ml-forecasting-github-dau.ipynb * Update automl-forecasting-orange-juice-sales-mlflow.ipynb * Update quickstart.ipynb * Update train-model.ipynb * Update pipeline.ipynb * Update auto-ml-forecasting-github-dau.ipynb * Update auto-ml-forecasting-github-dau.ipynb --------- Co-authored-by: Sheri Gilley <sgilley@microsoft.com>
This commit is contained in:
Родитель
7c695d99df
Коммит
867d4c2ba8
|
@ -0,0 +1,53 @@
|
|||
$schema: https://azuremlsdk2.blob.core.windows.net/preview/0.0.1/autoMLJob.schema.json
|
||||
type: automl
|
||||
experiment_name: dpv2-cli-automl-classifier-experiment
|
||||
description: A Classification job using bank marketing
|
||||
# Serverless compute is used to run this AutoML job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
|
||||
task: classification
|
||||
log_verbosity: debug
|
||||
primary_metric: accuracy
|
||||
|
||||
target_column_name: "y"
|
||||
|
||||
#validation_data_size: 0.20
|
||||
#n_cross_validations: 5
|
||||
#test_data_size: 0.1
|
||||
|
||||
training_data:
|
||||
path: "./training-mltable-folder"
|
||||
type: mltable
|
||||
validation_data:
|
||||
path: "./validation-mltable-folder"
|
||||
type: mltable
|
||||
test_data:
|
||||
path: "./test-mltable-folder"
|
||||
type: mltable
|
||||
|
||||
limits:
|
||||
timeout_minutes: 180
|
||||
max_trials: 40
|
||||
max_concurrent_trials: 5
|
||||
trial_timeout_minutes: 20
|
||||
enable_early_termination: true
|
||||
exit_score: 0.92
|
||||
|
||||
featurization:
|
||||
mode: custom
|
||||
transformer_params:
|
||||
imputer:
|
||||
- fields: ["job"]
|
||||
parameters:
|
||||
strategy: most_frequent
|
||||
blocked_transformers:
|
||||
- WordEmbedding
|
||||
training:
|
||||
enable_model_explainability: true
|
||||
allowed_training_algorithms:
|
||||
- gradient_boosting
|
||||
- logistic_regression
|
||||
# Resources to run this serverless job
|
||||
resources:
|
||||
instance_type="Standard_E4s_v3"
|
||||
instance_count=5
|
|
@ -4,7 +4,6 @@ type: automl
|
|||
experiment_name: dpv2-cli-automl-forecasting-orange-juice-sales
|
||||
# name: dpv2-sdk-forecasting-train-job-01
|
||||
description: A Time-Series Forecasting job using orange juice sales dataset
|
||||
compute: azureml:cpu-cluster
|
||||
task: forecasting
|
||||
primary_metric: normalized_root_mean_squared_error
|
||||
log_verbosity: info
|
||||
|
|
|
@ -4,7 +4,6 @@ type: automl
|
|||
experiment_name: dpv2-cli-automl-forecasting-github-dau-experiment
|
||||
description: A Time-Series Forecasting job using Github DAU dataset that trains only the TCNForecaster model.
|
||||
|
||||
compute: azureml:automl-gpu-cluster
|
||||
|
||||
task: forecasting
|
||||
primary_metric: normalized_root_mean_squared_error
|
||||
|
@ -33,3 +32,6 @@ training:
|
|||
enable_stack_ensemble: false
|
||||
allowed_training_algorithms:
|
||||
- TCNForecaster
|
||||
resources:
|
||||
instance_type: Standard_E4s_v3
|
||||
instance_count: 4
|
||||
|
|
|
@ -5,7 +5,6 @@ experiment_name: dpv2-cli-automl-classifier-experiment
|
|||
# name: dpv2-cli-classifier-train-job-basic-01
|
||||
description: A Classification job using bank marketing
|
||||
|
||||
compute: azureml:cpu-cluster
|
||||
|
||||
task: classification
|
||||
primary_metric: accuracy
|
||||
|
|
|
@ -3,4 +3,3 @@ command: ls
|
|||
code: src
|
||||
environment:
|
||||
image: library/python:latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -8,4 +8,3 @@ inputs:
|
|||
path: azureml:local-folder-example@latest
|
||||
mode: ro_mount
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -8,4 +8,3 @@ inputs:
|
|||
path: azureml:sampledata@latest
|
||||
mode: ro_mount
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
|
@ -4,4 +4,3 @@ command: >-
|
|||
code: src
|
||||
environment:
|
||||
image: library/python:latest
|
||||
compute: azureml:cpu-cluster
|
|
@ -2,7 +2,6 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
|
|||
command: python hello-interactive.py && sleep 600
|
||||
code: src
|
||||
environment: azureml:AzureML-tensorflow-2.7-ubuntu20.04-py38-cuda11-gpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
||||
services:
|
||||
my_vscode:
|
||||
|
|
|
@ -8,4 +8,3 @@ inputs:
|
|||
type: uri_file
|
||||
path: azureml://datastores/workspaceblobstore/paths/example-data/iris.csv
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -9,4 +9,3 @@ inputs:
|
|||
type: uri_folder
|
||||
path: azureml://datastores/workspaceblobstore/paths/example-data/
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -8,4 +8,3 @@ inputs:
|
|||
type: uri_file
|
||||
path: https://azuremlexamples.blob.core.windows.net/datasets/iris.csv
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -9,4 +9,3 @@ inputs:
|
|||
type: uri_folder
|
||||
path: wasbs://datasets@azuremlexamples.blob.core.windows.net/
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -7,4 +7,3 @@ inputs:
|
|||
type: uri_file
|
||||
iris_csv: https://azuremlexamples.blob.core.windows.net/datasets/iris.csv
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -2,4 +2,3 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
|
|||
command: python hello-mlflow.py
|
||||
code: src
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -13,4 +13,3 @@ inputs:
|
|||
type: mlflow_model # List of all model types here: https://learn.microsoft.com/azure/machine-learning/reference-yaml-model#yaml-syntax
|
||||
path: ../../assets/model/mlflow-model
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -20,4 +20,3 @@ outputs:
|
|||
output_folder:
|
||||
type: custom_model # mlflow_model,custom_model, triton_model
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
compute: azureml:cpu-cluster
|
|
@ -5,4 +5,3 @@ command: |
|
|||
code: src
|
||||
environment:
|
||||
image: library/python:latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: hello_pipeline_abc
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
settings:
|
||||
default_compute: azureml:serverless
|
||||
|
||||
inputs:
|
||||
hello_string_top_level_input: "hello world"
|
||||
jobs:
|
||||
a:
|
||||
command: echo hello ${{inputs.hello_string}}
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
inputs:
|
||||
hello_string: ${{parent.inputs.hello_string_top_level_input}}
|
||||
b:
|
||||
command: echo "world" >> ${{outputs.world_output}}/world.txt
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
outputs:
|
||||
world_output:
|
||||
c:
|
||||
command: echo ${{inputs.world_input}}/world.txt
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
inputs:
|
||||
world_input: ${{parent.jobs.b.outputs.world_output}}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: hello_pipeline_customize_output_file
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
settings:
|
||||
default_compute: azureml:serverless
|
||||
|
||||
outputs:
|
||||
output:
|
||||
type: uri_file
|
||||
path: azureml://datastores/workspaceblobstore/paths/${{name}}/hello_world.txt
|
||||
mode: rw_mount
|
||||
jobs:
|
||||
hello_world:
|
||||
command: echo "hello" && echo "world" > ${{outputs.output}}
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
outputs:
|
||||
output: ${{parent.outputs.output}}
|
|
@ -0,0 +1,15 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: hello_pipeline_customize_output_folder
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
settings:
|
||||
default_compute: azureml:serverless
|
||||
jobs:
|
||||
hello_world:
|
||||
command: echo "hello" && echo "world" > ${{outputs.output}}/hello_world-folder.txt
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
outputs:
|
||||
output:
|
||||
type: uri_folder
|
||||
path: azureml://datastores/workspaceblobstore/paths/${{name}}/
|
|
@ -0,0 +1,19 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: hello_pipeline_default_artifacts
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
settings:
|
||||
default_compute: azureml:serverless
|
||||
jobs:
|
||||
hello_job:
|
||||
command: echo "hello" && echo "world" > ./outputs/world.txt
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
outputs:
|
||||
artifacts:
|
||||
world_job:
|
||||
command: cat ${{inputs.world_input}}/outputs/world.txt
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
inputs:
|
||||
world_input: ${{parent.jobs.hello_job.outputs.artifacts}}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: hello_pipeline_io
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
settings:
|
||||
default_compute: azureml:serverless
|
||||
jobs:
|
||||
hello_job:
|
||||
command: echo "hello" && echo "world" > ${{outputs.world_output}}/world.txt
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
outputs:
|
||||
world_output:
|
||||
world_job:
|
||||
command: cat ${{inputs.world_input}}/world.txt
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:1
|
||||
inputs:
|
||||
world_input: ${{parent.jobs.hello_job.outputs.world_output}}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: hello_pipeline
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
settings:
|
||||
default_compute: azureml:serverless
|
||||
jobs:
|
||||
hello_job:
|
||||
command: echo "hello"
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
world_job:
|
||||
command: echo "world"
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: hello_pipeline_settings
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
settings:
|
||||
default_datastore: azureml:workspaceblobstore
|
||||
default_compute: azureml:serverless
|
||||
jobs:
|
||||
hello_job:
|
||||
command: echo 202204190 & echo "hello"
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:1
|
||||
world_job:
|
||||
command: echo 202204190 & echo "hello"
|
||||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:1
|
|
@ -10,7 +10,6 @@ trial:
|
|||
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest
|
||||
inputs:
|
||||
A: 0.5
|
||||
compute: azureml:cpu-cluster
|
||||
sampling_algorithm: random
|
||||
search_space:
|
||||
B:
|
||||
|
|
|
@ -2,6 +2,5 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
|
|||
command: echo $hello_env_var
|
||||
environment:
|
||||
image: library/python:latest
|
||||
compute: azureml:cpu-cluster
|
||||
environment_variables:
|
||||
hello_env_var: "hello world"
|
||||
|
|
|
@ -7,4 +7,3 @@ environment:
|
|||
inputs:
|
||||
hello_string: "hello world"
|
||||
hello_number: 42
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -2,7 +2,6 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
|
|||
command: echo "hello world"
|
||||
environment:
|
||||
image: library/python:latest
|
||||
compute: azureml:cpu-cluster
|
||||
tags:
|
||||
hello: world
|
||||
display_name: hello-world-example
|
||||
|
|
|
@ -4,4 +4,3 @@ outputs:
|
|||
hello_output:
|
||||
environment:
|
||||
image: python
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -2,4 +2,3 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
|
|||
command: echo "hello world" > ./outputs/helloworld.txt
|
||||
environment:
|
||||
image: library/python:latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -2,4 +2,3 @@ $schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
|
|||
command: echo "hello world"
|
||||
environment:
|
||||
image: library/python:latest
|
||||
compute: azureml:cpu-cluster
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
|
||||
type: pipeline
|
||||
display_name: 1b_e2e_registered_components
|
||||
description: E2E dummy train-score-eval pipeline with registered components
|
||||
# Serverless compute is used to run this pipeline job.
|
||||
# Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you.
|
||||
inputs:
|
||||
pipeline_job_training_max_epocs: 20
|
||||
pipeline_job_training_learning_rate: 1.8
|
||||
pipeline_job_learning_rate_schedule: 'time-based'
|
||||
|
||||
outputs:
|
||||
pipeline_job_trained_model:
|
||||
mode: upload
|
||||
pipeline_job_scored_data:
|
||||
mode: upload
|
||||
pipeline_job_evaluation_report:
|
||||
mode: upload
|
||||
|
||||
settings:
|
||||
default_compute: azureml:serverless
|
||||
|
||||
jobs:
|
||||
train_job:
|
||||
type: command
|
||||
component: azureml:my_train@latest
|
||||
inputs:
|
||||
training_data:
|
||||
type: uri_folder
|
||||
path: ./data
|
||||
max_epocs: ${{parent.inputs.pipeline_job_training_max_epocs}}
|
||||
learning_rate: ${{parent.inputs.pipeline_job_training_learning_rate}}
|
||||
learning_rate_schedule: ${{parent.inputs.pipeline_job_learning_rate_schedule}}
|
||||
outputs:
|
||||
model_output: ${{parent.outputs.pipeline_job_trained_model}}
|
||||
services:
|
||||
my_vscode:
|
||||
type: vs_code
|
||||
my_jupyter_lab:
|
||||
type: jupyter_lab
|
||||
my_tensorboard:
|
||||
type: tensor_board
|
||||
log_dir: "outputs/tblogs"
|
||||
# my_ssh:
|
||||
# type: tensor_board
|
||||
# ssh_public_keys: <paste the entire pub key content>
|
||||
# nodes: all # Use the `nodes` property to pick which node you want to enable interactive services on. If `nodes` are not selected, by default, interactive applications are only enabled on the head node.
|
||||
|
||||
score_job:
|
||||
type: command
|
||||
component: azureml:my_score@latest
|
||||
inputs:
|
||||
model_input: ${{parent.jobs.train_job.outputs.model_output}}
|
||||
test_data:
|
||||
type: uri_folder
|
||||
path: ./data
|
||||
outputs:
|
||||
score_output: ${{parent.outputs.pipeline_job_scored_data}}
|
||||
|
||||
evaluate_job:
|
||||
type: command
|
||||
component: azureml:my_eval@latest
|
||||
inputs:
|
||||
scoring_result: ${{parent.jobs.score_job.outputs.score_output}}
|
||||
outputs:
|
||||
eval_output: ${{parent.outputs.pipeline_job_evaluation_report}}
|
|
@ -0,0 +1,996 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# AutoML: Train \"the best\" classifier model for the UCI Bank Marketing dataset. \n",
|
||||
"\n",
|
||||
"**Requirements** - In order to benefit from this tutorial, you will need:\n",
|
||||
"- A basic understanding of Machine Learning\n",
|
||||
"- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F)\n",
|
||||
"- An Azure ML workspace. [Check this notebook for creating a workspace](../../../resources/workspace/workspace.ipynb) \n",
|
||||
"- This notebook leverages **serverless compute** to run the job. There is no need for user to create and manage compute. \n",
|
||||
"- A python environment\n",
|
||||
"- Installed Azure Machine Learning Python SDK v2 - [install instructions](../../../README.md) - check the getting started section\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"**Learning Objectives** - By the end of this tutorial, you should be able to:\n",
|
||||
"- Connect to your AML workspace from the Python SDK\n",
|
||||
"- Create an `AutoML classification Job` with the 'classification()' factory-fuction.\n",
|
||||
"- Train the model using AmlCompute by submitting/running the AutoML training job\n",
|
||||
"- Obtaing the model and score predictions with it\n",
|
||||
"- Leverage the auto generated training code and use it for retraining on an updated dataset\n",
|
||||
"\n",
|
||||
"**Motivations** - This notebook explains how to setup and run an AutoML classification job. This is one of the nine ML-tasks supported by AutoML. Other ML-tasks are 'regression', 'time-series forecasting', 'image classification', 'image object detection', 'nlp text classification', etc.\n",
|
||||
"\n",
|
||||
"In this notebook, we go over how you can use AutoML for training a Classification model. We will use the UCI Bank Marketing dataset to train and deploy the model to use in inference scenarios. The classification goal is to predict if the client will subscribe to a term deposit with the bank. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 1. Connect to Azure Machine Learning Workspace\n",
|
||||
"\n",
|
||||
"The [workspace](https://docs.microsoft.com/en-us/azure/machine-learning/concept-workspace) is the top-level resource for Azure Machine Learning, providing a centralized place to work with all the artifacts you create when you use Azure Machine Learning. In this section we will connect to the workspace in which the job will be run.\n",
|
||||
"\n",
|
||||
"## 1.1. Import the required libraries"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1634852261599
|
||||
},
|
||||
"name": "automl-import"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Import required libraries\n",
|
||||
"import os\n",
|
||||
"from azure.identity import DefaultAzureCredential\n",
|
||||
"from azure.identity import AzureCliCredential\n",
|
||||
"from azure.ai.ml import automl, Input, MLClient, command\n",
|
||||
"\n",
|
||||
"from azure.ai.ml.constants import AssetTypes\n",
|
||||
"from azure.ai.ml.entities import Data\n",
|
||||
"from azure.ai.ml.automl import (\n",
|
||||
" classification,\n",
|
||||
" ClassificationPrimaryMetrics,\n",
|
||||
" ClassificationModels,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1.2. Configure workspace details and get a handle to the workspace\n",
|
||||
"\n",
|
||||
"To connect to a workspace, we need identifier parameters - a subscription, resource group and workspace name. We will use these details in the `MLClient` from `azure.ai.ml` to get a handle to the required Azure Machine Learning workspace. We use the [default azure authentication](https://docs.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python) for this tutorial. Check the [configuration notebook](../../configuration.ipynb) for more details on how to configure credentials and connect to a workspace."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1634852261744
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"name": "mlclient-setup",
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"credential = DefaultAzureCredential()\n",
|
||||
"ml_client = None\n",
|
||||
"try:\n",
|
||||
" ml_client = MLClient.from_config(credential)\n",
|
||||
"except Exception as ex:\n",
|
||||
" print(ex)\n",
|
||||
" # Enter details of your AML workspace\n",
|
||||
" subscription_id = \"<SUBSCRIPTION_ID>\"\n",
|
||||
" resource_group = \"<RESOURCE_GROUP>\"\n",
|
||||
" workspace = \"<AML_WORKSPACE_NAME>\"\n",
|
||||
" ml_client = MLClient(credential, subscription_id, resource_group, workspace)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Show Azure ML Workspace information"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"workspace = ml_client.workspaces.get(name=ml_client.workspace_name)\n",
|
||||
"\n",
|
||||
"subscription_id = ml_client.connections._subscription_id\n",
|
||||
"resource_group = workspace.resource_group\n",
|
||||
"workspace_name = ml_client.workspace_name\n",
|
||||
"\n",
|
||||
"output = {}\n",
|
||||
"output[\"Workspace\"] = workspace_name\n",
|
||||
"output[\"Subscription ID\"] = subscription_id\n",
|
||||
"output[\"Resource Group\"] = resource_group\n",
|
||||
"output[\"Location\"] = workspace.location\n",
|
||||
"output"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 2. MLTable with input Training Data\n",
|
||||
"\n",
|
||||
"## 2.1. Create MLTable data input"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"name": "data-load"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Training MLTable defined locally, with local data to be uploaded\n",
|
||||
"my_training_data_input = Input(\n",
|
||||
" type=AssetTypes.MLTABLE, path=\"./data/training-mltable-folder\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# WITH REMOTE PATH: If available already in the cloud/workspace-blob-store\n",
|
||||
"# my_training_data_input = Input(type=AssetTypes.MLTABLE, path=\"azureml://datastores/workspaceblobstore/paths/Classification/Train\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 3. Configure and run the AutoML classification job\n",
|
||||
"In this section we will configure and run the AutoML classification job.\n",
|
||||
"\n",
|
||||
"## 3.1 Configure the job through the classification() factory function\n",
|
||||
"\n",
|
||||
"### classification() parameters:\n",
|
||||
"\n",
|
||||
"The `classification()` factory function allows user to configure AutoML for the classification task for the most common scenarios with the following properties.\n",
|
||||
"\n",
|
||||
"- `target_column_name` - The name of the column to target for predictions. It must always be specified. This parameter is applicable to 'training_data', 'validation_data' and 'test_data'.\n",
|
||||
"- `primary_metric` - The metric that AutoML will optimize for Classification model selection.\n",
|
||||
"- `training_data` - The data to be used for training. It should contain both training feature columns and a target column. Optionally, this data can be split for segregating a validation or test dataset. \n",
|
||||
"You can use a registered MLTable in the workspace using the format '<mltable_name>:<version>' OR you can use a local file or folder as a MLTable. For e.g Input(mltable='my_mltable:1') OR Input(mltable=MLTable(local_path=\"./data\"))\n",
|
||||
"The parameter 'training_data' must always be provided.\n",
|
||||
"- `name` - The name of the Job/Run. This is an optional property. If not specified, a random name will be generated.\n",
|
||||
"- `experiment_name` - The name of the Experiment. An Experiment is like a folder with multiple runs in Azure ML Workspace that should be related to the same logical machine learning experiment.\n",
|
||||
"\n",
|
||||
"### set_limits() function parameters:\n",
|
||||
"This is an optional configuration method to configure limits parameters such as timeouts. \n",
|
||||
" \n",
|
||||
"- `timeout_minutes` - Maximum amount of time in minutes that the whole AutoML job can take before the job terminates. This timeout includes setup, featurization and training runs but does not include the ensembling and model explainability runs at the end of the process since those actions need to happen once all the trials (children jobs) are done. If not specified, the default job's total timeout is 6 days (8,640 minutes). To specify a timeout less than or equal to 1 hour (60 minutes), make sure your dataset's size is not greater than 10,000,000 (rows times column) or an error results.\n",
|
||||
"\n",
|
||||
"- `trial_timeout_minutes` - Maximum time in minutes that each trial (child job) can run for before it terminates. If not specified, a value of 1 month or 43200 minutes is used.\n",
|
||||
" \n",
|
||||
"- `max_trials` - The maximum number of trials/runs each with a different combination of algorithm and hyperparameters to try during an AutoML job. If not specified, the default is 1000 trials. If using 'enable_early_termination' the number of trials used can be smaller.\n",
|
||||
" \n",
|
||||
"- `max_concurrent_trials` - Represents the maximum number of trials (children jobs) that would be executed in parallel. It's a good practice to match this number with the number of nodes your cluster.\n",
|
||||
" \n",
|
||||
"- `enable_early_termination` - Whether to enable early termination if the score is not improving in the short term. \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# General job parameters\n",
|
||||
"max_trials = 5\n",
|
||||
"exp_name = \"dpv2-classifier-experiment\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1634852262026
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"name": "classification-configuration",
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Create the AutoML classification job with the related factory-function.\n",
|
||||
"from azure.ai.ml.entities import ResourceConfiguration \n",
|
||||
"\n",
|
||||
"classification_job = automl.classification(\n",
|
||||
" experiment_name=exp_name,\n",
|
||||
" training_data=my_training_data_input,\n",
|
||||
" target_column_name=\"y\",\n",
|
||||
" primary_metric=\"accuracy\",\n",
|
||||
" n_cross_validations=5,\n",
|
||||
" enable_model_explainability=True,\n",
|
||||
" tags={\"my_custom_tag\": \"My custom value\"},\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Limits are all optional\n",
|
||||
"classification_job.set_limits(\n",
|
||||
" timeout_minutes=600,\n",
|
||||
" trial_timeout_minutes=20,\n",
|
||||
" max_trials=max_trials,\n",
|
||||
" # max_concurrent_trials = 4,\n",
|
||||
" # max_cores_per_trial: -1,\n",
|
||||
" enable_early_termination=True,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Training properties are optional\n",
|
||||
"classification_job.set_training(\n",
|
||||
" blocked_training_algorithms=[ClassificationModels.LOGISTIC_REGRESSION],\n",
|
||||
" enable_onnx_compatible_models=True,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Serverless compute resources used to run the job\n",
|
||||
"classification_job.resources = \n",
|
||||
"ResourceConfiguration(instance_type=\"Standard_E4s_v3\", instance_count=6)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3.2 Run the Command\n",
|
||||
"Using the `MLClient` created earlier, we will now run this Command in the workspace."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1634852267930
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"name": "job-submit",
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Submit the AutoML job\n",
|
||||
"returned_job = ml_client.jobs.create_or_update(\n",
|
||||
" classification_job\n",
|
||||
") # submit the job to the backend\n",
|
||||
"\n",
|
||||
"print(f\"Created job: {returned_job}\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Wait until the AutoML job is finished\n",
|
||||
"ml_client.jobs.stream(returned_job.name) waits until the specified job is finished"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ml_client.jobs.stream(returned_job.name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get a URL for the status of the job\n",
|
||||
"returned_job.services[\"Studio\"].endpoint"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(returned_job.name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 4. Retrieve the Best Trial (Best Model's trial/run)\n",
|
||||
"Use the MLFLowClient to access the results (such as Models, Artifacts, Metrics) of a previously completed AutoML Trial."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Initialize MLFlow Client\n",
|
||||
"The models and artifacts that are produced by AutoML can be accessed via the MLFlow interface. \n",
|
||||
"Initialize the MLFlow client here, and set the backend as Azure ML, via. the MLFlow Client.\n",
|
||||
"\n",
|
||||
"*IMPORTANT*, you need to have installed the latest MLFlow packages with:\n",
|
||||
"\n",
|
||||
" pip install azureml-mlflow\n",
|
||||
"\n",
|
||||
" pip install mlflow"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Obtain the tracking URI for MLFlow"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import mlflow\n",
|
||||
"\n",
|
||||
"# Obtain the tracking URL from MLClient\n",
|
||||
"MLFLOW_TRACKING_URI = ml_client.workspaces.get(\n",
|
||||
" name=ml_client.workspace_name\n",
|
||||
").mlflow_tracking_uri\n",
|
||||
"\n",
|
||||
"print(MLFLOW_TRACKING_URI)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Set the MLFLOW TRACKING URI\n",
|
||||
"\n",
|
||||
"mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)\n",
|
||||
"\n",
|
||||
"print(\"\\nCurrent tracking uri: {}\".format(mlflow.get_tracking_uri()))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from mlflow.tracking.client import MlflowClient\n",
|
||||
"from mlflow.artifacts import download_artifacts\n",
|
||||
"\n",
|
||||
"# Initialize MLFlow client\n",
|
||||
"mlflow_client = MlflowClient()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Get the AutoML parent Job"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"job_name = returned_job.name\n",
|
||||
"\n",
|
||||
"# Example if providing an specific Job name/ID\n",
|
||||
"# job_name = \"b4e95546-0aa1-448e-9ad6-002e3207b4fc\"\n",
|
||||
"\n",
|
||||
"# Get the parent run\n",
|
||||
"mlflow_parent_run = mlflow_client.get_run(job_name)\n",
|
||||
"\n",
|
||||
"print(\"Parent Run: \")\n",
|
||||
"print(mlflow_parent_run)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Print parent run tags. 'automl_best_child_run_id' tag should be there.\n",
|
||||
"print(mlflow_parent_run.data.tags)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Get the AutoML best child run"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get the best model's child run\n",
|
||||
"\n",
|
||||
"best_child_run_id = mlflow_parent_run.data.tags[\"automl_best_child_run_id\"]\n",
|
||||
"print(\"Found best child run id: \", best_child_run_id)\n",
|
||||
"\n",
|
||||
"best_run = mlflow_client.get_run(best_child_run_id)\n",
|
||||
"\n",
|
||||
"print(\"Best child run: \")\n",
|
||||
"print(best_run)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Get best model run's metrics\n",
|
||||
"\n",
|
||||
"Access the results (such as Models, Artifacts, Metrics) of a previously completed AutoML Run."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"best_run.data.metrics"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Download the best model locally\n",
|
||||
"\n",
|
||||
"Access the results (such as Models, Artifacts, Metrics) of a previously completed AutoML Run."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"# Create local folder\n",
|
||||
"local_dir = \"./artifact_downloads\"\n",
|
||||
"if not os.path.exists(local_dir):\n",
|
||||
" os.mkdir(local_dir)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Download run's artifacts/outputs\n",
|
||||
"local_path = download_artifacts(\n",
|
||||
" run_id=best_run.info.run_id, artifact_path=\"outputs\", dst_path=local_dir\n",
|
||||
")\n",
|
||||
"print(\"Artifacts downloaded in: {}\".format(local_path))\n",
|
||||
"print(\"Artifacts: {}\".format(os.listdir(local_path)))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Show the contents of the MLFlow model folder\n",
|
||||
"os.listdir(\"./artifact_downloads/outputs/mlflow-model\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 5. Register Best Model and Deploy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5.1 Create managed online endpoint"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# import required libraries\n",
|
||||
"from azure.ai.ml.entities import (\n",
|
||||
" ManagedOnlineEndpoint,\n",
|
||||
" ManagedOnlineDeployment,\n",
|
||||
" Model,\n",
|
||||
" Environment,\n",
|
||||
" CodeConfiguration,\n",
|
||||
" ProbeSettings,\n",
|
||||
")\n",
|
||||
"from azure.ai.ml.constants import ModelType"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Creating a unique endpoint name with current datetime to avoid conflicts\n",
|
||||
"import datetime\n",
|
||||
"\n",
|
||||
"online_endpoint_name = \"bankmarketing-\" + datetime.datetime.now().strftime(\"%m%d%H%M%f\")\n",
|
||||
"\n",
|
||||
"# create an online endpoint\n",
|
||||
"endpoint = ManagedOnlineEndpoint(\n",
|
||||
" name=online_endpoint_name,\n",
|
||||
" description=\"this is a sample online endpoint for mlflow model\",\n",
|
||||
" auth_mode=\"key\",\n",
|
||||
" tags={\"foo\": \"bar\"},\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ml_client.begin_create_or_update(endpoint).result()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5.2 Register best model and deploy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Register model"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model_name = \"bankmarketing-model\"\n",
|
||||
"model = Model(\n",
|
||||
" path=f\"azureml://jobs/{best_run.info.run_id}/outputs/artifacts/outputs/mlflow-model/\",\n",
|
||||
" name=model_name,\n",
|
||||
" description=\"my sample classification model\",\n",
|
||||
" type=AssetTypes.MLFLOW_MODEL,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# for downloaded file\n",
|
||||
"# model = Model(path=\"artifact_downloads/outputs/model.pkl\", name=model_name)\n",
|
||||
"\n",
|
||||
"registered_model = ml_client.models.create_or_update(model)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"registered_model.id"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Deploy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"deployment = ManagedOnlineDeployment(\n",
|
||||
" name=\"bankmarketing-deploy\",\n",
|
||||
" endpoint_name=online_endpoint_name,\n",
|
||||
" model=registered_model.id,\n",
|
||||
" instance_type=\"Standard_DS2_V2\",\n",
|
||||
" instance_count=1,\n",
|
||||
" liveness_probe=ProbeSettings(\n",
|
||||
" failure_threshold=30,\n",
|
||||
" success_threshold=1,\n",
|
||||
" timeout=2,\n",
|
||||
" period=10,\n",
|
||||
" initial_delay=2000,\n",
|
||||
" ),\n",
|
||||
" readiness_probe=ProbeSettings(\n",
|
||||
" failure_threshold=10,\n",
|
||||
" success_threshold=1,\n",
|
||||
" timeout=10,\n",
|
||||
" period=10,\n",
|
||||
" initial_delay=2000,\n",
|
||||
" ),\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ml_client.online_deployments.begin_create_or_update(deployment).result()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# bankmarketing deployment to take 100% traffic\n",
|
||||
"endpoint.traffic = {\"bankmarketing-deploy\": 100}\n",
|
||||
"ml_client.begin_create_or_update(endpoint)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Test the deployment"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# test the blue deployment with some sample data\n",
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"test_data = pd.read_csv(\"./data/test-mltable-folder/bank_marketing_test_data.csv\")\n",
|
||||
"\n",
|
||||
"test_data = test_data.drop(\"y\", axis=1)\n",
|
||||
"\n",
|
||||
"test_data_json = test_data.to_json(orient=\"records\", indent=4)\n",
|
||||
"data = (\n",
|
||||
" '{ \\\n",
|
||||
" \"input_data\": {\"data\": '\n",
|
||||
" + test_data_json\n",
|
||||
" + \"}}\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"request_file_name = \"sample-request-bankmarketing.json\"\n",
|
||||
"\n",
|
||||
"with open(request_file_name, \"w\") as request_file:\n",
|
||||
" request_file.write(data)\n",
|
||||
"\n",
|
||||
"ml_client.online_endpoints.invoke(\n",
|
||||
" endpoint_name=online_endpoint_name,\n",
|
||||
" deployment_name=\"bankmarketing-deploy\",\n",
|
||||
" request_file=request_file_name,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# wait and delete endpoint\n",
|
||||
"import time\n",
|
||||
"\n",
|
||||
"time.sleep(60)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Get endpoint details"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get the details for online endpoint\n",
|
||||
"endpoint = ml_client.online_endpoints.get(name=online_endpoint_name)\n",
|
||||
"\n",
|
||||
"# existing traffic details\n",
|
||||
"print(endpoint.traffic)\n",
|
||||
"\n",
|
||||
"# Get the scoring URI\n",
|
||||
"print(endpoint.scoring_uri)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Delete the deployment and endpoint"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ml_client.online_endpoints.begin_delete(name=online_endpoint_name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Next Step: Load the best model and try predictions\n",
|
||||
"\n",
|
||||
"Loading the models locally assume that you are running the notebook in an environment compatible with the model. The list of dependencies that is expected by the model is specified in the MLFlow model produced by AutoML (in the 'conda.yaml' file within the mlflow-model folder).\n",
|
||||
"\n",
|
||||
"Since the AutoML model was trained remotelly in a different environment with different dependencies to your current local conda environment where you are running this notebook, if you want to load the model you have several options:\n",
|
||||
"\n",
|
||||
"1. A recommended way to locally load the model in memory and try predictions is to create a new/clean conda environment with the dependencies specified in the conda.yaml file within the MLFlow model's folder, then use MLFlow to load the model and call .predict() as explained in the notebook **mlflow-model-local-inference-test.ipynb** in this same folder.\n",
|
||||
"\n",
|
||||
"2. You can install all the packages/dependencies specified in conda.yaml into your current conda environment you used for using Azure ML SDK and AutoML. MLflow SDK also have a method to install the dependencies in the current environment. However, this option could have risks of package version conflicts depending on what's installed in your current environment.\n",
|
||||
"\n",
|
||||
"3. You can also use: mlflow models serve -m 'xxxxxxx'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 6. Using the auto generated model training code for retraining on new data\n",
|
||||
"Code generation is automatically enabled on all sdk v2 jobs, so we now have access to the code that was used to generate any of the AutoML tried models. Below we'll be using the generated training script of the best model to retrain on a new dataset.\n",
|
||||
"\n",
|
||||
"## 6.1 Register Dataset\n",
|
||||
"For this demo, we'll begin by registering a dataset to use for retraining and setting the MLFlow tracking uri. It should be noted that this is not new data, just a combination of the Training and Validation datasets.\n",
|
||||
"\n",
|
||||
"*IMPORTANT*, MLFlow is used to access the results for the above run, so make sure you have installed the latest MLFlow packages with:\n",
|
||||
"\n",
|
||||
" pip install azureml-mlflow\n",
|
||||
"\n",
|
||||
" pip install mlflow"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"retrain_data = Data(\n",
|
||||
" path=\"./data/retrained-mltable-folder/\",\n",
|
||||
" type=AssetTypes.MLTABLE,\n",
|
||||
" description=\"Updated training dataset, includes validation data.\",\n",
|
||||
" name=\"bankmarketing-retrain-data\",\n",
|
||||
")\n",
|
||||
"retrain_data = ml_client.data.create_or_update(retrain_data)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import mlflow\n",
|
||||
"\n",
|
||||
"# Obtain the tracking URL from MLClient\n",
|
||||
"MLFLOW_TRACKING_URI = ml_client.workspaces.get(\n",
|
||||
" name=ml_client.workspace_name\n",
|
||||
").mlflow_tracking_uri\n",
|
||||
"\n",
|
||||
"print(MLFLOW_TRACKING_URI)\n",
|
||||
"\n",
|
||||
"# Set the MLFLOW TRACKING URI\n",
|
||||
"mlflow.set_tracking_uri(MLFLOW_TRACKING_URI)\n",
|
||||
"\n",
|
||||
"print(\"\\nCurrent tracking uri: {}\".format(mlflow.get_tracking_uri()))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 6.2 Download Script\n",
|
||||
"Next, we'll download the generated script for the best run and use it for retraining. For more advanced scenarios, you can customize the training script as you need: change the featurization pipeline, change the learner algorithm or its hyperparameters, etc.\n",
|
||||
"\n",
|
||||
"For this exercise, we'll leave the script as it was generated."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from mlflow.tracking.client import MlflowClient\n",
|
||||
"\n",
|
||||
"# Initialize MLFlow client\n",
|
||||
"mlflow_client = MlflowClient()\n",
|
||||
"\n",
|
||||
"# Get the parent run\n",
|
||||
"job_name = returned_job.name\n",
|
||||
"mlflow_parent_run = mlflow_client.get_run(job_name)\n",
|
||||
"print(\"Parent Run: \")\n",
|
||||
"print(mlflow_parent_run)\n",
|
||||
"\n",
|
||||
"# Get the best model's child run\n",
|
||||
"best_child_run_id = mlflow_parent_run.data.tags[\"automl_best_child_run_id\"]\n",
|
||||
"print(\"Found best child run id: \", best_child_run_id)\n",
|
||||
"best_run = mlflow_client.get_run(best_child_run_id)\n",
|
||||
"\n",
|
||||
"# Download run's artifacts/outputs\n",
|
||||
"local_dir = \"./artifact_downloads/\"\n",
|
||||
"if not os.path.exists(local_dir):\n",
|
||||
" os.mkdir(local_dir)\n",
|
||||
"local_path = download_artifacts(\n",
|
||||
" run_id=best_run.info.run_id, artifact_path=\"outputs\", dst_path=local_dir\n",
|
||||
")\n",
|
||||
"print(\"Artifacts downloaded in: {}\".format(local_path))\n",
|
||||
"print(\"Artifacts: {}\".format(os.listdir(local_path)))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 6.3 Create and Run the Command\n",
|
||||
"Finally, we will create a command and submit the job."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"command_str = f\"python script.py --training_dataset_uri {retrain_data.path}\"\n",
|
||||
"command_job = command(\n",
|
||||
" code=\"./artifact_downloads/outputs/generated_code/\",\n",
|
||||
" command=command_str,\n",
|
||||
" tags=dict(automl_child_run_id=best_run.info.run_id),\n",
|
||||
" environment=\"AzureML-AutoML@latest\",\n",
|
||||
" compute=compute_name,\n",
|
||||
" experiment_name=exp_name,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"script_job = ml_client.create_or_update(command_job)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"After the job completes, we can download/test/deploy the model it has built."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"script_job.studio_url\n",
|
||||
"ml_client.jobs.stream(script_job.name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Next Steps\n",
|
||||
"You can see further examples of other AutoML tasks such as Image-Classification, Image-Object-Detection, NLP-Text-Classification, Time-Series-Forcasting, etc."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernel_info": {
|
||||
"name": "python3-azureml"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.10 - SDK V2",
|
||||
"language": "python",
|
||||
"name": "python310-sdkv2"
|
||||
},
|
||||
"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.10.4"
|
||||
},
|
||||
"microsoft": {
|
||||
"host": {
|
||||
"AzureML": {
|
||||
"notebookHasBeenCompleted": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"nteract": {
|
||||
"version": "nteract-front-end@1.0.0"
|
||||
},
|
||||
"vscode": {
|
||||
"interpreter": {
|
||||
"hash": "a0fdce2a800559117d1dfcce1e32c89fae80776a81d787167901ec651db4530b"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
|
@ -38,14 +38,14 @@
|
|||
"- A basic understanding of Machine Learning\n",
|
||||
"- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F)\n",
|
||||
"- An Azure ML workspace. [Check this notebook for creating a workspace](../../../resources/workspace/workspace.ipynb) \n",
|
||||
"- A Compute Cluster. [Check this notebook to create a compute cluster](../../../resources/compute/compute.ipynb)\n",
|
||||
"- Serverless compute to run the job\n",
|
||||
"- A python environment\n",
|
||||
"- Installation instructions - [install instructions](../../../README.md)\n",
|
||||
"\n",
|
||||
"**Learning Objectives** - By the end of this tutorial, you should be able to:\n",
|
||||
"- Connect to your AML workspace from the Python SDK\n",
|
||||
"- Create an `AutoML time-series forecasting Job` with the 'forecasting()' factory-fuction\n",
|
||||
"- Train the model using AmlCompute by submitting/running the AutoML forecasting training job\n",
|
||||
"- Train the model using serverless compute by submitting/running the AutoML forecasting training job\n",
|
||||
"- Obtain the model and use it to generate forecast\n",
|
||||
"\n",
|
||||
"**Motivations** - This notebook explains how to setup and run an AutoML forecasting job. This is one of the nine ML-tasks supported by AutoML. Other ML-tasks are 'regression', 'classification', 'image classification', 'image object detection', 'nlp text classification', etc.\n",
|
||||
|
@ -296,49 +296,10 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 3. Create or Attach existing AmlCompute.\n",
|
||||
"Azure Machine Learning Compute is a managed-compute infrastructure that allows the user to easily create a single or multi-node compute. In this tutorial, you will create and an AmlCompute cluster as your training compute resource.\n",
|
||||
"\n",
|
||||
"### Creation of AmlCompute takes approximately 5 minutes.\n",
|
||||
"If the AmlCompute with that name is already in your workspace this code will skip the creation process. As with other Azure services, there are limits on certain resources (e.g. AmlCompute) associated with the Azure Machine Learning service. Please read this article on the default limits and how to request more quota."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azure.core.exceptions import ResourceNotFoundError\n",
|
||||
"from azure.ai.ml.entities import AmlCompute\n",
|
||||
"\n",
|
||||
"compute_name = \"github-cluster-sdkv2\"\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # Retrieve an already attached Azure Machine Learning Compute.\n",
|
||||
" compute = ml_client.compute.get(compute_name)\n",
|
||||
"except ResourceNotFoundError as e:\n",
|
||||
" compute = AmlCompute(\n",
|
||||
" name=compute_name,\n",
|
||||
" size=\"STANDARD_DS12_V2\",\n",
|
||||
" type=\"amlcompute\",\n",
|
||||
" min_instances=0,\n",
|
||||
" max_instances=4,\n",
|
||||
" idle_time_before_scale_down=120,\n",
|
||||
" )\n",
|
||||
" poller = ml_client.begin_create_or_update(compute)\n",
|
||||
" poller.wait()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 4. Configure and run the AutoML Forecasting training job\n",
|
||||
"# 3. Configure and run the AutoML Forecasting training job\n",
|
||||
"In this section we will configure and run the AutoML job, for training the model.\n",
|
||||
"\n",
|
||||
"## 4.1 Configure the job through the forecasting() factory function\n",
|
||||
"## 3.1 Configure the job through the forecasting() factory function\n",
|
||||
"\n",
|
||||
"### forecasting() function parameters:\n",
|
||||
"\n",
|
||||
|
@ -349,7 +310,6 @@
|
|||
"|**target_column_name**|The name of the column to target for predictions. It must always be specified. This parameter is applicable to 'training_data', 'validation_data' and 'test_data'.|\n",
|
||||
"|**primary_metric**|The metric that AutoML will optimize for model selection.|\n",
|
||||
"|**training_data**|The data to be used for training. It should contain both training feature columns and a target column. Optionally, this data can be split for segregating a validation or test dataset. You can use a registered MLTable in the workspace using the format '<mltable_name>:<version>' OR you can use a local file or folder as a MLTable. For e.g Input(mltable='my_mltable:1') OR Input(mltable=MLTable(local_path=\"./data\")). The parameter 'training_data' must always be provided.\n",
|
||||
"|**compute**|The compute on which the AutoML job will run. In this example we are using a compute called 'github-cluster-sdkv2' present in the workspace. You can replace it any other compute in the workspace.|\n",
|
||||
"|**name**|The name of the Job/Run. This is an optional property. If not specified, a random name will be generated.|\n",
|
||||
"|**experiment_name**|The name of the Experiment. An Experiment is like a folder with multiple runs in Azure ML Workspace that should be related to the same logical machine learning experiment.|\n",
|
||||
"\n",
|
||||
|
@ -417,9 +377,9 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"# Create the AutoML forecasting job with the related factory-function.\n",
|
||||
"from azure.ai.ml.entities import ResourceConfiguration\n",
|
||||
"\n",
|
||||
"forecasting_job = automl.forecasting(\n",
|
||||
" compute=compute_name,\n",
|
||||
" experiment_name=exp_name,\n",
|
||||
" training_data=my_training_data_input,\n",
|
||||
" # validation_data = my_validation_data_input,\n",
|
||||
|
@ -444,6 +404,10 @@
|
|||
"# Enable Dnn training and allow only TCNForecaster model\n",
|
||||
"forecasting_job.set_training(\n",
|
||||
" allowed_training_algorithms=[\"TCNForecaster\"], enable_dnn_training=True\n",
|
||||
")\n",
|
||||
"# Serverless compute resources used to run the job\n",
|
||||
"forecasting_job.resources = ResourceConfiguration(\n",
|
||||
" instance_type=\"Standard_E4s_v3\", instance_count=4\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
|
@ -452,7 +416,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 4.2 Train the AutoML model\n",
|
||||
"## 3.2 Train the AutoML model\n",
|
||||
"Using the `MLClient` created earlier, we will now run this Command in the workspace."
|
||||
]
|
||||
},
|
||||
|
@ -484,7 +448,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 5. Retrieve the Best Trial (Best Model's trial/run)\n",
|
||||
"# 4. Retrieve the Best Trial (Best Model's trial/run)\n",
|
||||
"Use the MLFLowClient to access the results (such as Models, Artifacts, Metrics) of a previously completed AutoML Trial."
|
||||
]
|
||||
},
|
||||
|
@ -493,7 +457,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5.1 Initialize MLFlow Client\n",
|
||||
"## 4.1 Initialize MLFlow Client\n",
|
||||
"The models and artifacts that are produced by AutoML can be accessed via the MLFlow interface. \n",
|
||||
"Initialize the MLFlow client here, and set the backend as Azure ML, via. the MLFlow Client.\n",
|
||||
"\n",
|
||||
|
@ -620,7 +584,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 5.2 Get best model run's validation metrics"
|
||||
"## 4.2 Get best model run's validation metrics"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -637,9 +601,9 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 6 Model Evaluation and Deployment\n",
|
||||
"# 5 Model Evaluation and Deployment\n",
|
||||
"\n",
|
||||
"## 6.1 Download the best model\n",
|
||||
"## 5.1 Download the best model\n",
|
||||
"\n",
|
||||
"Access the results (such as Models, Artifacts, Metrics) of a previously completed AutoML Run."
|
||||
]
|
||||
|
@ -677,13 +641,49 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 6.2 Forecasting using batch endpoint\n",
|
||||
"## 5.2 Forecasting using batch endpoint\n",
|
||||
"Now that we have retrieved the best pipeline/model, it can be used to make predictions on test data. We will do batch scoring on the test dataset which must have the same schema as training dataset.\n",
|
||||
"\n",
|
||||
"The inference will run on a remote compute. In this example, it will re-use the training compute. First we will load model and environment from the local file.\n",
|
||||
"The inference will run on a remote compute. First we need to create compute and then load model and environment from the local file.\n",
|
||||
"\n",
|
||||
"### Creation of AmlCompute takes approximately 5 minutes.\n",
|
||||
"If the AmlCompute with that name is already in your workspace this code will skip the creation process. As with other Azure services, there are limits on certain resources (e.g. AmlCompute) associated with the Azure Machine Learning service. Please read this article on the default limits and how to request more quota."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azure.core.exceptions import ResourceNotFoundError\n",
|
||||
"from azure.ai.ml.entities import AmlCompute\n",
|
||||
"\n",
|
||||
"compute_name = \"github-cluster-sdkv2\"\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # Retrieve an already attached Azure Machine Learning Compute.\n",
|
||||
" compute = ml_client.compute.get(compute_name)\n",
|
||||
"except ResourceNotFoundError as e:\n",
|
||||
" compute = AmlCompute(\n",
|
||||
" name=compute_name,\n",
|
||||
" size=\"STANDARD_DS12_V2\",\n",
|
||||
" type=\"amlcompute\",\n",
|
||||
" min_instances=0,\n",
|
||||
" max_instances=4,\n",
|
||||
" idle_time_before_scale_down=120,\n",
|
||||
" )\n",
|
||||
" poller = ml_client.begin_create_or_update(compute)\n",
|
||||
" poller.wait()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Create a model endpoint\n",
|
||||
"First we need to register the model, environment and batch endpoint."
|
||||
"We need to register the model, environment and batch endpoint."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -948,7 +948,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 6.3 Deployment\n",
|
||||
"## 5.3 Deployment\n",
|
||||
"\n",
|
||||
"After we have tested our model on the batch endpoint, we may want to deploy it as a service. Currently no code deployment using mlflow is not supported for forecasting tasks and we will use the workaround which is described in the Deployment section of the [automl-forecasting-task-energy-demand](https://github.com/Azure/azureml-examples/blob/main/sdk/python/jobs/automl-standalone-jobs/automl-forecasting-task-energy-demand/automl-forecasting-task-energy-demand-advanced-mlflow.ipynb) notebook."
|
||||
]
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
"- A basic understanding of Machine Learning\n",
|
||||
"- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F)\n",
|
||||
"- An Azure ML workspace. [Check this notebook for creating a workspace](../../../resources/workspace/workspace.ipynb)\n",
|
||||
"- A Compute Cluster. [Check this notebook to create a compute cluster](../../../resources/compute/compute.ipynb)\n",
|
||||
"- A python environment\n",
|
||||
"- Installed Azure Machine Learning Python SDK v2 - [install instructions](../../../README.md) - check the getting started section\n",
|
||||
"\n",
|
||||
|
@ -389,46 +388,6 @@
|
|||
"- https://learn.microsoft.com/en-us/azure/machine-learning/how-to-create-data-assets?tabs=Python-SDK covers how to work with them in the v2 CLI/SDK."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 3 Create or Attach existing AmlCompute.\n",
|
||||
"[Azure Machine Learning Compute](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-set-up-training-targets#amlcompute) is a managed-compute infrastructure that allows the user to easily create a single or multi-node compute. In this tutorial, you create AmlCompute as your training compute resource.\n",
|
||||
"\n",
|
||||
"#### Creation of AmlCompute takes approximately 5 minutes.\n",
|
||||
"If the AmlCompute with that name is already in your workspace this code will skip the creation process.\n",
|
||||
"As with other Azure services, there are limits on certain resources (e.g. AmlCompute) associated with the Azure Machine Learning service. Please read [this article](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-quotas) on the default limits and how to request more quota."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azure.core.exceptions import ResourceNotFoundError\n",
|
||||
"from azure.ai.ml.entities import AmlCompute\n",
|
||||
"\n",
|
||||
"cluster_name = \"oj-cluster\"\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # Retrieve an already attached Azure Machine Learning Compute.\n",
|
||||
" compute = ml_client.compute.get(cluster_name)\n",
|
||||
"except ResourceNotFoundError as e:\n",
|
||||
" compute = AmlCompute(\n",
|
||||
" name=cluster_name,\n",
|
||||
" size=\"STANDARD_DS12_V2\",\n",
|
||||
" type=\"amlcompute\",\n",
|
||||
" min_instances=0,\n",
|
||||
" max_instances=4,\n",
|
||||
" idle_time_before_scale_down=120,\n",
|
||||
" )\n",
|
||||
" poller = ml_client.begin_create_or_update(compute)\n",
|
||||
" poller.wait()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
|
@ -448,7 +407,6 @@
|
|||
"|**target_column_name**|The name of the label column.|\n",
|
||||
"|**primary_metric**|This is the metric that you want to optimize.<br> Forecasting supports the following primary metrics <br><i>spearman_correlation</i><br><i>normalized_root_mean_squared_error</i><br><i>r2_score</i><br><i>normalized_mean_absolute_error</i>|\n",
|
||||
"|**training_data**|The training data to be used within the experiment. You can use a registered MLTable in the workspace using the format '<mltable_name>:<version/>' OR you can use a local file or folder as a MLTable. For e.g Input(mltable='my_mltable:1') OR Input(mltable=MLTable(local_path=\"./data\")) The parameter 'training_data' must always be provided.|\n",
|
||||
"|**compute**|The compute on which the AutoML job will run. In this example we are using a compute called 'oj-cluster' present in the workspace. You can replace it any other compute in the workspace.|\n",
|
||||
"|**n_cross_validations**|Number of cross-validation folds to use for model/pipeline selection. This can be set to \"auto\", in which case AutoMl determines the number of cross-validations automatically, if a validation set is not provided. Or users could specify an integer value.|\n",
|
||||
"|**name**|The name of the Job/Run. This is an optional property. If not specified, a random name will be generated.\n",
|
||||
"|**experiment_name**|The name of the Experiment. An Experiment is like a folder with multiple runs in Azure ML Workspace that should be related to the same logical machine learning experiment.|\n",
|
||||
|
@ -583,8 +541,9 @@
|
|||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azure.ai.ml.entities import ResourceConfiguration\n",
|
||||
"\n",
|
||||
"forecasting_job = automl.forecasting(\n",
|
||||
" compute=cluster_name,\n",
|
||||
" experiment_name=exp_name,\n",
|
||||
" training_data=my_training_data_input,\n",
|
||||
" target_column_name=target_column_name,\n",
|
||||
|
@ -617,7 +576,11 @@
|
|||
")\n",
|
||||
"\n",
|
||||
"# Training properties are optional\n",
|
||||
"forecasting_job.set_training(blocked_training_algorithms=[\"ExtremeRandomTrees\"])"
|
||||
"forecasting_job.set_training(blocked_training_algorithms=[\"ExtremeRandomTrees\"])\n",
|
||||
"# Serverless compute resources used to run the job\n",
|
||||
"forecasting_job.resources = ResourceConfiguration(\n",
|
||||
" instance_type=\"Standard_E4s_v3\", instance_count=4\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -978,6 +941,45 @@
|
|||
"To create a batch deployment, we will use the forecasting_script.py which will load the model and will call the forecast method each time we will envoke the endpoint."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Create or Attach existing AmlCompute.\n",
|
||||
"[Azure Machine Learning Compute](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-set-up-training-targets#amlcompute) is a managed-compute infrastructure that allows the user to easily create a single or multi-node compute. In this tutorial, you create AmlCompute as your training compute resource.\n",
|
||||
"\n",
|
||||
"#### Creation of AmlCompute takes approximately 5 minutes.\n",
|
||||
"If the AmlCompute with that name is already in your workspace this code will skip the creation process.\n",
|
||||
"As with other Azure services, there are limits on certain resources (e.g. AmlCompute) associated with the Azure Machine Learning service. Please read [this article](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-manage-quotas) on the default limits and how to request more quota."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azure.core.exceptions import ResourceNotFoundError\n",
|
||||
"from azure.ai.ml.entities import AmlCompute\n",
|
||||
"\n",
|
||||
"cluster_name = \"oj-cluster\"\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # Retrieve an already attached Azure Machine Learning Compute.\n",
|
||||
" compute = ml_client.compute.get(cluster_name)\n",
|
||||
"except ResourceNotFoundError as e:\n",
|
||||
" compute = AmlCompute(\n",
|
||||
" name=cluster_name,\n",
|
||||
" size=\"STANDARD_DS12_V2\",\n",
|
||||
" type=\"amlcompute\",\n",
|
||||
" min_instances=0,\n",
|
||||
" max_instances=4,\n",
|
||||
" idle_time_before_scale_down=120,\n",
|
||||
" )\n",
|
||||
" poller = ml_client.begin_create_or_update(compute)\n",
|
||||
" poller.wait()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
|
|
@ -0,0 +1,275 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Build Pipeline with Components from yaml\n",
|
||||
"\n",
|
||||
"**Requirements** - In order to benefit from this tutorial, you will need:\n",
|
||||
"- A basic understanding of Machine Learning\n",
|
||||
"- An Azure account with an active subscription - [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F)\n",
|
||||
"- This pipeline job will use **Serverless Compute** to execute the job. You do not need to create and manage compute anymore to run the job\n",
|
||||
"- A python environment\n",
|
||||
"- Installed Azure Machine Learning Python SDK v2 - [install instructions](../../../README.md) - check the getting started section\n",
|
||||
"\n",
|
||||
"**Learning Objectives** - By the end of this tutorial, you should be able to:\n",
|
||||
"- Connect to your AML workspace from the Python SDK\n",
|
||||
"- Define and load `CommandComponent` from YAML\n",
|
||||
"- Create `Pipeline` using loaded component.\n",
|
||||
"\n",
|
||||
"**Motivations** - This notebook covers the scenario that user define components using yaml then use these components to build pipeline."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 1. Connect to Azure Machine Learning Workspace\n",
|
||||
"\n",
|
||||
"The [workspace](https://docs.microsoft.com/en-us/azure/machine-learning/concept-workspace) is the top-level resource for Azure Machine Learning, providing a centralized place to work with all the artifacts you create when you use Azure Machine Learning. In this section we will connect to the workspace in which the job will be run.\n",
|
||||
"\n",
|
||||
"## 1.1 Import the required libraries"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Import required libraries\n",
|
||||
"from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential\n",
|
||||
"\n",
|
||||
"from azure.ai.ml import MLClient, Input\n",
|
||||
"from azure.ai.ml.dsl import pipeline\n",
|
||||
"from azure.ai.ml import load_component"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1.2 Configure credential\n",
|
||||
"\n",
|
||||
"We are using `DefaultAzureCredential` to get access to workspace. \n",
|
||||
"`DefaultAzureCredential` should be capable of handling most Azure SDK authentication scenarios. \n",
|
||||
"\n",
|
||||
"Reference for more available credentials if it does not work for you: [configure credential example](../../configuration.ipynb), [azure-identity reference doc](https://docs.microsoft.com/en-us/python/api/azure-identity/azure.identity?view=azure-python)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"try:\n",
|
||||
" credential = DefaultAzureCredential()\n",
|
||||
" # Check if given credential can get token successfully.\n",
|
||||
" credential.get_token(\"https://management.azure.com/.default\")\n",
|
||||
"except Exception as ex:\n",
|
||||
" # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work\n",
|
||||
" credential = InteractiveBrowserCredential()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 1.3 Get a handle to the workspace\n",
|
||||
"\n",
|
||||
"We use config file to connect to a workspace. The Azure ML workspace should be configured with computer cluster. [Check this notebook for configure a workspace](../../configuration.ipynb)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 2. Define and create components into workspace\n",
|
||||
"## 2.1 Load components from YAML"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"parent_dir = \".\"\n",
|
||||
"train_model = load_component(source=parent_dir + \"/train_model.yml\")\n",
|
||||
"score_data = load_component(source=parent_dir + \"/score_data.yml\")\n",
|
||||
"eval_model = load_component(source=parent_dir + \"/eval_model.yml\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 2.2 Inspect loaded component"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Print the component as yaml\n",
|
||||
"print(train_model)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Inspect more information\n",
|
||||
"print(type(train_model))\n",
|
||||
"help(train_model._func)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# 3. Sample pipeline job\n",
|
||||
"## 3.1 Build pipeline"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {"name": "build-pipeline"},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Construct pipeline\n",
|
||||
"@pipeline()\n",
|
||||
"def pipeline_with_components_from_yaml(\n",
|
||||
" training_input,\n",
|
||||
" test_input,\n",
|
||||
" training_max_epochs=20,\n",
|
||||
" training_learning_rate=1.8,\n",
|
||||
" learning_rate_schedule=\"time-based\",\n",
|
||||
"):\n",
|
||||
" \"\"\"E2E dummy train-score-eval pipeline with components defined via yaml.\"\"\"\n",
|
||||
" # Call component obj as function: apply given inputs & parameters to create a node in pipeline\n",
|
||||
" train_with_sample_data = train_model(\n",
|
||||
" training_data=training_input,\n",
|
||||
" max_epochs=training_max_epochs,\n",
|
||||
" learning_rate=training_learning_rate,\n",
|
||||
" learning_rate_schedule=learning_rate_schedule,\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" score_with_sample_data = score_data(\n",
|
||||
" model_input=train_with_sample_data.outputs.model_output, test_data=test_input\n",
|
||||
" )\n",
|
||||
" score_with_sample_data.outputs.score_output.mode = \"upload\"\n",
|
||||
"\n",
|
||||
" eval_with_sample_data = eval_model(\n",
|
||||
" scoring_result=score_with_sample_data.outputs.score_output\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Return: pipeline outputs\n",
|
||||
" return {\n",
|
||||
" \"trained_model\": train_with_sample_data.outputs.model_output,\n",
|
||||
" \"scored_data\": score_with_sample_data.outputs.score_output,\n",
|
||||
" \"evaluation_report\": eval_with_sample_data.outputs.eval_output,\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"pipeline_job = pipeline_with_components_from_yaml(\n",
|
||||
" training_input=Input(type=\"uri_folder\", path=parent_dir + \"/data/\"),\n",
|
||||
" test_input=Input(type=\"uri_folder\", path=parent_dir + \"/data/\"),\n",
|
||||
" training_max_epochs=20,\n",
|
||||
" training_learning_rate=1.8,\n",
|
||||
" learning_rate_schedule=\"time-based\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# set pipeline to use serverless compute\n",
|
||||
"pipeline_job.settings.default_compute = \"serverless\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Inspect built pipeline\n",
|
||||
"print(pipeline_job)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 3.2 Submit pipeline job"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Submit pipeline job to workspace\n",
|
||||
"pipeline_job = ml_client.jobs.create_or_update(\n",
|
||||
" pipeline_job, experiment_name=\"pipeline_samples\"\n",
|
||||
")\n",
|
||||
"pipeline_job"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Wait until the job completes\n",
|
||||
"ml_client.jobs.stream(pipeline_job.name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Next Steps\n",
|
||||
"You can see further examples of running a pipeline job [here](../README.md)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"description": {
|
||||
"description": "Create pipeline with CommandComponents from local YAML file"
|
||||
},
|
||||
"interpreter": {
|
||||
"hash": "3e9e0e270b75c5e6da2e22113ba4f77b864d68f95da6601809c29e46c73ae6bb"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.10 - SDK V2",
|
||||
"language": "python",
|
||||
"name": "python310-sdkv2"
|
||||
},
|
||||
"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.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
|
@ -8,16 +8,16 @@
|
|||
"\n",
|
||||
"Learn how a data scientist uses Azure Machine Learning (Azure ML) to train a model, then use the model for prediction. This tutorial will help you become familiar with the core concepts of Azure ML and their most common usage. \n",
|
||||
"\n",
|
||||
"You'll learn how to submit a *command job* to run your *training script* on a specified *compute resource*, configured with the *job environment* necessary to run the script.\n",
|
||||
"You'll learn how to submit a *command job* to run your *training script*, configured with the *job environment* necessary to run the script.\n",
|
||||
"\n",
|
||||
"The training script handles the data preparation, then trains and registers a model. Once you have the model, you'll *deploy* it as an *endpoint*, then call the endpoint for *inferencing*.\n",
|
||||
"\n",
|
||||
"The steps you'll take are:\n",
|
||||
"\n",
|
||||
"> * Connect to your Azure ML workspace\n",
|
||||
"> * Create your compute resource and job environment\n",
|
||||
"> * Create your job environment\n",
|
||||
"> * Create your training script\n",
|
||||
"> * Create and run your command job to run the training script on the compute resource, configured with the appropriate job environment\n",
|
||||
"> * Create and run your command job to run the training script, configured with the appropriate job environment\n",
|
||||
"> * View the output of your training script\n",
|
||||
"> * Deploy the newly-trained model as an endpoint\n",
|
||||
"> * Call the Azure ML endpoint for inferencing"
|
||||
|
@ -125,66 +125,7 @@
|
|||
"The result is a handler to the workspace that you'll use to manage other resources and jobs.\n",
|
||||
"\n",
|
||||
"> [!IMPORTANT]\n",
|
||||
"> Creating MLClient will not connect to the workspace. The client initialization is lazy, it will wait for the first time it needs to make a call (in the notebook below, that will happen during compute creation)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Create a compute resource to run your job\n",
|
||||
"\n",
|
||||
"You already have a compute resource you're using to run the notebook. But now you'll add another type, a **compute cluster** that you'll use to run your training job. The compute cluster can be single or multi-node machines with Linux or Windows OS, or a specific compute fabric like Spark.\n",
|
||||
"\n",
|
||||
"You'll provision a Linux compute cluster. See the [full list on VM sizes and prices](https://azure.microsoft.com/pricing/details/machine-learning/) .\n",
|
||||
"\n",
|
||||
"For this example, you only need a basic cluster, so you'll use a Standard_DS3_v2 model with 2 vCPU cores, 7-GB RAM."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"name": "cpu_compute_target"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azure.ai.ml.entities import AmlCompute\n",
|
||||
"\n",
|
||||
"# Name assigned to the compute cluster\n",
|
||||
"cpu_compute_target = \"cpu-cluster\"\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # let's see if the compute target already exists\n",
|
||||
" cpu_cluster = ml_client.compute.get(cpu_compute_target)\n",
|
||||
" print(\n",
|
||||
" f\"You already have a cluster named {cpu_compute_target}, we'll reuse it as is.\"\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"except Exception:\n",
|
||||
" print(\"Creating a new cpu compute target...\")\n",
|
||||
"\n",
|
||||
" # Let's create the Azure ML compute object with the intended parameters\n",
|
||||
" cpu_cluster = AmlCompute(\n",
|
||||
" name=cpu_compute_target,\n",
|
||||
" # Azure ML Compute is the on-demand VM service\n",
|
||||
" type=\"amlcompute\",\n",
|
||||
" # VM Family\n",
|
||||
" size=\"STANDARD_DS3_V2\",\n",
|
||||
" # Minimum running nodes when there is no job running\n",
|
||||
" min_instances=0,\n",
|
||||
" # Nodes in cluster\n",
|
||||
" max_instances=4,\n",
|
||||
" # How many seconds will the node running after the job termination\n",
|
||||
" idle_time_before_scale_down=180,\n",
|
||||
" # Dedicated or LowPriority. The latter is cheaper but there is a chance of job termination\n",
|
||||
" tier=\"Dedicated\",\n",
|
||||
" )\n",
|
||||
" print(\n",
|
||||
" f\"AMLCompute with name {cpu_cluster.name} will be created, with compute size {cpu_cluster.size}\"\n",
|
||||
" )\n",
|
||||
" # Now, we pass the object to MLClient's create_or_update method\n",
|
||||
" cpu_cluster = ml_client.compute.begin_create_or_update(cpu_cluster)"
|
||||
"> Creating MLClient will not connect to the workspace. The client initialization is lazy, it will wait for the first time it needs to make a call (in the notebook below, that will happen during job environment creation)."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -193,7 +134,7 @@
|
|||
"source": [
|
||||
"## Create a job environment\n",
|
||||
"\n",
|
||||
"To run your AzureML job on your compute cluster, you'll need an [environment](https://docs.microsoft.com/azure/machine-learning/concept-environments). An environment lists the software runtime and libraries that you want installed on the compute where you’ll be training. It's similar to your Python environment on your local machine.\n",
|
||||
"To run your AzureML job, you'll need an [environment](https://docs.microsoft.com/azure/machine-learning/concept-environments). An environment lists the software runtime and libraries that you want installed on the compute where you’ll be training. It's similar to your Python environment on your local machine.\n",
|
||||
"\n",
|
||||
"AzureML provides many curated or ready-made environments, which are useful for common training and inference scenarios. You can also create your own custom environments using a docker image, or a conda configuration.\n",
|
||||
"\n",
|
||||
|
@ -295,7 +236,7 @@
|
|||
"source": [
|
||||
"## What is a command job?\n",
|
||||
"\n",
|
||||
"You'll create an Azure ML *command job* to train a model for credit default prediction. The command job is used to run a *training script* in a specified environment on a specified compute resource. You've already created the environment and the compute resource. Next you'll create the training script.\n",
|
||||
"You'll create an Azure ML *command job* to train a model for credit default prediction. The command job is used to run a *training script* in a specified environment on serverless compute. You've already created the environment. Next you'll create the training script.\n",
|
||||
"\n",
|
||||
"The *training script* handles the data preparation, training and registering of the trained model. In this tutorial, you'll create a Python training script.\n",
|
||||
"\n",
|
||||
|
@ -470,7 +411,6 @@
|
|||
"Now that you have a script that can perform the desired tasks, you'll use the general purpose **command** that can run command line actions. This command line action can be directly calling system commands or by running a script. \n",
|
||||
"\n",
|
||||
"Here, you'll create input variables to specify the input data, split ratio, learning rate and registered model name. The command script will:\n",
|
||||
"* Use the compute created earlier to run this command.\n",
|
||||
"* Use the environment created earlier - you can use the `@latest` notation to indicate the latest version of the environment when the command is run.\n",
|
||||
"* Configure some metadata like display name, experiment name etc. An *experiment* is a container for all the iterations you do on a certain project. All the jobs submitted under the same experiment name would be listed next to each other in Azure ML studio.\n",
|
||||
"* Configure the command line action itself - `python main.py` in this case. The inputs/outputs are accessible in the command via the `${{ ... }}` notation.\n",
|
||||
|
@ -503,7 +443,6 @@
|
|||
" code=\"./src/\", # location of source code\n",
|
||||
" command=\"python main.py --data ${{inputs.data}} --test_train_ratio ${{inputs.test_train_ratio}} --learning_rate ${{inputs.learning_rate}} --registered_model_name ${{inputs.registered_model_name}}\",\n",
|
||||
" environment=\"aml-scikit-learn@latest\",\n",
|
||||
" compute=\"cpu-cluster\",\n",
|
||||
" experiment_name=\"train_model_credit_default_prediction\",\n",
|
||||
" display_name=\"credit_default_prediction\",\n",
|
||||
")"
|
||||
|
@ -542,7 +481,7 @@
|
|||
"![Screenshot that shows the job overview](media/view-job.gif \"View the job in studio\")\n",
|
||||
"\n",
|
||||
"> [!IMPORTANT]\n",
|
||||
"> Wait until the status of the job is complete before returning to this notebook to continue. The job will take 2 to 3 minutes to run. It could take longer (up to 10 minutes) if the compute cluster has been scaled down to zero nodes and custom environment is still building.\n",
|
||||
"> Wait until the status of the job is complete before returning to this notebook to continue. The job will take 2 to 3 minutes to run. It could take longer (up to 10 minutes) if the compute has been scaled down to zero nodes and custom environment is still building.\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -85,7 +85,6 @@
|
|||
"\n",
|
||||
"* The dataset for training\n",
|
||||
"* The software environment to run the pipeline\n",
|
||||
"* A compute resource to where the job will run\n",
|
||||
"\n",
|
||||
"## Connect to the workspace\n",
|
||||
"\n",
|
||||
|
@ -237,69 +236,6 @@
|
|||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In the future, you can fetch the same dataset from the workspace using `credit_dataset = ml_client.data.get(\"<DATA ASSET NAME>\", version='<VERSION>')`.\n",
|
||||
"\n",
|
||||
"## Create a Compute Resource to run our pipeline\n",
|
||||
"\n",
|
||||
"Each step of an Azure ML pipeline can use a different compute resource for running the specific job of that step. It can be single or multi-node machines with Linux or Windows OS, or a specific compute fabric like Spark.\n",
|
||||
"\n",
|
||||
"In this section, we provision a Linux [compute cluster](https://docs.microsoft.com/azure/machine-learning/how-to-create-attach-compute-cluster?tabs=python). See the [full list on VM sizes and prices](https://azure.microsoft.com/en-ca/pricing/details/machine-learning/) .\n",
|
||||
"\n",
|
||||
"For this tutorial we only need a basic cluster, let's pick a Standard_DS3_v2 model with 2 vCPU cores, 7 GB RAM and create an Azure ML Compute"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"name": "cpu_cluster"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azure.ai.ml.entities import AmlCompute\n",
|
||||
"\n",
|
||||
"cpu_compute_target = \"cpu-cluster\"\n",
|
||||
"\n",
|
||||
"try:\n",
|
||||
" # let's see if the compute target already exists\n",
|
||||
" cpu_cluster = ml_client.compute.get(cpu_compute_target)\n",
|
||||
" print(\n",
|
||||
" f\"You already have a cluster named {cpu_compute_target}, we'll reuse it as is.\"\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"except Exception:\n",
|
||||
" print(\"Creating a new cpu compute target...\")\n",
|
||||
"\n",
|
||||
" # Let's create the Azure ML compute object with the intended parameters\n",
|
||||
" cpu_cluster = AmlCompute(\n",
|
||||
" # Name assigned to the compute cluster\n",
|
||||
" name=\"cpu-cluster\",\n",
|
||||
" # Azure ML Compute is the on-demand VM service\n",
|
||||
" type=\"amlcompute\",\n",
|
||||
" # VM Family\n",
|
||||
" size=\"STANDARD_DS3_V2\",\n",
|
||||
" # Minimum running nodes when there is no job running\n",
|
||||
" min_instances=0,\n",
|
||||
" # Nodes in cluster\n",
|
||||
" max_instances=4,\n",
|
||||
" # How many seconds will the node running after the job termination\n",
|
||||
" idle_time_before_scale_down=180,\n",
|
||||
" # Dedicated or LowPriority. The latter is cheaper but there is a chance of job termination\n",
|
||||
" tier=\"Dedicated\",\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" # Now, we pass the object to MLClient's create_or_update method\n",
|
||||
" cpu_cluster = ml_client.begin_create_or_update(cpu_cluster)\n",
|
||||
"\n",
|
||||
"print(\n",
|
||||
" f\"AMLCompute with name {cpu_cluster.name} is created, the compute size is {cpu_cluster.size}\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
|
@ -889,7 +825,7 @@
|
|||
"source": [
|
||||
"The python functions returned by `load_component()` work as any regular python function that we'll use within a pipeline to call each step.\n",
|
||||
"\n",
|
||||
"To code the pipeline, we use a specific `@dsl.pipeline` decorator that identifies the Azure ML pipelines. In the decorator, we can specify the pipeline description and default resources like compute and storage. Like a python function, pipelines can have inputs, you can then create multiple instances of a single pipeline with different inputs.\n",
|
||||
"To code the pipeline, we use a specific `@dsl.pipeline` decorator that identifies the Azure ML pipelines. In the decorator, we can specify the pipeline description and default resources like compute (serverless is used here) and storage. Like a python function, pipelines can have inputs, you can then create multiple instances of a single pipeline with different inputs.\n",
|
||||
"\n",
|
||||
"Here, we used *input data*, *split ratio* and *registered model name* as input variables. We then call the components and connect them via their inputs /outputs identifiers. The outputs of each step can be accessed via the `.outputs` property."
|
||||
]
|
||||
|
@ -913,7 +849,7 @@
|
|||
"\n",
|
||||
"\n",
|
||||
"@dsl.pipeline(\n",
|
||||
" compute=cpu_compute_target,\n",
|
||||
" compute=\"serverless\",\n",
|
||||
" description=\"E2E data_perp-train pipeline\",\n",
|
||||
")\n",
|
||||
"def credit_defaults_pipeline(\n",
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -17,7 +17,7 @@
|
|||
"\n",
|
||||
"> * Set up a handle to your Azure Machine Learning workspace\n",
|
||||
"> * Create your training script\n",
|
||||
"> * Create a scalable compute resource, a compute cluster \n",
|
||||
"> * Create a scalable compute resource, a compute cluster or use **serverless compute (preview)** instead\n",
|
||||
"> * Create and run a command job that will run the training script on the compute cluster, configured with the appropriate job environment\n",
|
||||
"> * View the output of your training script\n",
|
||||
"> * Deploy the newly-trained model as an endpoint\n",
|
||||
|
@ -273,6 +273,8 @@
|
|||
"\n",
|
||||
"## Create a compute cluster, a scalable way to run a training job\n",
|
||||
"\n",
|
||||
"You can **skip this step** if you want to use **serverless compute** to run the training job. Through serverless compute, Azure Machine Learning takes care of creating, scaling, deleting, patching and managing compute, along with providing managed network isolation, reducing the burden on you. \n",
|
||||
"\n",
|
||||
"You already have a compute instance, which you're using to run the notebook. Now you'll add a second type of compute, a **compute cluster** that you'll use to run your training job. While a compute instance is a single node machine, a compute cluster can be single or multi-node machines with Linux or Windows OS, or a specific compute fabric like Spark.\n",
|
||||
"\n",
|
||||
"You'll provision a Linux compute cluster. See the [full list on VM sizes and prices](https://azure.microsoft.com/pricing/details/machine-learning/) .\n",
|
||||
|
@ -336,7 +338,7 @@
|
|||
"Now that you have a script that can perform the desired tasks, and a compute cluster to run the script, you'll use a general purpose **command** that can run command line actions. This command line action can directly call system commands or run a script. \n",
|
||||
"\n",
|
||||
"Here, you'll create input variables to specify the input data, split ratio, learning rate and registered model name. The command script will:\n",
|
||||
"* Use the compute cluster to run the command.\n",
|
||||
"* Use the compute cluster to run the command or just **remove the compute line to use serverless compute**.\n",
|
||||
"* Use an *environment* that defines software and runtime libraries needed for the training script. Azure Machine Learning provides many curated or ready-made environments, which are useful for common training and inference scenarios. You'll use one of those environments here. In the [Train a model](train-model.ipynb) tutorial, you'll learn how to create a custom environment. \n",
|
||||
"* Configure the command line action itself - `python main.py` in this case. The inputs/outputs are accessible in the command via the `${{ ... }}` notation.\n",
|
||||
"* In this sample, we access the data from a file on the internet. "
|
||||
|
@ -371,7 +373,7 @@
|
|||
" code=\"./src/\", # location of source code\n",
|
||||
" command=\"python main.py --data ${{inputs.data}} --test_train_ratio ${{inputs.test_train_ratio}} --learning_rate ${{inputs.learning_rate}} --registered_model_name ${{inputs.registered_model_name}}\",\n",
|
||||
" environment=\"AzureML-sklearn-1.0-ubuntu20.04-py38-cpu@latest\",\n",
|
||||
" compute=\"cpu-cluster\",\n",
|
||||
" compute=\"cpu-cluster\", # you can remove this line to use serverless compute\n",
|
||||
" display_name=\"credit_default_prediction\",\n",
|
||||
")"
|
||||
]
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче