forked from Azure/azureml-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-workspace.py
112 lines (103 loc) · 3.39 KB
/
setup-workspace.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# imports
import argparse
from azureml.core import Workspace
from azureml.core.compute import ComputeTarget, AmlCompute, AksCompute
# setup argparse
parser = argparse.ArgumentParser()
parser.add_argument("--config", type=str, default="")
parser.add_argument("--subscription-id", type=str, default=None)
parser.add_argument("--workspace-name", type=str, default="main-python-sdk")
parser.add_argument("--resource-group", type=str, default="azureml-examples-rg")
parser.add_argument("--location", type=str, default="eastus")
parser.add_argument("--create-aks", type=bool, default=False)
parser.add_argument("--create-V100", type=bool, default=False)
args = parser.parse_args()
# constants, variables, parameters, etc.
amlcomputes = {
"cpu-cluster": {
"vm_size": "STANDARD_DS3_V2",
"min_nodes": 0,
"max_nodes": 10,
"idle_seconds_before_scaledown": 1200,
},
"cpu-cluster-ds12": {
"vm_size": "STANDARD_DS12_V2",
"min_nodes": 0,
"max_nodes": 10,
"idle_seconds_before_scaledown": 1200,
},
"gpu-cluster": {
"vm_size": "STANDARD_NC6",
"min_nodes": 0,
"max_nodes": 4,
"idle_seconds_before_scaledown": 1200,
},
"gpu-K80-2": {
"vm_size": "STANDARD_NC12",
"min_nodes": 0,
"max_nodes": 4,
"idle_seconds_before_scaledown": 1200,
},
}
v100computes = {
"gpu-V100-1": {
"vm_size": "STANDARD_NC6S_V3",
"min_nodes": 0,
"max_nodes": 4,
"idle_seconds_before_scaledown": 1200,
},
"gpu-V100-2": {
"vm_size": "STANDARD_NC12S_V3",
"min_nodes": 0,
"max_nodes": 2,
"idle_seconds_before_scaledown": 1200,
},
"gpu-V100-4": {
"vm_size": "STANDARD_NC24S_V3",
"min_nodes": 0,
"max_nodes": 2,
"idle_seconds_before_scaledown": 1200,
},
}
akscomputes = {
"aks-cpu-deploy": {"vm_size": "STANDARD_DS3_V2", "agent_count": 3},
"aks-gpu-deploy": {"vm_size": "STANDARD_NC6S_V3", "agent_count": 3},
}
# create or get Workspace
try:
ws = Workspace.from_config(args.config)
except:
ws = Workspace.create(
args.workspace_name,
subscription_id=args.subscription_id,
resource_group=args.resource_group,
location=args.location,
create_resource_group=True,
exist_ok=True,
show_output=True,
)
ws.write_config()
# create aml compute targets
for ct_name in amlcomputes:
if ct_name not in ws.compute_targets:
compute_config = AmlCompute.provisioning_configuration(**amlcomputes[ct_name])
ct = ComputeTarget.create(ws, ct_name, compute_config)
ct.wait_for_completion(show_output=True)
# create aml V100 compute targets
if args.create_V100:
for ct_name in v100computes:
if ct_name not in ws.compute_targets:
compute_config = AmlCompute.provisioning_configuration(
**v100computes[ct_name]
)
ct = ComputeTarget.create(ws, ct_name, compute_config)
ct.wait_for_completion(show_output=True)
# create aks compute targets
if args.create_aks:
for ct_name in akscomputes:
if ct_name not in ws.compute_targets:
compute_config = AksCompute.provisioning_configuration(
**akscomputes[ct_name]
)
ct = ComputeTarget.create(ws, ct_name, compute_config)
ct.wait_for_completion(show_output=True)