[59e0da]: / utils / attach_compute.py

Download this file

35 lines (33 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from azureml.core import Workspace
from azureml.exceptions import ComputeTargetException
from azureml.core.compute import ComputeTarget, DatabricksCompute, AmlCompute
def get_compute_aml(
workspace: Workspace,
compute_name: str,
vm_size: str
):
try:
if compute_name in workspace.compute_targets:
compute_target = workspace.compute_targets[compute_name]
if compute_target and type(compute_target) is AmlCompute:
print('Found existing compute target ' + compute_name
+ ' so using it.')
else:
compute_config = AmlCompute.provisioning_configuration(
vm_size=vm_size,
vm_priority="lowpriority",
min_nodes=int(0),
max_nodes=int(4),
idle_seconds_before_scaledown="300"
)
compute_target = ComputeTarget.create(workspace, compute_name,
compute_config)
compute_target.wait_for_completion(
show_output=True,
min_node_count=None,
timeout_in_minutes=10)
return compute_target
except ComputeTargetException as e:
print(e)
print('An error occurred trying to provision compute.')
exit()