forked from machine-learning-exchange/katalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculation-pipeline.yaml
337 lines (310 loc) · 13.4 KB
/
calculation-pipeline.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
# Copyright 2021 The MLX Contributors
#
# SPDX-License-Identifier: Apache-2.0
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: calculation-pipeline
annotations:
tekton.dev/output_artifacts: '{"add": [{"key": "artifacts/$PIPELINERUN/add/Output.tgz",
"name": "add-Output", "path": "/tmp/outputs/Output/data"}], "add-2": [{"key":
"artifacts/$PIPELINERUN/add-2/Output.tgz", "name": "add-2-Output", "path": "/tmp/outputs/Output/data"}],
"my-divmod": [{"key": "artifacts/$PIPELINERUN/my-divmod/mlpipeline-ui-metadata.tgz",
"name": "mlpipeline-ui-metadata", "path": "/tmp/outputs/mlpipeline_ui_metadata/data"},
{"key": "artifacts/$PIPELINERUN/my-divmod/mlpipeline-metrics.tgz", "name": "mlpipeline-metrics",
"path": "/tmp/outputs/mlpipeline_metrics/data"}, {"key": "artifacts/$PIPELINERUN/my-divmod/quotient.tgz",
"name": "my-divmod-quotient", "path": "/tmp/outputs/quotient/data"}, {"key":
"artifacts/$PIPELINERUN/my-divmod/remainder.tgz", "name": "my-divmod-remainder",
"path": "/tmp/outputs/remainder/data"}]}'
tekton.dev/input_artifacts: '{"add-2": [{"name": "my-divmod-quotient", "parent_task":
"my-divmod"}], "my-divmod": [{"name": "add-Output", "parent_task": "add"}]}'
tekton.dev/artifact_bucket: mlpipeline
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000
tekton.dev/artifact_endpoint_scheme: http://
tekton.dev/artifact_items: '{"add": [["Output", "$(results.output.path)"]], "add-2":
[["Output", "$(results.output.path)"]], "my-divmod": [["mlpipeline-ui-metadata",
"/tmp/outputs/mlpipeline_ui_metadata/data"], ["mlpipeline-metrics", "/tmp/outputs/mlpipeline_metrics/data"],
["quotient", "$(results.quotient.path)"], ["remainder", "$(results.remainder.path)"]]}'
sidecar.istio.io/inject: "false"
pipelines.kubeflow.org/big_data_passing_format: $(workspaces.$TASK_NAME.path)/artifacts/$ORIG_PR_NAME/$TASKRUN_NAME/$TASK_PARAM_NAME
pipelines.kubeflow.org/pipeline_spec: '{"description": "A toy pipeline that performs
arithmetic calculations.", "inputs": [{"default": "7.0", "name": "a", "optional":
true, "type": "Float"}, {"default": "8.0", "name": "b", "optional": true, "type":
"Float"}, {"default": "17.0", "name": "c", "optional": true, "type": "Float"}],
"name": "Calculation Pipeline"}'
spec:
params:
- name: a
value: '7.0'
- name: b
value: '8.0'
- name: c
value: '17.0'
pipelineSpec:
params:
- name: a
default: '7.0'
- name: b
default: '8.0'
- name: c
default: '17.0'
tasks:
- name: add
params:
- name: a
value: $(params.a)
taskSpec:
steps:
- name: main
args:
- --a
- $(inputs.params.a)
- --b
- '4'
- '----output-paths'
- $(results.output.path)
command:
- sh
- -ec
- |
program_path=$(mktemp)
printf "%s" "$0" > "$program_path"
python3 -u "$program_path" "$@"
- |
def add(a, b):
"""Calculates sum of two arguments"""
return a + b
def _serialize_float(float_value: float) -> str:
if isinstance(float_value, str):
return float_value
if not isinstance(float_value, (float, int)):
raise TypeError('Value "{}" has type "{}" instead of float.'.format(str(float_value), str(type(float_value))))
return str(float_value)
import argparse
_parser = argparse.ArgumentParser(prog='Add', description='Calculates sum of two arguments')
_parser.add_argument("--a", dest="a", type=float, required=True, default=argparse.SUPPRESS)
_parser.add_argument("--b", dest="b", type=float, required=True, default=argparse.SUPPRESS)
_parser.add_argument("----output-paths", dest="_output_paths", type=str, nargs=1)
_parsed_args = vars(_parser.parse_args())
_output_files = _parsed_args.pop("_output_paths", [])
_outputs = add(**_parsed_args)
_outputs = [_outputs]
_output_serializers = [
_serialize_float,
]
import os
for idx, output_file in enumerate(_output_files):
try:
os.makedirs(os.path.dirname(output_file))
except OSError:
pass
with open(output_file, 'w') as f:
f.write(_output_serializers[idx](_outputs[idx]))
image: python:3.7
params:
- name: a
results:
- name: output
description: /tmp/outputs/Output/data
metadata:
labels:
pipelines.kubeflow.org/pipelinename: ''
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/cache_enabled: "true"
annotations:
pipelines.kubeflow.org/component_spec_digest: '{"name": "Add", "outputs":
[{"name": "Output", "type": "Float"}], "version": "Add@sha256=6747051c897943c73ef931bf243a7a5ea738f7981a2208ab6daf11bcdf6744c4"}'
tekton.dev/template: ''
timeout: 525600m
- name: my-divmod
params:
- name: add-Output
value: $(tasks.add.results.output)
- name: b
value: $(params.b)
taskSpec:
steps:
- name: main
args:
- --dividend
- $(inputs.params.add-Output)
- --divisor
- $(inputs.params.b)
- '----output-paths'
- $(results.quotient.path)
- $(results.remainder.path)
- /tmp/outputs/mlpipeline_ui_metadata/data
- /tmp/outputs/mlpipeline_metrics/data
command:
- sh
- -ec
- |
program_path=$(mktemp)
printf "%s" "$0" > "$program_path"
python3 -u "$program_path" "$@"
- |
def my_divmod(dividend, divisor):
"""Divides two numbers and calculate the quotient and remainder"""
#Pip installs inside a component function.
#NOTE: installs should be placed right at the beginning to avoid upgrading a package
# after it has already been imported and cached by python
import sys, subprocess;
subprocess.run([sys.executable, '-m', 'pip', 'install', 'tensorflow==1.8.0'])
#Imports inside a component function:
import numpy as np
#This function demonstrates how to use nested functions inside a component function:
def divmod_helper(dividend, divisor):
return np.divmod(dividend, divisor)
(quotient, remainder) = divmod_helper(dividend, divisor)
from tensorflow.python.lib.io import file_io
import json
# Exports a sample tensorboard:
metadata = {
'outputs' : [{
'type': 'tensorboard',
'source': 'gs://ml-pipeline-dataset/tensorboard-train',
}]
}
# Exports two sample metrics:
metrics = {
'metrics': [{
'name': 'quotient',
'numberValue': float(quotient),
},{
'name': 'remainder',
'numberValue': float(remainder),
}]}
from collections import namedtuple
divmod_output = namedtuple('MyDivmodOutput', ['quotient', 'remainder', 'mlpipeline_ui_metadata', 'mlpipeline_metrics'])
return divmod_output(quotient, remainder, json.dumps(metadata), json.dumps(metrics))
def _serialize_float(float_value: float) -> str:
if isinstance(float_value, str):
return float_value
if not isinstance(float_value, (float, int)):
raise TypeError('Value "{}" has type "{}" instead of float.'.format(str(float_value), str(type(float_value))))
return str(float_value)
import argparse
_parser = argparse.ArgumentParser(prog='My divmod', description='Divides two numbers and calculate the quotient and remainder')
_parser.add_argument("--dividend", dest="dividend", type=float, required=True, default=argparse.SUPPRESS)
_parser.add_argument("--divisor", dest="divisor", type=float, required=True, default=argparse.SUPPRESS)
_parser.add_argument("----output-paths", dest="_output_paths", type=str, nargs=4)
_parsed_args = vars(_parser.parse_args())
_output_files = _parsed_args.pop("_output_paths", [])
_outputs = my_divmod(**_parsed_args)
_output_serializers = [
_serialize_float,
_serialize_float,
str,
str,
]
import os
for idx, output_file in enumerate(_output_files):
try:
os.makedirs(os.path.dirname(output_file))
except OSError:
pass
with open(output_file, 'w') as f:
f.write(_output_serializers[idx](_outputs[idx]))
image: tensorflow/tensorflow:1.11.0-py3
params:
- name: add-Output
- name: b
results:
- name: quotient
description: /tmp/outputs/quotient/data
- name: remainder
description: /tmp/outputs/remainder/data
stepTemplate:
volumeMounts:
- name: mlpipeline-ui-metadata
mountPath: /tmp/outputs/mlpipeline_ui_metadata
- name: mlpipeline-metrics
mountPath: /tmp/outputs/mlpipeline_metrics
volumes:
- name: mlpipeline-ui-metadata
emptyDir: {}
- name: mlpipeline-metrics
emptyDir: {}
metadata:
labels:
pipelines.kubeflow.org/pipelinename: ''
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/cache_enabled: "true"
annotations:
pipelines.kubeflow.org/component_spec_digest: '{"name": "My divmod", "outputs":
[{"name": "quotient", "type": "Float"}, {"name": "remainder", "type":
"Float"}, {"name": "mlpipeline_ui_metadata", "type": "UI_metadata"},
{"name": "mlpipeline_metrics", "type": "Metrics"}], "version": "My divmod@sha256=4c899614d703dce761021d181331942f218ad9dceb0c389dff06e39841d9b067"}'
tekton.dev/template: ''
timeout: 525600m
- name: add-2
params:
- name: c
value: $(params.c)
- name: my-divmod-quotient
value: $(tasks.my-divmod.results.quotient)
taskSpec:
steps:
- name: main
args:
- --a
- $(inputs.params.my-divmod-quotient)
- --b
- $(inputs.params.c)
- '----output-paths'
- $(results.output.path)
command:
- sh
- -ec
- |
program_path=$(mktemp)
printf "%s" "$0" > "$program_path"
python3 -u "$program_path" "$@"
- |
def add(a, b):
"""Calculates sum of two arguments"""
return a + b
def _serialize_float(float_value: float) -> str:
if isinstance(float_value, str):
return float_value
if not isinstance(float_value, (float, int)):
raise TypeError('Value "{}" has type "{}" instead of float.'.format(str(float_value), str(type(float_value))))
return str(float_value)
import argparse
_parser = argparse.ArgumentParser(prog='Add', description='Calculates sum of two arguments')
_parser.add_argument("--a", dest="a", type=float, required=True, default=argparse.SUPPRESS)
_parser.add_argument("--b", dest="b", type=float, required=True, default=argparse.SUPPRESS)
_parser.add_argument("----output-paths", dest="_output_paths", type=str, nargs=1)
_parsed_args = vars(_parser.parse_args())
_output_files = _parsed_args.pop("_output_paths", [])
_outputs = add(**_parsed_args)
_outputs = [_outputs]
_output_serializers = [
_serialize_float,
]
import os
for idx, output_file in enumerate(_output_files):
try:
os.makedirs(os.path.dirname(output_file))
except OSError:
pass
with open(output_file, 'w') as f:
f.write(_output_serializers[idx](_outputs[idx]))
image: python:3.7
params:
- name: c
- name: my-divmod-quotient
results:
- name: output
description: /tmp/outputs/Output/data
metadata:
labels:
pipelines.kubeflow.org/pipelinename: ''
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/cache_enabled: "true"
annotations:
pipelines.kubeflow.org/component_spec_digest: '{"name": "Add", "outputs":
[{"name": "Output", "type": "Float"}], "version": "Add@sha256=6747051c897943c73ef931bf243a7a5ea738f7981a2208ab6daf11bcdf6744c4"}'
tekton.dev/template: ''
timeout: 525600m
timeout: 525600m