.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_pipelines/kfp/intro_pipeline.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_pipelines_kfp_intro_pipeline.py: Intro KubeFlow Pipelines Example ================================ This an introductory pipeline using KubeFlow Pipelines built with only TorchX components. TorchX is intended to allow making cross platform components. As such, we have a standard definition that uses adapters to convert it to the specific pipeline platform. This is an example of using the KFP adapter to run a TorchX component as part of a KubeFlow Pipeline. TorchX tries to leverage standard mechanisms wherever possible. For KFP we use the existing KFP pipeline definition syntax and add a single `component_from_app` conversion step to convert a TorchX component into one KFP can understand. Typically you have a separate component file but for this example we define the AppDef inline. .. GENERATED FROM PYTHON SOURCE LINES 28-53 .. code-block:: default import kfp from torchx import specs from torchx.components.base.binary_component import binary_component from torchx.pipelines.kfp.adapter import container_from_app def pipeline() -> None: # First we define our AppDef for the component. We use the binary_component # helper for making single node components. AppDef is a core part of TorchX # and can be used to describe complex distributed multi container apps or # just a single node component like here. echo_app: specs.AppDef = binary_component( name="examples-intro", entrypoint="/bin/echo", args=["Hello TorchX!"], image="alpine", ) # To convert the TorchX AppDef into a KFP container we use # the container_from_app adapter. This takes generates a KFP component # definition from the TorchX app def and instantiates it into a container. echo_container: kfp.dsl.ContainerOp = container_from_app(echo_app) .. GENERATED FROM PYTHON SOURCE LINES 54-56 To generate the pipeline definition file we need to call into the KFP compiler with our pipeline function. .. GENERATED FROM PYTHON SOURCE LINES 56-65 .. code-block:: default kfp.compiler.Compiler().compile( pipeline_func=pipeline, package_path="pipeline.yaml", ) with open("pipeline.yaml", 'rt') as f: print(f.read()) .. GENERATED FROM PYTHON SOURCE LINES 66-73 Once this has all run you should have a pipeline file (typically pipeline.yaml) that you can upload to your KFP cluster via the UI or a kfp.Client. See the `KFP SDK Examples `_ for more info on launching KFP pipelines. .. GENERATED FROM PYTHON SOURCE LINES 75-77 See the :ref:`Advanced KubeFlow Pipelines Example` for how to chain multiple components together and use builtin components. .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_examples_pipelines_kfp_intro_pipeline.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: intro_pipeline.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: intro_pipeline.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_