Kubeflow 管道¶
TorchX 提供了一个适配器,用于将 TorchX 组件作为 Kubeflow 的一部分运行 管道。请参见 KubeFlow 管道示例。

torchx.pipelines.kfp 中¶

此模块包含用于将 TorchX 组件转换为 KubeFlow 的适配器 管道组件。
当前的 KFP 适配器仅支持单节点(1 个角色和 1 个副本) 组件。
- torchx.pipelines.kfp.adapter 的container_from_app(app: torchx.specs.api.AppDef, *args: object, ui_metadata: 可选[Mapping[str, object]] = None, **kwargs: object) → kfp.dsl._container_op.ContainerOp[来源]¶
container_from_app将应用程序转换为 KFP 组件并返回一个 对应的 ContainerOp 实例。
有关参数的说明,请参见 component_from_app。任何未指定 参数将传递给 KFP 容器工厂方法。
>>> import kfp >>> from torchx import specs >>> from torchx.pipelines.kfp.adapter import container_from_app >>> app_def = specs.AppDef( ... name="trainer", ... roles=[specs.Role("trainer", image="foo:latest")], ... ) >>> def pipeline(): ... trainer = container_from_app(app_def) ... print(trainer) >>> kfp.compiler.Compiler().compile( ... pipeline_func=pipeline, ... package_path="/tmp/pipeline.yaml", ... ) {'ContainerOp': {... 'name': 'trainer-trainer', ...}}
- torchx.pipelines.kfp.adapter 的resource_from_app(app: torchx.specs.api.AppDef, queue: str, service_account: Optional[str] = 无)→ kfp.dsl._resource_op。ResourceOp[来源]¶
resource_from_app从提供的应用程序生成 KFP ResourceOp,该应用程序使用 Kubernetes 上的 Volcano 作业调度程序来运行分布式应用程序。请参阅 https://volcano.sh/en/docs/ 了解有关 Volcano 以及如何安装的更多信息。
- 参数
app – 要适应的 torchx AppDef。
queue (队列) – 用于安排作员的 Volcano 队列。
>>> import kfp >>> from torchx import specs >>> from torchx.pipelines.kfp.adapter import resource_from_app >>> app_def = specs.AppDef( ... name="trainer", ... roles=[specs.Role("trainer", image="foo:latest", num_replicas=3)], ... ) >>> def pipeline(): ... trainer = resource_from_app(app_def, queue="test") ... print(trainer) >>> kfp.compiler.Compiler().compile( ... pipeline_func=pipeline, ... package_path="/tmp/pipeline.yaml", ... ) {'ResourceOp': {... 'name': 'trainer-0', ... 'name': 'trainer-1', ... 'name': 'trainer-2', ...}}
- torchx.pipelines.kfp.adapter 的component_from_app(app: torchx.specs.api.AppDef, ui_metadata: Optional[Mapping[str, object]] = 没有) → torchx.pipelines.kfp.adapter.ContainerFactory[来源]¶
component_from_app 接收 TorchX 组件/AppDef 并返回 KFP ContainerOp 工厂。这等效于 kfp.components.load_component_from_* 方法。
- 参数
app – 为其生成 KFP 容器工厂的 AppDef。
ui_metadata – 输出 KFP UI 元数据,以便您可以显示模型结果 在 UI 中。有关格式的更多信息,请参阅 https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/。
>>> from torchx import specs >>> from torchx.pipelines.kfp.adapter import component_from_app >>> app_def = specs.AppDef( ... name="trainer", ... roles=[specs.Role("trainer", image="foo:latest")], ... ) >>> component_from_app(app_def) <function component_from_app...>
- torchx.pipelines.kfp.adapter 的component_spec_from_app(app: torchx.specs.api.AppDef) → Tuple[str, torchx.specs.api.Role][来源]¶
component_spec_from_app 接收 TorchX 组件并生成 yaml spec 的 SPEC 中。值得注意的是,这并不应用资源或port_maps因为那些 必须在运行时应用,这就是为什么它也返回 role spec 的原因。
>>> from torchx import specs >>> from torchx.pipelines.kfp.adapter import component_spec_from_app >>> app_def = specs.AppDef( ... name="trainer", ... roles=[specs.Role("trainer", image="foo:latest")], ... ) >>> component_spec_from_app(app_def) ('description: ...', Role(...))