code for amlcompute section

This commit is contained in:
Sheri Gilley
2019-01-03 18:55:31 -06:00
parent 3c581b533f
commit 80bba4c7ae
2 changed files with 120 additions and 0 deletions

View File

@@ -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)
#<amlcompute_temp>
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'
#</amlcompute_temp>
# 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)

View File

@@ -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)
#<cpu_basic>
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)
#</cpu_basic>
#<aml_runconfig>
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'])
#</aml_runconfig>
# Submit the experiment using the run configuration
#<amlcompute_submit>
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)
#</amlcompute_submit>