備註
按一下 這裡以下載完整的範例程式碼。
分散式 KubeFlow Pipelines 範例¶
這是一個 KFP pipeline 範例,它使用 resource_from_app 來使用 kubernetes/volcano 作業排程器啟動分散式運算子。這僅適用於已安裝 https://volcano.sh/en/docs/ 的 Kubernetes KFP 叢集。
import kfp
from torchx import specs
from torchx.pipelines.kfp.adapter import resource_from_app
def pipeline() -> None:
# First we define our AppDef for the component, we set
echo_app = specs.AppDef(
name="test-dist",
roles=[
specs.Role(
name="dist-echo",
image="alpine",
entrypoint="/bin/echo",
args=["hello dist!"],
num_replicas=3,
),
],
)
# To convert the TorchX AppDef into a KFP container we use
# the resource_from_app adapter. This takes generates a KFP Kubernetes
# resource operator definition from the TorchX app def and instantiates it.
echo_container: kfp.dsl.BaseOp = resource_from_app(echo_app, queue="default")
若要產生 pipeline 定義檔,我們需要使用 pipeline 函數呼叫 KFP 編譯器。
kfp.compiler.Compiler().compile(
pipeline_func=pipeline,
package_path="pipeline.yaml",
)
with open("pipeline.yaml", "rt") as f:
print(f.read())
完成所有這些步驟後,您應該會有一個 pipeline 檔案(通常是 pipeline.yaml),您可以透過 UI 或 kfp.Client 將其上傳到您的 KFP 叢集。
如需啟動 KFP pipelines 的詳細資訊,請參閱 KFP SDK 範例。
如需如何將多個元件鏈結在一起以及如何使用內建元件的資訊,請參閱 進階 KubeFlow Pipelines 範例。
# sphinx_gallery_thumbnail_path = '_static/img/gallery-kfp.png'
腳本總執行時間:(0 分 0.000 秒)