开始

创建您的第一个管道

要开始使用教程,请通过以下命令安装 kfp v2:

pip install kfp

这是一个简单的管道,它打印问候语:

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

您可以 将管道编译 为 YAML,使用 KFP SDK DSL Compiler

from kfp import compiler

compiler.Compiler().compile(hello_pipeline, 'pipeline.yaml')

这个 dsl.componentdsl.pipeline 装饰器将你的类型注解的Python函数分别转换为组件和管道。KFP SDK编译器将特定领域语言(DSL)对象编译为一个自包含的管道 YAML文件

您可以将YAML文件提交给符合KFP的后端进行执行。如果您已经部署了KFP开源后端实例并获得了部署的端点,您可以使用KFP SDK Client提交管道进行执行。以下是使用参数 recipient='World' 提交管道执行:

from kfp.client import Client

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

客户端将打印一个链接,以在用户界面中查看管道执行图和日志。在这种情况下,管道有一个任务,打印并返回 'Hello, World!'

下一步

在接下来的几个部分中,您将更多地了解构建管道的核心概念,以及如何创建更具表现力和实用性的管道。

反馈

此页面有帮助吗?


Last modified July 6, 2024: 部分还原 #3787 (#3794) (b0d73bc)