From 80bba4c7ae1f08f537dd88347c0a452ae8f71bdb Mon Sep 17 00:00:00 2001 From: Sheri Gilley Date: Thu, 3 Jan 2019 18:55:31 -0600 Subject: [PATCH] code for amlcompute section --- .../amlcompute.py | 48 +++++++++++++ .../amlcompute2.py | 72 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 ignore/doc-qa/how-to-set-up-training-targets/amlcompute.py create mode 100644 ignore/doc-qa/how-to-set-up-training-targets/amlcompute2.py diff --git a/ignore/doc-qa/how-to-set-up-training-targets/amlcompute.py b/ignore/doc-qa/how-to-set-up-training-targets/amlcompute.py new file mode 100644 index 00000000..7ab08e69 --- /dev/null +++ b/ignore/doc-qa/how-to-set-up-training-targets/amlcompute.py @@ -0,0 +1,48 @@ +# Code for Azure Machine Learning Compute - Run-based creation + +# Check core SDK version number +import azureml.core + +print("SDK version:", azureml.core.VERSION) + + +from azureml.core import Workspace +ws = Workspace.from_config() + + +# Set up an experiment +from azureml.core import Experiment +experiment_name = 'my-experiment' +script_folder= "./" + +exp = Experiment(workspace=ws, name=experiment_name) + + +# +from azureml.core.compute import ComputeTarget, AmlCompute + +# First, list the supported VM families for Azure Machine Learning Compute +print(AmlCompute.supported_vmsizes(workspace=ws)) + +from azureml.core.runconfig import RunConfiguration +# Create a new runconfig object +run_temp_compute = RunConfiguration() + +# Signal that you want to use AmlCompute to execute the script +run_temp_compute.target = "amlcompute" + +# AmlCompute is created in the same region as your workspace +# Set the VM size for AmlCompute from the list of supported_vmsizes +run_temp_compute.amlcompute.vm_size = 'STANDARD_D2_V2' +# + + +# Submit the experiment using the run configuration +from azureml.core import ScriptRunConfig + +src = ScriptRunConfig(source_directory = script_folder, script = 'train.py', run_config = run_temp_compute) +run = exp.submit(src) +run.wait_for_completion(show_output = True) + + + diff --git a/ignore/doc-qa/how-to-set-up-training-targets/amlcompute2.py b/ignore/doc-qa/how-to-set-up-training-targets/amlcompute2.py new file mode 100644 index 00000000..f8fc9d08 --- /dev/null +++ b/ignore/doc-qa/how-to-set-up-training-targets/amlcompute2.py @@ -0,0 +1,72 @@ +# Code for Azure Machine Learning Compute - Persistent compute + +# Check core SDK version number +import azureml.core + +print("SDK version:", azureml.core.VERSION) + +from azureml.core import Workspace +ws = Workspace.from_config() + + +# Set up an experiment +from azureml.core import Experiment +experiment_name = 'my-experiment' +script_folder= "./" + +exp = Experiment(workspace=ws, name=experiment_name) + +# +from azureml.core.compute import ComputeTarget, AmlCompute +from azureml.core.compute_target import ComputeTargetException + +# Choose a name for your CPU cluster +cpu_cluster_name = "cpucluster" + +# Verify that cluster does not exist already +try: + cpu_cluster = ComputeTarget(workspace=ws, name=cpu_cluster_name) + print('Found existing cluster, use it.') +except ComputeTargetException: + compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_D2_V2', + max_nodes=4) + cpu_cluster = ComputeTarget.create(ws, cpu_cluster_name, compute_config) + +cpu_cluster.wait_for_completion(show_output=True) +# + +# +from azureml.core.runconfig import RunConfiguration +from azureml.core.conda_dependencies import CondaDependencies +from azureml.core.runconfig import DEFAULT_CPU_IMAGE + +# Create a new runconfig object +run_amlcompute = RunConfiguration() + +# Use the cpu_cluster you created above. +run_amlcompute.target = cpu_cluster + +# Enable Docker +run_amlcompute.environment.docker.enabled = True + +# Set Docker base image to the default CPU-based image +run_amlcompute.environment.docker.base_image = DEFAULT_CPU_IMAGE + +# Use conda_dependencies.yml to create a conda environment in the Docker image for execution +run_amlcompute.environment.python.user_managed_dependencies = False + +# Auto-prepare the Docker image when used for execution (if it is not already prepared) +run_amlcompute.auto_prepare_environment = True + +# Specify CondaDependencies obj, add necessary packages +run_amlcompute.environment.python.conda_dependencies = CondaDependencies.create(conda_packages=['scikit-learn']) +# + +# Submit the experiment using the run configuration +# +from azureml.core import ScriptRunConfig + +src = ScriptRunConfig(source_directory = script_folder, script = 'train.py', run_config = run_amlcompute) +run = exp.submit(src) +run.wait_for_completion(show_output = True) +#