Kubeflow Pipeline 문서 읽기 | 첫 파이프라인 생성하기

no-brand·2023년 8월 10일
0

kubeflow

목록 보기
1/1

Hello World Kubeflow Pipeline

첫 파이프라인 생성하기

  • Requirements
    파이프라인 코드를 작성하기 위해서는 kfp 라이브러리 설치가 필요합니다.
    $ pip install kfp --pre

  • 파이프라인 DSL 작성
    일반 python 함수를 decorator를 이용해서 손쉽게 dsl component, dsl pipeline 으로 변경할 수 있습니다.

    from kfp import dsl
    
    @dsl.component
    def say_hello(name: str) -> str:
        hello_text = f'Hello, {name}!'
        print(hello_text)
        return hello_text
       
    @dsl.pipeline
    def hello_pipeline(recipient: str) -> str:
        hello_task = say_hello(name=recipient)
        return hello_task.output

  • 파이프라인 DSL 컴파일
    KFP SDK Compiler 이용하면 DSL(domain-specific language) 객체를 self-contained 파이프라인 YAML 파일로 변환할 수 있습니다.

    • Q. self-contained 란?
    from kfp import compiler
    
    compiler.Compiler().compile(hello_pipeline, 'pipeline.yaml')

  • 파이프라인 실행
    실행을 위해서 KFP 가 설치된 백엔드에 YAML 파일을 제출할 수 있습니다. KFP 백엔드의 deployment endpoint 를 이용합니다. 이때는 KFP SDK Client 를 이용하고, Argument 를 받도록 처리된 부분들은 다 채우도록 합니다.
    수행하면, 파이프라인 Execution Graph, Log 등을 확인할 수 있는 UI 링크를 제공합니다.

    from kfp.client import Client
    
    client = Client(host='<MY-KFP-ENDPOINT>')
    run = client.create_run_from_pipeline_package(
        'pipeline.yaml',
        arguments={
            'recipient': 'World',
        },
    )

Reference

1개의 댓글

comment-user-thumbnail
2023년 8월 10일

즐겁게 읽었습니다. 유용한 정보 감사합니다.

답글 달기