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

fix(sdk): Allow keyword-only arguments in pipeline function signature #4544

Merged

Conversation

Udiknedormin
Copy link
Contributor

Support keyword-only arguments in pipeline function during compilation. Solves #4543, this is the suggested solution described there. Also adds test to check if the problem was solved

It seems it could be cherry-picked in the current release branch.

@kubeflow-bot
Copy link

This change is Reviewable

@k8s-ci-robot
Copy link
Contributor

Hi @Udiknedormin. Thanks for your PR.

I'm waiting for a kubeflow member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

arg_type = None
for input in pipeline_meta.inputs or []:
if arg_name == input.name:
arg_type = input.type
break
args_list.append(dsl.PipelineParam(sanitize_k8s_name(arg_name, True), param_type=arg_type))
param = dsl.PipelineParam(sanitize_k8s_name(arg_name, True), param_type=arg_type)
if arg.kind == inspect.Parameter.KEYWORD_ONLY:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can put all arguments in a dictionary and then just use signature.bind which will sort out what goes where?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it would work with position-only arguments:

def foo(a: str, /, b: str, *, c: str):
    print(a, b, c)

import inspect
sig = inspect.signature(foo)

kargs = {"a": "A", "b": "B", "c": "C"}
bound_arguments = sig.bind(**kwargs) # Error: "a" is positional-only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Position-only arguments won't work with kwargs in signature.bind:

def foo(a: str, /, b: str, *, c: str): ...
    
import inspect
sig = inspect.signature(foo)

kwargs = {"a": "A", "b": "B", "c": "C"}
bound_arguments = sig.bind(**kwargs) # Error: "a" is positional-only

args = ["A"]
kwargs = {"b": "B", "c": "C"}
bound_arguments = sig.bind(**kwargs) # ok, no error

So it seems to me that the easiest approach is to only bound keyword-only arguments to kwargs, and the rest arguments to args.

@Ark-kun
Copy link
Contributor

Ark-kun commented Sep 26, 2020

/ok-to-test
/lgtm

def test_keyword_only_argument_for_pipeline_func(self):
def some_pipeline(casual_argument: str, *, keyword_only_argument: str):
pass
kfp.compiler.Compiler().compile(some_pipeline)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can pass None as path.

Copy link
Contributor Author

@Udiknedormin Udiknedormin Oct 2, 2020

Choose a reason for hiding this comment

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

Oh, right! I saw _compile in tests but it was marked as "deprecated", so I just mindlessly replaced it, I guess... It should be _create_workflow.

Copy link
Contributor

Choose a reason for hiding this comment

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

_compile is fine as well. We might de-deprecate it... The deprecation was due to a way TFX SDK was using the private compiler functions.

@Udiknedormin
Copy link
Contributor Author

@Ark-kun I can see test failed with:

sample-test-ns84j-2459195470: ERROR: Could not find a version that satisfies the requirement tensorflow==1.8.0
  (from versions:
    1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2,
    1.14.0rc0, 1.14.0rc1, 1.14.0,
    1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 1.15.2, 1.15.3, 1.15.4,
    2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.0.3,
    2.1.0rc0, 2.1.0rc1, 2.1.0rc2, 2.1.0, 2.1.1, 2.1.2,
    2.2.0rc0, 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0, 2.2.1,
    2.3.0rc0, 2.3.0rc1, 2.3.0rc2, 2.3.0, 2.3.1)
sample-test-ns84j-2459195470: ERROR: No matching distribution found for tensorflow==1.8.0

Looks like a dependency problem unrelated to this PR.

@Ark-kun
Copy link
Contributor

Ark-kun commented Oct 6, 2020

/lgtm

@Ark-kun
Copy link
Contributor

Ark-kun commented Oct 12, 2020

/approve

@k8s-ci-robot k8s-ci-robot removed the lgtm label Oct 15, 2020
@Ark-kun
Copy link
Contributor

Ark-kun commented Oct 17, 2020

/retest
/lgtm

@Ark-kun
Copy link
Contributor

Ark-kun commented Oct 17, 2020

/hold

pipeline_func_arg = basic.save_most_frequent_word

# clone name and description
@dsl.pipeline(
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps @pipeline is not needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should have the same name and description as save_most_frequent_word, so it seems to me it does.

@k8s-ci-robot k8s-ci-robot removed the lgtm label Nov 19, 2020
@Udiknedormin
Copy link
Contributor Author

@Ark-kun I applied your suggestions.

@Ark-kun
Copy link
Contributor

Ark-kun commented Nov 21, 2020

Thank you for your contribution and your patience.
/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Ark-kun, Udiknedormin

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

@Ark-kun
Copy link
Contributor

Ark-kun commented Dec 16, 2020

/hold cancel

@k8s-ci-robot
Copy link
Contributor

@Udiknedormin: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
kubeflow-pipeline-e2e-test 83e8b84 link /test kubeflow-pipeline-e2e-test
kubeflow-pipeline-sample-test 83e8b84 link /test kubeflow-pipeline-sample-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

@Udiknedormin
Copy link
Contributor Author

@Ark-kun Is there anything more that needs to be done before this PR is merged?

@k8s-ci-robot k8s-ci-robot removed the lgtm label Jan 30, 2021
@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Ark-kun, Udiknedormin

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-robot
Copy link

New changes are detected. LGTM label has been removed.

@Ark-kun
Copy link
Contributor

Ark-kun commented Jan 30, 2021

@Ark-kun Is there anything more that needs to be done before this PR is merged?

I do not think so. I've approved this PR on Nov 21.

Re-LGTMing after fixing the merge conflict

/lgtm

@google-oss-robot google-oss-robot merged commit ce985bc into kubeflow:master Jan 30, 2021
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.

5 participants