

1) AI Platform Pipelines (구버전)
2) Vertex AI Pipelines (신버전)
from kfp.v2 import dsl
# Pipelines Workflow 정의
@dsl.pipeline(
name='pipeline-test',
description='pipeline test for ml workflow.',
pipeline_root=PIPELINE_ROOT
)
# 하단의 component는 예시
def pipeline():
# 각 단계에서의 output을 다음 component의 input으로 할당
get_data_op = get_data()
get_preprocessing_data_op = get_preprocessing_data(input_dataset = get_data_op.output)
get_train_dataset_op = get_train_dataset(input_dataset = get_preprocessing_data_op.outputs['transformed_dataset'])
train_causalimpact_op = train_causalimpact(train_dataset = get_train_dataset_op.outputs['train_dataset'],
index_dataset = get_preprocessing_data_op.outputs['index_dataset'],
period_dataset = get_train_dataset_op.outputs['period_dataset'])
get_transform_bq_load_dataset_op = get_transform_bq_load_dataset(result_dataset = train_causalimpact_op.output)
from kfp import compiler
compiler.Compiler().compile(
pipeline_func=pipeline,
package_path='pipeline_test.yaml'
)
import google.cloud.aiplatform as aip
# Before initializing, make sure to set the GOOGLE_APPLICATION_CREDENTIALS
# environment variable to the path of your service account.
aip.init(
project=project_id,
location=PROJECT_REGION,
)
# Prepare the pipeline job
job = aip.PipelineJob(
display_name="pipeline-test",
template_path="pipeline_test.yaml",
pipeline_root=pipeline_root_path
)
job.submit()
# non-example! 오류 예시
invalid_val = 5
@dsl.component
def error_func(a: int) -> int:
"""Fails at runtime."""
return invalid_val * a
from kfp import dsl
@dsl.container_component
def say_hello():
return dsl.ContainerSpec(image='alpine', command=['echo'], args=['Hello'])