Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from azureml.core.compute import ComputeTarget, AmlCompute
from azureml.core.compute_target import ComputeTargetException
# Now let's make sure we have a compute resource created
cluster_name = "My-Cluster" # The name of the cluster
vm_size = 'Standard_D2DS_V4' # There are many different specs available for CPU or GPU tasks.
min_nodes = 0 # This is important to prevent billing while idle
max_nodes = 4 # Azure does limit you to a certain quota, but you can get that extended
# Fetch or create the compute resource
try:
cpu_cluster = ComputeTarget(workspace=ws, name=cluster_name) # This will throw a ComputeTargetException if this doesn't exist
print('Using existing compute: ' + cluster_name)
except ComputeTargetException:
# Create the cluster
print('Provisioning cluster...')
compute_config = AmlCompute.provisioning_configuration(vm_size=vm_size, min_nodes=min_nodes, max_nodes=max_nodes)
cpu_cluster = ComputeTarget.create(ws, cluster_name, compute_config)
# Ensure the cluster is ready to go
cpu_cluster.wait_for_completion(show_output=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment