Skip to content

Instantly share code, notes, and snippets.

@IntegerMan
Created July 19, 2022 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IntegerMan/316daa10a7e15644664c821ddf295efd to your computer and use it in GitHub Desktop.
Save IntegerMan/316daa10a7e15644664c821ddf295efd to your computer and use it in GitHub Desktop.
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