In a KFP v2 pipeline, when should a step pass data as an Input[Dataset] or Output[Model] artifact instead of a str parameter, and why?
answer
- small values versus files
- JSON inside the executor input
- .path, .uri and .metadata
- backend copies .path to the pipeline root
- a corpus returned as str
basics
~20 sParameters (str, int, float, bool, list, dict) are small JSON values passed with a task's inputs. Datasets, models and metrics belong in artifacts: written to .path, then copied by the backend to object storage with lineage.
solid answer
~40 sKFP v2 has two kinds of inputs and outputs. **Parameters** are built-in types (`str`, `int`, `float`, `bool`, `list`, `dict`) that KFP serializes as JSON, hands to the step inside its executor input and records as values in ML Metadata. They suit a week label, a test fraction or a score. **Artifacts** are typed files. A component declares `articles: Input[Dataset]` or `model: Output[Model]` and writes to `model.path`, and the backend copies that file to `model.uri` under the pipeline root in the object store (SeaweedFS by default since KFP 2.15), recording `.metadata` and lineage. Returning 200,000 articles as one `str` output pushes a bulk payload through a channel meant for small values. It leaves no file in storage and no dataset in the lineage, so write a `Dataset` artifact instead.
code
python · 19 linesfrom kfp import dsl
from kfp.dsl import Dataset, Input, Metrics, Model, Output
@dsl.component(base_image='python:3.11', packages_to_install=['pandas', 'pyarrow'])
def split_dataset(articles: Input[Dataset], train: Output[Dataset],
test: Output[Dataset], test_fraction: float = 0.2):
import pandas as pd
df = pd.read_parquet(articles.path)
test_df = df.sample(frac=test_fraction, random_state=7)
test_df.to_parquet(test.path)
df.drop(test_df.index).to_parquet(train.path)
train.metadata['rows'] = len(df) - len(test_df)
@dsl.component(base_image='python:3.11')
def evaluate_model(model: Input[Model], test: Input[Dataset],
metrics: Output[Metrics]) -> float:
accuracy = 0.91 # stand-in for scoring model.path on test.path
metrics.log_metric('accuracy', accuracy)
return accuracygo deeper
Recall the split: built-in types are parameters for small values, Input and Output artifact types are for files such as datasets and models.
Explain the mechanics: parameters as JSON in the executor input and ML Metadata, artifacts written to .path and copied by the backend to .uri under the pipeline root.
Spot the defect in review: a corpus returned as a string, a model pickled into a parameter, a step writing straight to a bucket outside KFP's tracking, and say what each costs.
Decide what the team's data contract between steps is: which outputs must be tracked artifacts with lineage, where the pipeline root lives, and when a shared workspace volume is cheaper than copying.
## Two kinds of data between steps In Kubeflow Pipelines (KFP) v2 every component input and output belongs to one of two categories, and its type annotation decides which: | | Parameters | Artifacts | |---|---|---| | Annotation | `str`, `int`, `float`, `bool`, `list`, `dict` | `Input[Dataset]`, `Output[Model]`, `Output[Metrics]`, ... | | What moves | a JSON value | a file (or directory) in object storage | | Recorded as | a typed value in ML Metadata | an artifact with type, URI and metadata | | Meant for | small configuration and results | datasets, models, evaluation outputs | The KFP docs title their parameters page "Pass small amounts of data between components". That title is the whole design intent. ## How a parameter travels KFP serializes every parameter as JSON. For a Python component the SDK builds the container arguments around `--executor_input`, plus a placeholder that the backend fills at run time with the task's resolved inputs. The parameter value therefore rides inside that executor input. It is also stored in ML Metadata as one of the KFP types `string`, `number`, `boolean` or `object`. Output parameters work the same way in reverse. A Python component returns a value, or a `typing.NamedTuple` of several, and the next task reads it through `.output` or `.outputs['name']`. ## How an artifact travels With the traditional artifact syntax, which the open-source backend runs: 1. The backend gives each output artifact a `.uri` under the **pipeline root**, a path in an object-store bucket. 2. Inside the component, `.path` is a local filesystem path that corresponds to that `.uri`. 3. Your code writes the file at `model.path` and may annotate it, for example `model.metadata['framework'] = 'sklearn'`. 4. When the step ends, the backend copies the file from `.path` to `.uri` and records the artifact with its type and metadata. 5. A downstream task that declares `Input[Model]` receives the artifact and reads it from `.path`. It should treat that file as immutable. You never pass an output artifact when you call a component, and in this syntax you never return one either. The backend hands the function a pre-built output object to fill in. The newer Pythonic syntax, in which a component returns a `Model`, is not supported at run time by the open-source backend. ## Why a large parameter is a defect Picture an ingest step typed `-> str` that returns the week's 200,000 articles as one JSON string, which `split_dataset(corpus: str)` then parses: - **Wrong channel.** The payload is carried in the executor input of every consumer and stored as a parameter value in the metadata store. Both are built for small values, and very large ones risk running into size limits along the way. - **No stored file.** Nothing lands under the pipeline root, so there is no `.uri` to download, inspect or hand to another tool. - **No lineage.** The run's artifact lineage never shows a dataset flowing from ingest to train, and the UI displays a string where a dataset should be. - **Serialization cost.** Every consumer has to deserialize the whole corpus from JSON before it can do anything. The fix is to declare `articles: Output[Dataset]`, write Parquet to `articles.path`, and let `split_dataset(articles: Input[Dataset], ...)` read it. Keep parameters for the week label, `test_fraction` and the evaluation scores that later steps branch on. ## Artifact types `Artifact` is the generic base type and is compatible with every other type. The common subclasses are: - `Dataset` and `Model`: the workhorses of most pipelines; - `Metrics`: scalar metrics through `log_metric('accuracy', 0.91)`; - `ClassificationMetrics`, `SlicedClassificationMetrics`, `HTML`, `Markdown`: rendered specially in the KFP UI. The compiler type-checks artifact wiring, so feeding a `Model` output into an `Input[Dataset]` fails at compile time instead of in the middle of a run. ## A quick rule for reviews When you review a component signature, ask three questions about each input and output: 1. **Is it a file, or would it naturally be saved as one?** Then it is an artifact: `Dataset`, `Model`, `Metrics` or the generic `Artifact`. 2. **Will a later step branch on it, or will a person read it in the run's inputs?** Then it is a parameter: a label, a threshold, a score, a short list of names. 3. **Does it need to be found again next month?** An artifact has a `.uri` and a lineage record. A parameter value is only visible on the run that used it. A component that answers "file" but declares `str` is the defect this question is about. ## When even artifacts are heavy Copying large inputs through the object store at every step costs time and storage. KFP 2.15 added **Pipeline Run Workspaces**. `@dsl.pipeline(pipeline_config=dsl.PipelineConfig(workspace=dsl.WorkspaceConfig(size='250GB')))` creates a PVC that is mounted into every task pod, and components receive its mount path through `dsl.WORKSPACE_PATH_PLACEHOLDER`. Steps that share bulk files can use the volume, while the outputs worth tracking stay artifacts.
- Where do the artifact files actually land, and who decides?Under the pipeline root, a path in an object-store bucket. Operators set it cluster-wide with `defaultPipelineRoot` in the `kfp-launcher` ConfigMap, authors per pipeline with `@dsl.pipeline(pipeline_root=...)`, and callers per run with `pipeline_root=` on the client call. Since KFP 2.15 the default deployment ships SeaweedFS instead of MinIO. The artifacts' metadata, storage paths included, lives in an SQL database.
- Your steps shuttle tens of gigabytes between them; what did KFP 2.15 add for that?Pipeline Run Workspaces. `dsl.PipelineConfig(workspace=dsl.WorkspaceConfig(size=...))` on the pipeline creates a PVC mounted into every task pod, and `dsl.WORKSPACE_PATH_PLACEHOLDER` passes its mount path to components. `dsl.KubernetesWorkspaceConfig(pvcSpecPatch=...)` sets storage class and access modes. Bulk files stay on the volume rather than being uploaded and downloaded at each step.
- Passing a whole dataset as a JSON string parameter is fine if it fits
- Return the Model object from the function to create the output artifact
- Output artifacts must be given a bucket path when the component is called
- An input artifact's .uri is a local file path the code can open
- Editing an input artifact's file in place updates the upstream artifact
Assumes KFP SDK 2.17.0 and the open-source 2.17 backend; Pipeline Run Workspaces need KFP 2.15 or later, and SeaweedFS is the default object store deployment since 2.15.