Kubeflow Pipelines¶
TorchX 提供了一个适配器,可以在 Kubeflow Pipelines 中运行 TorchX 组件。请参阅 KubeFlow Pipelines 示例。
torchx.pipelines.kfp¶
此模块包含适配器,用于将TorchX组件转换为KubeFlow管道组件。
当前的 KFP 适配器仅支持单节点(1 个角色和 1 个副本)组件。
- torchx.pipelines.kfp.adapter.container_from_app(app: torchx.specs.api.AppDef, *args: object, ui_metadata: Optional[Mapping[str, object]] = None, **kwargs: object) → kfp.dsl._container_op.ContainerOp[source]¶
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] = None) → kfp.dsl._resource_op.ResourceOp[source]¶
resource_from_app 从提供的应用程序生成一个 KFP ResourceOp,在 Kubernetes 上使用 Volcano 作业调度程序来运行分布式应用程序。有关 Volcano 的更多信息及其安装方法,请参见 https://volcano.sh/en/docs/。
- Parameters
应用 – 用于适配的TorchX AppDef。
队列 – 用于调度操作员的 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]] = None) → torchx.pipelines.kfp.adapter.ContainerFactory[source]¶
component_from_app 接受一个 TorchX 组件/AppDef 并返回一个 KFP ContainerOp 工厂。这相当于 kfp.components.load_component_from_* 方法。
- Parameters
应用 – 用于生成KFP容器工厂的AppDef。
ui_metadata – KFP UI Metadata to output so you can have model results show up in the UI. See https://www.kubeflow.org/docs/components/pipelines/sdk/output-viewer/ for more info on the format.
>>> 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][source]¶
component_spec_from_app 接受一个 TorchX 组件并为其生成 yaml 规范。值得注意的是,这并不会应用资源或端口映射,因为这些必须在运行时应用,因此它还会返回角色规范。
>>> 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(...))