试用 Pipelines 示例

Kubeflow Pipelines notebooks 和示例入门

您可以通过运行 Kubeflow Pipelines 仓库中提供的示例或通过一个介绍该过程的 Jupyter notebook 来学习如何构建和部署 pipeline。

在命令行上编译示例

本节向您展示如何编译 Kubeflow Pipelines 示例并使用 Kubeflow Pipelines UI 部署它们。

开始之前

设置您的环境

  1. 克隆或下载Kubeflow Pipelines 示例

  2. 安装Kubeflow Pipelines SDK

  3. 如果尚未激活 Python 3 环境,请激活它

    source activate <YOUR-PYTHON-ENVIRONMENT-NAME>
    

    例如

    source activate mlpipeline
    

选择并编译 pipeline

检查您下载的 pipeline 示例并选择一个来使用。sequential.py 示例 pipeline:是一个很好的入门选择。

每个 pipeline 都定义为一个 Python 程序。在将 pipeline 提交到 Kubeflow Pipelines 服务之前,您必须将 pipeline 编译为中间表示。中间表示的形式是一个压缩到 .tar.gz 文件中的 YAML 文件。

使用 dsl-compile 命令编译您选择的 pipeline

dsl-compile --py [path/to/python/file] --output [path/to/output/tar.gz]

例如,要编译sequential.py 示例 pipeline

export DIR=[YOUR PIPELINES REPO DIRECTORY]/samples/core/sequential
dsl-compile --py ${DIR}/sequential.py --output ${DIR}/sequential.tar.gz

部署 pipeline

通过 Kubeflow Pipelines UI 上传生成的 .tar.gz 文件。请参阅 UI 入门指南

在 Jupyter notebook 中构建 pipeline

您可以选择在 Jupyter notebook 中构建 pipeline。示例 notebook 会引导您完成整个过程。

最简单的方法是使用与 Kubeflow Pipelines 系统安装在同一集群中的 Jupyter 服务。

注意:notebook 示例在同一集群外部的 Jupyter notebook 上无法工作,因为 Python 库通过集群内的服务名称与 Kubeflow Pipelines 系统通信。

按照以下步骤启动 notebook

  1. 部署 Kubeflow

    • 按照 GCP 部署指南,包括使用 Kubeflow 部署 UI 部署 Kubeflow 的步骤。

    • 当 Kubeflow 运行时,通过以下形式的 URL 访问 Kubeflow UI:https://<deployment-name>.endpoints.<project>.cloud.goog/

  2. 按照Kubeflow notebooks 设置指南创建一个 Jupyter notebook 服务器并打开 Jupyter UI。

  3. https://github.com/kubeflow/pipelines/tree/sdk/release-1.8/samples/core 下载示例 notebook。

  4. 从 Jupyter UI 上传这些 notebook:在 Jupyter 中,进入树状视图并在屏幕右上角区域找到上传按钮。

  5. 打开一个已上传的 notebook。

  6. 确保 notebook 内核设置为 Python 3。Python 版本显示在 Jupyter notebook 视图的右上角。

  7. 按照 notebook 中的说明操作。

以下 notebook 可用

  • 使用 TFX OSS 组件的 KubeFlow pipeline:此 notebook 演示了如何基于 TensorFlow Extended (TFX) 组件构建机器学习 pipeline。该 pipeline 包含一个 TFDV 步骤用于推断模式,一个 TFT 预处理器,一个 TensorFlow 训练器,一个 TFMA 分析器,以及一个模型部署器,它将训练好的模型部署到同一集群中的 tf-serving。该 notebook 还演示了如何在 notebook 内部构建基于 Python 3 的组件,包括如何构建 Docker 容器。

  • 轻量级 Python 组件:此 notebook 演示了如何构建基于 Python 3 的简单 Python 组件,并在 pipeline 中快速迭代使用它们。如果使用此技术,构建组件时无需构建 Docker 容器。请注意,容器镜像可能不是独立的,因为源代码未构建到容器中。

下一步

反馈

此页面有帮助吗?


上次修改时间 2024年9月27日: 修复 Notebook 中的断链 (#3878) (888c2da)