forked from kubeflow/examples
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tfargo.yaml
351 lines (349 loc) · 13.9 KB
/
tfargo.yaml
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: tf-workflow-
spec:
entrypoint: tests
onExit: exit-handler
# Parameters can be passed/overridden via the argo CLI.
# To override the printed message, run `argo submit` with the -p option:
# $ argo submit examples/arguments-parameters.yaml -p message="goodbye world"
arguments:
parameters:
- name: datasets-image
# default image
value: gcr.io/constant-cubist-173123/tf_workflow:nan_workflow
- name: tf-master # number of tf masters
value: 1
- name: tf-worker # number of tf workers
value: 1
- name: tf-ps # number of tf parameter servers
value: 2
- name: tf-image
value: elsonrodriguez/mytfmodel:1.45
- name: tf-server-image
value: elsonrodriguez/mytfserver:1.6
- name: job-name
value: job21
- name: namespace
value: default
- name: s3sourceURL
value: s3://tfoperator/data/mnist/
- name: s3resultURL
value: s3://tfoperator/models
- name: aws-endpoint-url
value: https://s3.amazonaws.com
- name: aws-secret
value: aws-creds
- name: gcsresultURL
value: s3://superpuke/models
volumes:
- name: training-data
emptyDir: {}
- name: training-output
templates:
- name: tests
steps:
- - name: mount-datasets
template: kvc
- - name: get-volume
template: get-volumemanager-info
- - name: train
template: tf-train
arguments:
parameters:
- name: nodeaffinity
value: "{{steps.get-volume.outputs.parameters.nodeaffinity}}"
- name: hostpath
value: "{{steps.get-volume.outputs.parameters.hostpath}}"
- - name: export-model
template: tf-export
- - name: inference
template: tf-inference
# - - name: prepare-datasets
# template: download-and-convert-data
- name: exit-handler
steps:
- - name: cleanup
template: clean
# - name: download-and-convert-data
# container:
# image: gcr.io/constant-cubist-173123/tf_workflow:nan_workflow
# imagePullPolicy: Always
# command: ["bash", "-c", "python /notebooks/models/research/slim/download_and_convert_data.py --dataset_name=flowers --dataset_dir=/tmp/data"]
# outputs:
# artifacts:
# - name: training-data
# path: /tmp/data
- name: kvc
resource:
action: apply
successCondition: status.state == Running
manifest: |
apiVersion: aipg.intel.com/v1
kind: VolumeManager
metadata:
name: mnist
namespace: {{workflow.parameters.namespace}}
spec:
volumeConfigs:
- id: "mnist-{{workflow.uid}}"
replicas: 1
sourceType: "S3"
sourceURL: "{{workflow.parameters.s3sourceURL}}"
AccessMode: "ReadWriteOnce"
Capacity: 1Gi
Labels:
tfdata: mnist
Options:
awsCredentialsSecretName: {{workflow.parameters.aws-secret}}
- name: get-volumemanager-info
container:
image: nervana/circleci:master
imagePullPolicy: Always
command: ["bash", "-c", "kubectl get volumemanager mnist -o json | jq -r '.status.volumes[].volumeSource.hostPath.path' | tee /tmp/hostpath; kubectl get volumemanager mnist -o json | jq '.status.volumes[].nodeAffinity' | tee /tmp/nodeaffinity"]
outputs:
parameters:
- name: hostpath
valueFrom:
path: /tmp/hostpath
- name: nodeaffinity
valueFrom:
path: /tmp/nodeaffinity
- name: tf-train
inputs:
parameters:
- name: nodeaffinity
- name: hostpath
resource:
action: apply
# NOTE: need to detect master node complete
successCondition: status.state == Succeeded
manifest: |
apiVersion: "kubeflow.org/v1alpha1"
kind: "TFJob"
metadata:
name: {{workflow.parameters.job-name}}
namespace: {{workflow.parameters.namespace}}
spec:
replicaSpecs:
- replicas: {{workflow.parameters.tf-master}}
tfReplicaType: MASTER
template:
spec:
affinity:
nodeAffinity:
{{inputs.parameters.nodeaffinity}}
serviceAccountName: tf-job-operator
containers:
- image: {{workflow.parameters.tf-image}}
name: tensorflow
imagePullPolicy: Always
args: ["python", "/opt/model.py", "--data_dir=/tmp/data", "--train_dir=/tmp/train", "--download=true", "--sync_replicas=true"]
volumeMounts:
- name: training-result
mountPath: /tmp/train
- name: training-data
mountPath: /tmp/data
- image: nervana/circleci:jose_wait_for_master
name: upload
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: {{workflow.parameters.aws-secret}}
key: awsAccessKeyID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{workflow.parameters.aws-secret}}
key: awsSecretAccessKey
command: ['sh', '-c', "./bin/wait_for_master $POD_NAMESPACE $POD_NAME; aws --endpoint-url {{workflow.parameters.aws-endpoint-url}} s3 cp --recursive /tmp/train {{workflow.parameters.s3resultURL}}/unfinished/{{workflow.parameters.job-name}}/"]
volumeMounts:
- name: training-result
mountPath: /tmp/train
volumes:
- name: training-result
emptyDir: {}
- name: training-data
hostPath:
path: {{inputs.parameters.hostpath}}
restartPolicy: OnFailure
- replicas: {{workflow.parameters.tf-worker}}
tfReplicaType: WORKER
template:
spec:
affinity:
nodeAffinity:
{{inputs.parameters.nodeaffinity}}
serviceAccountName: tf-job-operator
containers:
- image: {{workflow.parameters.tf-server-image}}
name: tensorflow
imagePullPolicy: Always
volumeMounts:
- name: training-result
mountPath: /tmp/train
- name: training-data
mountPath: /tmp/data
- image: nervana/circleci:jose_wait_for_master
name: upload
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: {{workflow.parameters.aws-secret}}
key: awsAccessKeyID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{workflow.parameters.aws-secret}}
key: awsSecretAccessKey
command: ['sh', '-c', "./bin/wait_for_master $POD_NAMESPACE $POD_NAME; aws --endpoint-url {{workflow.parameters.aws-endpoint-url}} s3 cp --recursive /tmp/train {{workflow.parameters.s3resultURL}}/unfinished/{{workflow.parameters.job-name}}/"]
volumeMounts:
- name: training-result
mountPath: /tmp/train
volumes:
- name: training-result
emptyDir: {}
- name: training-data
hostPath:
path: {{inputs.parameters.hostpath}}
restartPolicy: OnFailure
- replicas: {{workflow.parameters.tf-ps}}
tfReplicaType: PS
template:
spec:
containers:
- image: {{workflow.parameters.tf-server-image}}
name: tensorflow
imagePullPolicy: Always
restartPolicy: OnFailure
- name: tf-export
resource:
action: apply
successCondition: status.phase == Succeeded
failureCondition: status.phase == Failed
manifest: |
apiVersion: v1
kind: Pod
metadata:
name: exporter-{{workflow.parameters.job-name}}
spec:
restartPolicy: Never
containers:
- name: s3-download-unfinished
image: volumecontroller/aws-cli:latest
env:
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: {{workflow.parameters.aws-secret}}
key: awsAccessKeyID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{workflow.parameters.aws-secret}}
key: awsSecretAccessKey
- name: AWS_ENDPOINT_URL
value: {{workflow.parameters.aws-endpoint-url}}
command: ['sh', '-c', "aws s3 cp --recursive {{workflow.parameters.s3resultURL}}/unfinished/{{workflow.parameters.job-name}}/ /tmp/train && touch /tmp/download-done/done"]
volumeMounts:
- name: training-result
mountPath: /tmp/train
- name: download-done
mountPath: /tmp/download-done
- image: elsonrodriguez/mytfmodel:1.45
name: export
imagePullPolicy: Always
command: ['/bin/bash','-c', 'while [ ! -f /tmp/download-done/done ]; do sleep 5; done; ls -r /tmp/export/model; python /opt/export.py --checkpoint_dir=/tmp/train --output_dir=/tmp/export/model && touch /tmp/export-done/done']
volumeMounts:
- name: training-result
mountPath: /tmp/train
- name: download-done
mountPath: /tmp/download-done
- name: export-done
mountPath: /tmp/export-done
- name: export-result
mountPath: /tmp/export
- name: s3-upload-exported
image: volumecontroller/aws-cli:latest
env:
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: gcs-creds
key: awsAccessKeyID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: gcs-creds
key: awsSecretAccessKey
- name: AWS_ENDPOINT_URL
value: https://storage.googleapis.com
command: ['sh', '-c', 'while [ ! -f /tmp/export-done/done ]; do sleep 5; done; aws s3 cp --recursive /tmp/export/model/ {{workflow.parameters.gcsresultURL}}/exported/{{workflow.parameters.job-name}}/']
volumeMounts:
- name: export-result
mountPath: /tmp/export
- name: export-done
mountPath: /tmp/export-done
volumes:
- name: training-result
emptyDir: {}
- name: export-result
emptyDir: {}
- name: download-done
emptyDir: {}
- name: export-done
emptyDir: {}
- name: tf-inference
script:
image: elsonrodriguez/ksonnet:0.8.0-test6
command: ["/ksonnet-entrypoint.sh"]
source: |
MODEL_COMPONENT=serveMnist
MODEL_PATH=gs://superpuke/models/exported/{{workflow.parameters.job-name}} #{{workflow.parameters.gcsresultURL}}/exported/{{workflow.parameters.job-name}}
MODEL_SERVER_IMAGE=gcr.io/constant-cubist-173123/model-server:1.0
ks init my-model-server
cd my-model-server
ks registry add kubeflow github.com/kubeflow/kubeflow/tree/master/kubeflow
ks pkg install kubeflow/tf-serving
ks env add cloud
# TODO change mnist name to be specific to a job. Right now mnist name is required to serve the model.
ks generate tf-serving ${MODEL_COMPONENT} --name=mnist2 --namespace={{workflow.parameters.namespace}} --model_path=${MODEL_PATH} --model_server_image=${MODEL_SERVER_IMAGE}
ks apply cloud -c ${MODEL_COMPONENT}
env:
- name: SERVICE_ACCOUNT
value: argo
- name: clean
container:
image: nervana/circleci:master
imagePullPolicy: Always
command: ["bash", "-c", "kubectl delete tfjob {{workflow.parameters.job-name}} || true; kubectl delete pod exporter-{{workflow.parameters.job-name}} || true"]
# NOTE: export mnodel
# - name: tf_model_export
# spec:
# containers:
# - image: elsonrodriguez/mytfmodel:1.45
# name: tensorflow
# command: python export.py --checkpoint_dir=/combined_training_results/ --output_dir=/saved_model