Skip to content

Instantly share code, notes, and snippets.

@ftnext
Last active April 14, 2024 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftnext/e9e9c102e5c1a214b8215a4e63138346 to your computer and use it in GitHub Desktop.
Save ftnext/e9e9c102e5c1a214b8215a4e63138346 to your computer and use it in GitHub Desktop.
# Rewrite with kfp v2 https://huggingface.co/blog/turhancan97/building-your-first-kubeflow-pipeline
from typing import List
from kfp import compiler, dsl
@dsl.component(base_image="python:3.9")
def read_data() -> List[int]:
data = [1, 2, 3, 4, 5]
return data
@dsl.component(base_image="python:3.9")
def compute_average(data: List[int]) -> float:
return sum(data) / len(data)
@dsl.component(base_image="python:3.9")
def save_result(value: float, filename: str = "result.txt") -> None:
with open(filename, "w") as f:
f.write(str(value))
@dsl.pipeline(
name="My first pipeline",
description="A simple pipeline that computes the average of an array.",
# pipeline_root="gs://mlops-study-hello-world", # Kubeflow Pipelinesではコメントとする
)
def my_pipeline():
read_data_task = read_data()
compute_average_task = compute_average(data=read_data_task.output)
save_result_task = save_result(value=compute_average_task.output)
compiler.Compiler().compile(my_pipeline, "my_pipeline.yaml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment