> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Passing Data Between Components Parameters

> Shows how to pass scalar parameters between Kubeflow Pipelines components using a train_model returning accuracy and evaluate_model consuming it, plus compilation, UI inspection, and best practices.

This lesson shows how to pass simple scalar values between components in a Kubeflow Pipelines (KFP) v2 pipeline using parameters. Parameters are intended for small, simple values — for example hyperparameters, evaluation metrics, or scalar flags. For large or complex outputs (models, datasets, binary files), use artifacts instead.

What you'll learn:

* How to return a scalar value from one component.
* How to pass that scalar value as an input parameter to another component.
* Best practices and when to use parameters vs artifacts.

## Overview of the example

We implement two components:

* `train_model`: performs (mock) training and returns a scalar accuracy (`float`).
* `evaluate_model`: receives the `accuracy` and an optional `threshold` and prints whether the model passed.

Pattern: return the scalar from the training task, then pass `train_task.output` to the evaluation component.

## Example implementation (KFP v2 DSL)

```python theme={null}
from kfp.v2 import compiler
from kfp.v2.dsl import component, pipeline

@component
def train_model() -> float:
    # Pretend training logic
    epochs = 10
    accuracy = 0.91 + (epochs * 0.001)  # 0.92
    return accuracy

@component
def evaluate_model(accuracy: float, threshold: float = 0.92):
    if accuracy >= threshold:
        print(f"Model passed with accuracy {accuracy}")
    else:
        print(f"Model failed with accuracy {accuracy}")

@pipeline(name="parameter-passing-example")
def ml_pipeline():
    train_task = train_model()
    # Pass the scalar output of train_task into evaluate_model
    evaluate_model(accuracy=train_task.output)

if __name__ == "__main__":
    # Compile the pipeline into a YAML file
    compiler.Compiler().compile(
        pipeline_func=ml_pipeline,
        package_path='passing-data-parameters.yaml'
    )
```

Notes on the code

* Annotate `train_model` with `-> float` so the component output type matches the returned value.
* `evaluate_model` declares `accuracy` and an optional `threshold` (default `0.92`).
* Inside the pipeline, capture the task returned by `train_model()` and pass `train_task.output` to `evaluate_model(...)`.
* The compiler produces a pipeline specification YAML (`passing-data-parameters.yaml`) you can upload to the Kubeflow UI.

## Quick reference: component responsibilities

| Component | Responsibility | Example output |
| - | - | - |
| `train_model` | Run training and return scalar metric | `0.92` |
| `evaluate_model` | Read accuracy parameter and compare against `threshold` | Console log `Model passed with accuracy 0.92` |

## Compile and run (high-level steps)

1. Save the Python script (e.g., `pipeline.py`) containing the example above.
2. Run the script locally to compile the pipeline:
   * `python pipeline.py` will generate `passing-data-parameters.yaml`.
3. Upload the YAML to the Kubeflow Pipelines UI:
   * In the UI, choose "Upload pipeline" → select `passing-data-parameters.yaml` → create a run.
4. Inspect the run once it finishes:
   * View each step’s Inputs / Outputs panels to verify the scalar parameter was passed correctly.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/MGkgrGfKHDtoCnUb/images/Kubeflow/Working-With-Kubeflow/Demo-Passing-Data-Between-Components-Parameters/kubeflow-new-pipeline-file-dialog.jpg?fit=max&auto=format&n=MGkgrGfKHDtoCnUb&q=85&s=ab747cc4c3eae95e89bb6a00f85ecbae" alt="A Kubeflow Central Dashboard &#x22;New Pipeline&#x22; page is visible with a macOS file-open dialog overlaid, showing files like parameters.yaml and several .py scripts. The Kubeflow navigation menu is shown on the left." width="1920" height="1080" data-path="images/Kubeflow/Working-With-Kubeflow/Demo-Passing-Data-Between-Components-Parameters/kubeflow-new-pipeline-file-dialog.jpg" />
</Frame>

## What to expect in the UI

Once the run completes, open the execution details for the evaluation step. You should see the scalar passed as an input parameter for that step (for this example, `0.92`) and the usual executor logs under output artifacts.

Example UI-style summary (simplified):

```text theme={null}
This step corresponds to execution "evaluate-model".

Input Parameters
accuracy 0.92

Output Artifacts
executor-logs
minio://mlpipeline/private-artifacts/...
```

## Best practices and guidance

* Use parameters for small scalar values (hyperparameters, thresholds, scalar metrics).
* Use artifacts to pass models, datasets, or other large/complex outputs.
* Always type your component outputs (e.g., `-> float`) so the compiler generates the correct component schema.

<Callout icon="lightbulb" color="#1CB2FE">
  Use parameters only for small, simple data such as hyperparameters or scalar metrics. For models, datasets, or any large/complex outputs, use artifacts instead.
</Callout>

## Useful links and references

* Kubeflow Pipelines documentation: [https://www.kubeflow.org/docs/components/pipelines/](https://www.kubeflow.org/docs/components/pipelines/)
* KFP SDK / DSL reference: [https://www.kubeflow.org/docs/components/pipelines/sdk/overview/](https://www.kubeflow.org/docs/components/pipelines/sdk/overview/)
* Compiler docs: [https://github.com/kubeflow/pipelines/tree/master/sdk/python/kfp/v2](https://github.com/kubeflow/pipelines/tree/master/sdk/python/kfp/v2)

<Callout icon="warning" color="#FF6B6B">
  Do not use parameters to pass large data. Attempting to serialize large objects as parameters can lead to failures or timeouts. Use artifact storage (e.g., MinIO/GCS) for models, datasets, and other heavy outputs.
</Callout>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/kubeflow/module/bece8da9-953e-480e-8774-b25b66c3830f/lesson/e0742b0e-4aa8-41dc-ab4e-d9d0483d4fec" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.