-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnewflow.py
105 lines (91 loc) · 3.18 KB
/
newflow.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
# Copyright 2018 Iguazio
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from kfp import dsl
from mlrun import build_function, deploy_function, get_current_project, run_function
from mlrun.model import HyperParamOptions
funcs = {}
DATASET = "iris_dataset"
LABELS = "label"
in_kfp = True
@dsl.pipeline(name="Demo training pipeline", description="Shows how to use mlrun.")
def newpipe():
project = get_current_project()
# build our ingestion function (container image)
builder = build_function("gen-iris")
# run the ingestion function with the new image and params
ingest = run_function(
"gen-iris",
name="get-data",
handler="iris_generator",
params={"format": "pq"},
outputs=[DATASET],
).after(builder)
print(ingest.outputs)
# analyze our dataset
run_function(
"describe",
name="summary",
params={"label_column": project.get_param("label", "label")},
inputs={"table": ingest.outputs[DATASET]},
)
# train with hyper-paremeters
train = run_function(
"auto-trainer",
name="train",
params={
"label_columns": LABELS,
"train_test_split_size": 0.10,
# for determinism, we need datasets to be split
# evenly datasets will include examples from all classes
"random_state": 7,
},
hyperparams={
"model_class": [
"sklearn.ensemble.RandomForestClassifier",
"sklearn.linear_model.LogisticRegression",
"sklearn.ensemble.AdaBoostClassifier",
]
},
hyper_param_options=HyperParamOptions(selector="max.accuracy"),
inputs={"dataset": ingest.outputs[DATASET]},
outputs=["model", "test_set"],
)
print(train.outputs)
# test and visualize our model
run_function(
"auto-trainer",
name="test",
handler="evaluate",
params={
"label_columns": LABELS,
"model": train.outputs["model"],
},
inputs={
"dataset": train.outputs["test_set"],
},
)
# deploy our model as a serverless function, we can pass a list of models to serve
deploy = deploy_function(
"serve",
models=[{"key": f"{DATASET}:v1", "model_path": train.outputs["model"]}],
)
# TODO: Add the following function once v2-model-tester is fixed
# test out new model server (via REST API calls), use imported function
# run_function(
# "hub://v2-model-tester",
# name="model-tester",
# params={"addr": deploy.outputs["endpoint"], "model": f"{DATASET}:v1"},
# inputs={"table": train.outputs["test_set"]},
# )