-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathpipelines_master.py
208 lines (174 loc) · 6.14 KB
/
pipelines_master.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import json
import os
import shutil
from utils import disable_pipeline
from azureml.core import Workspace, Environment
from azureml.core.authentication import ServicePrincipalAuthentication
from azureml.core.compute import AmlCompute, ComputeTarget
from azureml.core.runconfig import (
CondaDependencies,
RunConfiguration
)
from azureml.core.runconfig import DEFAULT_GPU_IMAGE
from azureml.pipeline.core import Pipeline
from azureml.pipeline.steps import PythonScriptStep
from azureml.pipeline.core.schedule import Schedule
from azureml.core import VERSION
print("azureml.core.VERSION", VERSION)
base_dir = "."
config_json = os.path.join(base_dir, "config.json")
with open(config_json, "r") as f:
config = json.load(f)
auth = ServicePrincipalAuthentication(
tenant_id=config["tenant_id"],
service_principal_id=config["service_principal_id"],
service_principal_password=config["service_principal_password"],
)
ws = Workspace(
config["subscription_id"],
config["resource_group"],
config["workspace_name"],
auth=auth
)
print(ws.get_details)
keyvault = ws.get_default_keyvault()
keyvault.set_secret("tenantID", config["tenant_id"])
keyvault.set_secret("servicePrincipalId", config["service_principal_id"])
keyvault.set_secret(
"servicePrincipalPassword",
config["service_principal_password"])
# folder for scripts that need to be uploaded to Aml compute target
script_folder = "./scripts/"
if os.path.exists(script_folder):
print("Deleting:", script_folder)
shutil.rmtree(script_folder)
os.makedirs(script_folder)
shutil.copy(os.path.join(base_dir, "utils.py"), script_folder)
shutil.copy(os.path.join(base_dir, "pipelines_slave.py"), script_folder)
shutil.copy(os.path.join(base_dir, "train.py"), script_folder)
shutil.copytree(
os.path.join(base_dir, "models"),
os.path.join(base_dir, script_folder, "models"))
shutil.copy(os.path.join(base_dir, "data_preparation.py"), script_folder)
shutil.copy(os.path.join(base_dir, "register_prednet.py"), script_folder)
shutil.copy(os.path.join(base_dir, "batch_scoring.py"), script_folder)
shutil.copy(os.path.join(base_dir, "train_clf.py"), script_folder)
shutil.copy(os.path.join(base_dir, "register_clf.py"), script_folder)
cpu_compute_name = config["cpu_compute"]
try:
cpu_compute_target = AmlCompute(ws, cpu_compute_name)
print("found existing compute target: %s" % cpu_compute_name)
except Exception: # ComputeTargetException:
print("creating new compute target")
provisioning_config = AmlCompute.provisioning_configuration(
vm_size="STANDARD_D2_V2",
max_nodes=4,
idle_seconds_before_scaledown=1800,
vm_priority="lowpriority"
)
cpu_compute_target = ComputeTarget.create(
ws, cpu_compute_name, provisioning_config
)
cpu_compute_target.wait_for_completion(
show_output=True, min_node_count=None, timeout_in_minutes=20
)
# choose a name for your cluster
gpu_compute_name = config["gpu_compute"]
try:
gpu_compute_target = AmlCompute(workspace=ws, name=gpu_compute_name)
print("found existing compute target: %s" % gpu_compute_name)
except Exception:
print("Creating a new compute target...")
provisioning_config = AmlCompute.provisioning_configuration(
vm_size="STANDARD_NC6",
max_nodes=10,
idle_seconds_before_scaledown=1800,
vm_priority="lowpriority"
)
# create the cluster
gpu_compute_target = ComputeTarget.create(
ws, gpu_compute_name, provisioning_config
)
# can poll for a minimum number of nodes and for a specific timeout.
# if no min node count is provided it uses the scale settings for the
# cluster
gpu_compute_target.wait_for_completion(
show_output=True, min_node_count=None, timeout_in_minutes=20
)
# use get_status() to get a detailed status for the current cluster.
print(cpu_compute_target.get_status().serialize())
cd = CondaDependencies.create()
# conda dependencies for compute targets
conda_dependencies = CondaDependencies.create(
conda_packages=["cudatoolkit=10.0"],
pip_packages=[
"azure-storage-blob==2.1.0",
"azureml-sdk",
"hickle==3.4.3",
"requests==2.21.0",
"sklearn",
"pandas",
"numpy",
"pillow==6.0.0",
"tensorflow-gpu==1.15",
"keras",
"matplotlib",
"seaborn",
]
)
env = Environment("prednet")
env.python.conda_dependencies = conda_dependencies
env.docker.enabled = True
env.docker.base_image = DEFAULT_GPU_IMAGE
env.register(ws)
# Runconfigs
runconfig = RunConfiguration()
runconfig.environment = env
print("PipelineData object created")
create_pipelines = PythonScriptStep(
name="create pipelines",
script_name="pipelines_slave.py",
compute_target=cpu_compute_target,
arguments=[
"--cpu_compute_name",
cpu_compute_name,
"--gpu_compute_name",
gpu_compute_name
],
source_directory=script_folder,
runconfig=runconfig,
allow_reuse=False,
)
print("pipeline building step created")
pipeline = Pipeline(workspace=ws, steps=[create_pipelines])
print("Pipeline created")
pipeline.validate()
print("Validation complete")
pipeline_name = "prednet_master"
disable_pipeline(pipeline_name=pipeline_name, dry_run=False)
disable_pipeline(pipeline_name="prednet_UCSDped1", dry_run=False)
published_pipeline = pipeline.publish(name=pipeline_name)
print("pipeline id: ", published_pipeline.id)
datastore = ws.get_default_datastore()
with open("placeholder.txt", "w") as f:
f.write(
"This is just a placeholder to ensure "
"that this path exists in the blobstore.\n"
)
datastore.upload_files(
[os.path.join(os.getcwd(), "placeholder.txt")],
target_path="prednet/data/raw_data/",
)
schedule = Schedule.create(
workspace=ws,
name=pipeline_name + "_sch",
pipeline_id=published_pipeline.id,
experiment_name="prednet_master",
datastore=datastore,
wait_for_provisioning=True,
description="Datastore scheduler for Pipeline" + pipeline_name,
path_on_datastore="prednet/data/raw_data",
polling_interval=5,
)
print("Created schedule with id: {}".format(schedule.id))
published_pipeline.submit(ws, published_pipeline.name)