Last active
January 31, 2020 01:47
-
-
Save post2web/5257ff3e6459d00dea47be4e0ba91ec7 to your computer and use it in GitHub Desktop.
XGBoost -> Deployer Pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kfp import dsl, gcp, compiler, components | |
deployer_component = components.load_component_from_url('https://raw.githubusercontent.com/kubeflow/pipelines/b850360cd6388cce127b8d079c2c6e7d54519ef2/components/gcp/ml_engine/deploy/component.yaml') | |
def xgboost_component( | |
output_location, | |
training_data, | |
validation_data, | |
data_type, | |
target_column, | |
objective, | |
num_round=10): | |
return dsl.ContainerOp( | |
name='Train XGBoost model', | |
image='gcr.io/aihub-c2t-containers/kfp-components/trainer/dist_xgboost:latest', | |
arguments=[ | |
'--output-location', output_location, | |
'--training-data', training_data, | |
'--validation-data', validation_data, | |
'--data-type', data_type, | |
'--target-column', target_column, | |
'--objective', objective, | |
'--target-column', target_column, | |
'--num-round', num_round, | |
], | |
file_outputs={'model_uri': '/tmp/model_uri.txt'}) | |
@dsl.pipeline(name='XGBoost training', description='XGBoost training pipeline') | |
def pipeline( | |
model_name, | |
model_version, | |
project_id, | |
output_location, | |
training_data='gs://aihub-c2t-containers-public/release-0.2.0/kfp-components/trainer/dist_xgboost/data/csv/iris/train.csv', | |
validation_data='gs://aihub-c2t-containers-public/release-0.2.0/kfp-components/trainer/dist_xgboost/data/csv/iris/valid.csv', | |
data_type='csv', | |
target_column='target', | |
objective='multi:softprob', | |
num_round=10): | |
xgboost = xgboost_component( | |
output_location=output_location, | |
training_data=training_data, | |
validation_data=validation_data, | |
data_type=data_type, | |
target_column=target_column, | |
objective=objective, | |
num_round=num_round, | |
).apply(gcp.use_gcp_secret('user-gcp-sa')) | |
deployer = deployer_component( | |
model_uri=xgboost.outputs['model_uri'], | |
project_id=project_id, | |
model_id=model_name, | |
version_id=model_version, | |
runtime_version='1.4', | |
replace_existing_version='True', | |
set_default='True', | |
wait_interval='30' | |
).apply(gcp.use_gcp_secret('user-gcp-sa')) | |
compiler.Compiler().compile(pipeline, 'pipeline.tar.gz') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment