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