But there isn't an explication about why I should to use one or another, for example for load a Container-based, I need to generate a docker image push, and load in the pipeline the yaml, with the specification, but with function-based, I only need import the function.
There are some misconceptions here.
There is only one kind of component under the hood - container-based component (there are also graph components, but this is irrelevant here).
However, most of our users like python and do not like building container. This is why I've developed a feature called "Lightweight python components" which generates ComponentSpec/component.yaml
from a python function source code. The generated component basically runs python3 -u -c '<your function>; <command-line parsing>' arg1 arg2 ...
.
There is a misconception that "function-based components are different from component.yaml
files".
No, it's the same format. You're supposed to save the generated component into a file for sharing: create_component_from_func(my_func, output_component_file='component.yaml')
. After your code stabilizes, you should upload the code and the component.yaml
to GitHub or other place and use load_component_from_url
to load that component.yaml
in pipelines.
Check the component.yaml
files in the KFP repo. More than half of the component.yaml
files are Lightweight components - they're generated from python functions.
component.yaml
are intended for sharing the components. They're declarative, portable, indexable, safe, language-agnostic etc. You should always publish component.yaml
files. If component.yaml
is generated from a python function, then it's good practice to put component.py
alongside so that the component can be easily regenerated when making changes.
The decision whether to create component using Lightweight python component feature or not is very simple:
Is you code in a self-contained python function (not a CLI program yet)? Do you want to avoid building, pushing and maintaining containers? If yes, then the Lightweight python component feature (create_component_from_func
) can help you and generate the component.yaml
for you.
Otherwise, write component.yaml
yourself.