Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
A collection of reusable components and pipelines for Kubeflow Pipelines.

Usage:
from kfp_components import components, pipelines
from kfp_components.components import training
from kfp_components.pipelines import evaluation
from library import components, pipelines
from library.components import training
from library.pipelines import evaluation
"""

# Import submodules to enable the convenient import patterns shown above
Expand All @@ -17,5 +17,5 @@
# Fallback to absolute imports (works during testing with sys.path modification)
import components # noqa: F401
import pipelines # noqa: F401

__all__ = ["components", "pipelines"]
#since the

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 20 has an incomplete comment (#since the) which looks accidental and will fail style/lint checks. Please remove it or replace it with a complete explanation.

Suggested change
#since the
# Re-export the package's public submodules.

Copilot uses AI. Check for mistakes.
__all__ = ["pipelines", "components"]
12 changes: 0 additions & 12 deletions components/__init__.py

This file was deleted.

8 changes: 0 additions & 8 deletions components/data_processing/__init__.py

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions components/deployment/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions components/deployment/component_valid/OWNERS

This file was deleted.

8 changes: 0 additions & 8 deletions components/evaluation/__init__.py

This file was deleted.

8 changes: 0 additions & 8 deletions components/training/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions library/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Toplevel package for reusable library components and pipelines."""
5 changes: 5 additions & 0 deletions library/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Convenience imports for the reusable component categories in ``library``."""

from . import data_processing, deployment, evaluation, training

__all__ = ["data_processing", "deployment", "evaluation", "training"]
4 changes: 4 additions & 0 deletions library/components/data_processing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Data processing components exposed under ``library.components.data_processing``."""

# Auto-generated imports will be added here by scripts/update_init_imports.py
# Components will be imported dynamically based on subdirectories
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
within Kubeflow Pipelines.
"""

import kfp.compiler
from kfp import dsl


Expand Down Expand Up @@ -262,7 +261,9 @@ def sdg(


if __name__ == "__main__":
kfp.compiler.Compiler().compile(
from kfp import compiler

compiler.Compiler().compile(
sdg,
package_path=__file__.replace(".py", "_component.yaml"),
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,7 @@ Downloads the yoda_sentences dataset from HuggingFace, renames columns to match

## Metadata 🗂️

- **Name**: yoda_data_processor
- **Stability**: alpha
- **Dependencies**:
- Kubeflow:
- Name: Pipelines, Version: >=2.15.2
- External Services:
- Name: HuggingFace Datasets, Version: >=4.4.2
- **Tags**:
- data_processing
- dataset_preparation
- text_processing
- yoda_speak
- translation
- **Last Verified**: 2025-12-19 11:30:16+00:00
- **Owners**:
- Approvers:
- mprahl
- nsingla
- Reviewers:
- HumairAK
See [metadata.yaml](metadata.yaml) for the component's tags, dependencies, owners, and last verification date.

## Additional Resources 📚

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import kfp.compiler
from kfp import dsl


def add_yoda_prefix(example: dict[str, str]) -> dict[str, str]:
"""Prefix a prompt with the Yoda translation instruction."""
updated_example = dict(example)
updated_example["prompt"] = "Translate the following to Yoda speak: " + updated_example["prompt"]
return updated_example


@dsl.component(
packages_to_install=["datasets"],
)
Expand Down Expand Up @@ -35,10 +41,6 @@ def prepare_yoda_dataset(
# Add prefix to prompts
print("Adding Yoda speak prefix to prompts")

def add_yoda_prefix(example):
example["prompt"] = "Translate the following to Yoda speak: " + example["prompt"]
return example

dataset = dataset.map(add_yoda_prefix)

# Split the dataset into train and eval sets
Expand All @@ -63,7 +65,9 @@ def add_yoda_prefix(example):


if __name__ == "__main__":
kfp.compiler.Compiler().compile(
from kfp import compiler

compiler.Compiler().compile(
prepare_yoda_dataset,
package_path=__file__.replace(".py", "_component.yaml"),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""Shared test helpers for yoda_data_processor tests."""

import json
import random
from pathlib import Path


class InMemoryDataset:
"""A tiny dataset double that preserves transformation behavior."""

def __init__(self, rows: list[dict[str, str]]):
"""Initialize the dataset with a copy of the provided rows."""
self.rows = [dict(row) for row in rows]

def __len__(self) -> int:
"""Return the number of rows in the dataset."""
return len(self.rows)

def rename_column(self, old_name: str, new_name: str) -> "InMemoryDataset":
"""Return a dataset with one column renamed."""
return InMemoryDataset(
[
{
(new_name if key == old_name else key): value
for key, value in row.items()
}
for row in self.rows
]
)

def remove_columns(self, columns: list[str]) -> "InMemoryDataset":
"""Return a dataset without the requested columns."""
columns_to_remove = set(columns)
return InMemoryDataset(
[
{
key: value
for key, value in row.items()
if key not in columns_to_remove
}
for row in self.rows
]
)

def map(self, transform) -> "InMemoryDataset":
"""Return a dataset with the transform applied to each row."""
return InMemoryDataset([transform(dict(row)) for row in self.rows])

def train_test_split(self, test_size: float, seed: int) -> dict[str, "InMemoryDataset"]:
"""Split the dataset deterministically into train and test subsets."""
shuffled_rows = [dict(row) for row in self.rows]
random.Random(seed).shuffle(shuffled_rows)

test_count = min(len(shuffled_rows), max(1, int(round(len(shuffled_rows) * test_size))))
split_index = len(shuffled_rows) - test_count
return {
"train": InMemoryDataset(shuffled_rows[:split_index]),
"test": InMemoryDataset(shuffled_rows[split_index:]),
}

def save_to_disk(self, path: str) -> None:
"""Persist rows in a simple JSONL file within the output directory."""
output_dir = Path(path)
output_dir.mkdir(parents=True, exist_ok=True)
with output_dir.joinpath("data.jsonl").open("w", encoding="utf-8") as handle:
for row in self.rows:
handle.write(json.dumps(row) + "\n")


def sample_rows() -> list[dict[str, str]]:
"""Return a representative input dataset for Yoda processor tests."""
return [
{
"sentence": "Train yourself to let go of everything you fear to lose.",
"translation_extra": "Let go of everything you fear to lose, train yourself to.",
"translation": "unused-1",
},
{
"sentence": "Do or do not. There is no try.",
"translation_extra": "Do or do not. Try, there is not.",
"translation": "unused-2",
},
{
"sentence": "Named must your fear be before banish it you can.",
"translation_extra": "Before banish it you can, named must your fear be.",
"translation": "unused-3",
},
{
"sentence": "Wars not make one great.",
"translation_extra": "Great, wars make one not.",
"translation": "unused-4",
},
{
"sentence": "Pass on what you have learned.",
"translation_extra": "What you have learned, pass on.",
"translation": "unused-5",
},
]


def read_saved_rows(path: Path) -> list[dict[str, str]]:
"""Load the saved JSONL rows from a component output directory."""
data_file = path / "data.jsonl"
return [
json.loads(line)
for line in data_file.read_text(encoding="utf-8").splitlines()
if line
]
Loading
Loading