Created
July 5, 2022 03:50
-
-
Save IntegerMan/f92a182dfda7d5241a2907d9a5d9b6ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from azureml.core import Workspace | |
from azureml.core.compute import ComputeTarget, AmlCompute | |
from azureml.core.compute_target import ComputeTargetException | |
# Load the workspace from config.json | |
ws = Workspace.from_config() | |
# Now let's make sure we have a compute resource | |
cluster_name = "My-Cluster" | |
# 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...') | |
max_nodes = 4 | |
sku = 'Standard_D2DS_V4' | |
compute_config = AmlCompute.provisioning_configuration(vm_size=sku, min_nodes=0, 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