Skip to content
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

feat(sdk): add runtime logic for custom artifact types (support for custom artifact types pt. 3) #8233

Conversation

connor-mccarthy
Copy link
Member

@connor-mccarthy connor-mccarthy commented Sep 1, 2022

Description of your changes:
Adds runtime handling to support use of custom artifact types from non-kfp libraries in lightweight components. This includes:

  • Inferring import statement and injecting into ephemeral_component.py at runtime
  • Constructing a custom artifact type instance and passing it into the component

Checklist:

@google-oss-prow
Copy link

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@connor-mccarthy
Copy link
Member Author

/test all

@connor-mccarthy connor-mccarthy changed the title feat(sdk): add runtime logic for custom artifact types feat(sdk): add runtime logic for custom artifact types (support for custom artifact types pt. 3) Sep 1, 2022
@connor-mccarthy connor-mccarthy force-pushed the add-custom-artifact-type-runtime-logic branch from 189a579 to d74f0cf Compare September 2, 2022 23:20
@connor-mccarthy connor-mccarthy changed the title feat(sdk): add runtime logic for custom artifact types (support for custom artifact types pt. 3) feat(sdk): add runtime logic for google artifact types (support for custom artifact types pt. 3) Sep 12, 2022
@connor-mccarthy connor-mccarthy force-pushed the add-custom-artifact-type-runtime-logic branch from d74f0cf to 2dd1d94 Compare September 12, 2022 20:10
@connor-mccarthy
Copy link
Member Author

/retest

@connor-mccarthy
Copy link
Member Author

/retest

@connor-mccarthy connor-mccarthy marked this pull request as ready for review September 12, 2022 21:02
@google-oss-prow google-oss-prow bot requested a review from james-jwu September 12, 2022 21:03
@connor-mccarthy connor-mccarthy changed the title feat(sdk): add runtime logic for google artifact types (support for custom artifact types pt. 3) feat(sdk): add runtime logic for custom artifact types (support for custom artifact types pt. 3) Sep 12, 2022
sdk/python/kfp/components/executor.py Outdated Show resolved Hide resolved
sdk/python/kfp/components/executor.py Outdated Show resolved Hide resolved
sdk/python/kfp/components/executor.py Outdated Show resolved Hide resolved
sdk/python/kfp/components/executor_test.py Outdated Show resolved Hide resolved
sdk/python/kfp/components/executor_test.py Outdated Show resolved Hide resolved
sdk/python/kfp/components/types/custom_artifact_types.py Outdated Show resolved Hide resolved
for arg in args:
annotation = arg.annotation
# Handle InputPath() and OutputPath()
if isinstance(annotation, ast.Call):
Copy link
Member

Choose a reason for hiding this comment

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

Don't quite follow the code, would it falls into this condition if users mistakenly use Input(...), and what if it's some other unexpected calls like PipelineParam(...)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed offline and removed handling for InputPath and OutputPath.

I agree that we should program more defensively around unexpected inputs, though I think this belongs in the kfp.components.extract_component_interface function. The issue of liberal acceptance of annotations is an issue that precedes this PR. WDYT about this as a separate work item?

Copy link
Member

Choose a reason for hiding this comment

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

though I think this belongs in the kfp.components.extract_component_interface function

I think you're probably right. I recall we do check and make sure the type annotation is one of our known usage, otherwise there will be compilation errors. As long as this change doesn't introduce regression to this UX, which I now think it probably doesn't, we should be all good.

sdk/python/requirements.in Outdated Show resolved Hide resolved
@connor-mccarthy
Copy link
Member Author

/retest

@google-oss-prow
Copy link

google-oss-prow bot commented Sep 13, 2022

@connor-mccarthy: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
kubeflow-pipelines-samples-v2 c99378a link true /test kubeflow-pipelines-samples-v2

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@connor-mccarthy connor-mccarthy marked this pull request as ready for review September 13, 2022 21:30
@connor-mccarthy
Copy link
Member Author

With fcd56b3 I implemented some significant refactoring which makes the code not only cleaner, but also safer by not going down the ast parsing code path unless required. Before this commit, the code used ast parsing for every lightweight component function.

Copy link
Member

@chensun chensun left a comment

Choose a reason for hiding this comment

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

/lgtm

sdk/python/kfp/components/executor_test.py Outdated Show resolved Hide resolved
sdk/python/kfp/components/executor_test.py Outdated Show resolved Hide resolved
sdk/python/kfp/components/executor_test.py Outdated Show resolved Hide resolved
"third_message": "World"
}
},
"outputs": {
"parameters": {
"output": {
"Output": {
Copy link
Member

Choose a reason for hiding this comment

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

Curious why do we have this diff? I guess executor input json is case-insensitive, you made the change so that it's more "correct" as KFP use Output as single return output name?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's exactly it: when a component of this type is executed this is what the executor input looks like.

sdk/python/kfp/components/executor_test.py Show resolved Hide resolved
@@ -483,59 +615,63 @@ def test_artifact_output(self):
}
"""

def test_func(first: str, second: str) -> Artifact:
def test_func(first: str, second: str, output: Output[Artifact]) -> str:
Copy link
Member

Choose a reason for hiding this comment

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

Keep a test case with -> Artifact? (likely don't need to change this test func at all)

'artifact_class_base_symbol': 'c',
'qualname': 'a.b.c.d.e',
'expected': 'a.b.c'
},
Copy link
Member

Choose a reason for hiding this comment

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

For my education, what would be a real-world case for the last case?

Copy link
Member Author

Choose a reason for hiding this comment

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

The case is where a user annotates with an artifact defined deeply in a package, but only imports a high-level module:

For example:

from google.cloud import aiplatform

@dsl.component
def comp(vertex_model: Output[aiplatform.metadata.schema.google.artifact_schema.VertexModel]):
    ....

@connor-mccarthy
Copy link
Member Author

/unhold

Copy link
Member

@chensun chensun left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks!

@google-oss-prow google-oss-prow bot added the lgtm label Sep 15, 2022
@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chensun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-prow google-oss-prow bot merged commit 166d6bb into kubeflow:master Sep 15, 2022
jlyaoyuli pushed a commit to jlyaoyuli/pipelines that referenced this pull request Jan 5, 2023
…ustom artifact types pt. 3) (kubeflow#8233)

* add runtime artifact instance creation logic

* refactor executor

* add executor tests

* add custom artifact type import handling and tests

* fix artifact class construction

* fix custom artifact type in tests

* add typing extensions dependency for all python versions

* use mock google namespace artifact for tests

* remove print statement

* update google artifact golden snapshot

* resolve some review feedback

* remove handling for OutputPath and InputPath custom artifact types; update function names and tests

* clarify named tuple tests

* update executor tests

* add artifact return and named tuple support; refactor; clean tests

* implement review feedback; clean up artifact names

* move test method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants