-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support applying Lightweight Python components in Pipeline SDK #770
Changes from all commits
17da6e1
acbd84a
b13bee6
6036089
e137632
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from .lightweight_component import Image, PythonComponent, lightweight_component # noqa | ||
from .pipeline import ( # noqa | ||
VALID_ACCELERATOR_TYPES, | ||
VALID_VERTEX_ACCELERATOR_TYPES, | ||
ComponentOp, | ||
Dataset, | ||
Pipeline, | ||
Resources, | ||
VALID_ACCELERATOR_TYPES, | ||
VALID_VERTEX_ACCELERATOR_TYPES, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import typing as t | ||
from dataclasses import dataclass | ||
from functools import wraps | ||
|
||
|
||
@dataclass | ||
class Image: | ||
base_image: str = "fondant:latest" | ||
extra_requires: t.Optional[t.List[str]] = None | ||
script: t.Optional[str] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the script is needed for the sagemaker runner? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For every runner, since the script is not baked into the image. In the docker & KfP runner, we'll probably include the script in the entrypoint instead of uploading it separately though. |
||
|
||
|
||
class PythonComponent: | ||
@classmethod | ||
def image(cls) -> Image: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for this not to be a (class)property? |
||
raise NotImplementedError | ||
|
||
|
||
def lightweight_component( | ||
extra_requires: t.Optional[t.List[str]] = None, | ||
base_image: t.Optional[str] = None, | ||
): | ||
"""Decorator to enable a python component.""" | ||
|
||
def wrapper(cls): | ||
kwargs = {} | ||
if base_image: | ||
kwargs["base_image"] = base_image | ||
if extra_requires: | ||
kwargs["extra_requires"] = extra_requires | ||
image = Image(**kwargs) | ||
|
||
# updated=() is needed to prevent an attempt to update the class's __dict__ | ||
@wraps(cls, updated=()) | ||
class AppliedPythonComponent(cls, PythonComponent): | ||
@classmethod | ||
def image(cls) -> Image: | ||
return image | ||
|
||
return AppliedPythonComponent | ||
|
||
return wrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should link this to the installed version of Fondant once we add the CI/CD for this.