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: check if parameter references exist in experiment parameters #1726

Merged

Conversation

henrysecond1
Copy link
Contributor

@henrysecond1 henrysecond1 commented Oct 29, 2021

What this PR does / why we need it:

Hi, we experienced that the users tend to make mistakes like below when creating experiments using new UI (Thanks for the nice UI update!)

When users set parameter references in trial templates like below,

image

they need to enter the parameter reference as same as the hyperparameter defined in the experiment spec.
The experiment is created without errors even if the users mistakenly set the wrong parameter reference.

I think it would be better to check the wrong parameter reference in the validating webhook
so that experiments are not created with the wrong parameter reference.

Please take a look, thanks!

@aws-kf-ci-bot
Copy link
Contributor

Hi @henrysecond1. 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.

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: henrysecond1
To complete the pull request process, please assign gaocegege after the PR has been reviewed.
You can assign the PR to them by writing /assign @gaocegege in a comment when ready.

The full list of commands accepted by this bot can be found 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

@coveralls
Copy link

coveralls commented Oct 29, 2021

Coverage Status

Coverage increased (+0.1%) to 73.71% when pulling 38b1770 on henrysecond1:fix/wrong-parameter-reference into 0a38e87 on kubeflow:master.

Copy link
Member

@anencore94 anencore94 left a comment

Choose a reason for hiding this comment

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

Thank you for such a nice contribution :) I think this feature helps many others

Comment on lines 291 to 294
// Check if parameter references exist in experiment parameters
if _, ok := experimentParameterNames[parameter.Reference]; !ok {
return fmt.Errorf("parameter reference %v does not exists in spec.Parameters: %v", parameter.Reference, instance.Spec.Parameters)
}
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, How about move these codes after

trialParametersNames[parameter.Name] = true
trialParametersRefs[parameter.Reference] = true

It may not important, but I feel like these should be right after codes right after checking duplicates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion, done :)

@@ -283,6 +288,10 @@ func (g *DefaultValidator) validateTrialTemplate(instance *experimentsv1beta1.Ex
if _, ok := trialParametersRefs[parameter.Reference]; ok {
return fmt.Errorf("parameter reference %v can't be duplicated in spec.trialTemplate.trialParameters: %v", parameter.Reference, trialTemplate.TrialParameters)
}
// Check if parameter references exist in experiment parameters
if _, ok := experimentParameterNames[parameter.Reference]; !ok {
return fmt.Errorf("parameter reference %v does not exists in spec.Parameters: %v", parameter.Reference, instance.Spec.Parameters)
Copy link
Member

Choose a reason for hiding this comment

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

nit: does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -283,6 +288,10 @@ func (g *DefaultValidator) validateTrialTemplate(instance *experimentsv1beta1.Ex
if _, ok := trialParametersRefs[parameter.Reference]; ok {
return fmt.Errorf("parameter reference %v can't be duplicated in spec.trialTemplate.trialParameters: %v", parameter.Reference, trialTemplate.TrialParameters)
}
// Check if parameter references exist in experiment parameters
Copy link
Member

Choose a reason for hiding this comment

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

nit: parameter reference exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 529 to 538
// Wrong parameter reference in trialParameters
{
Instance: func() *experimentsv1beta1.Experiment {
i := newFakeInstance()
i.Spec.TrialTemplate.TrialParameters[1].Reference = "wrong-ref"
return i
}(),
Err: true,
testDescription: "Wrong reference in Trial parameters",
},
Copy link
Member

Choose a reason for hiding this comment

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

nit: How about make this test case as invalidReferenceParameterTemplate or unknownReferenceParameterTemplate rather than validTemplate5?
Also, how about more detailed description? something like Trial template contains Trial Parameters which weren't referenced from spec.parameters

Copy link
Contributor Author

@henrysecond1 henrysecond1 Nov 1, 2021

Choose a reason for hiding this comment

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

I don't like the name validTemplate5 either and I agree that invalidReferenceParameterTemplate is better.. but I guess that some rules are applied to mock template names (maybe I misunderstood it?).

  • Mock templates with name validTemplate* have a valid job, while mock templates with specific names like missedParameterTemplate, invalidParameterTemplate have a invalid job.

So I named it as a validTemplate5 (since it has a valid job)... Please let me know if you still think it's better to name it as invalidReferenceParameterTemplate instead of validTemplate5?

I changed the description as you suggested, thanks :)

Copy link
Member

Choose a reason for hiding this comment

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

Since the validation logic was changed to check only it's empty, maybe we could change the test code :)
And in that case, yes the variable name validTemplate5 would be better.

@anencore94
Copy link
Member

/ok-to-test

@henrysecond1
Copy link
Contributor Author

@anencore94 Thanks for the review! PTAL

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for driving this @henrysecond1!
I left comment.

Comment on lines 295 to 297
if _, ok := experimentParameterNames[parameter.Reference]; !ok {
return fmt.Errorf("parameter reference %v does not exist in spec.parameters: %v", parameter.Reference, instance.Spec.Parameters)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think for NAS Experiments that doesn't work.
For example, for the ENAS Experiment, the Suggestion returns architecture and nn_config which don't exist in spec.Parameters.
For HP Experiments, currently all parameters that Suggestions return exist in spec.parameters, but I am not sure if for other AutoML techniques that always be true (for example for PBT, AutoMC, etc.).

I think for now, we can check if experimentParameterNames is not empty than we can apply this check.

WDYT @henrysecond1 @anencore94 @gaocegege @johnugeorge ?

Copy link
Member

Choose a reason for hiding this comment

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

SGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andreyvelich Thank you for pointing it out. Sounds good to me, too :)

Copy link
Member

Choose a reason for hiding this comment

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

Yes that make sense ! Thanks

@google-oss-prow google-oss-prow bot added size/M and removed size/S labels Nov 8, 2021
@henrysecond1
Copy link
Contributor Author

@anencore94 @andreyvelich I updated the test code (for the case when spec.parameters is empty). Could you re-check PR? Thanks for your time.

@andreyvelich
Copy link
Member

Thank you for updating this @henrysecond1!
/lgtm
/assign @gaocegege @johnugeorge

@johnugeorge
Copy link
Member

/lgtm

Copy link
Member

@gaocegege gaocegege left a comment

Choose a reason for hiding this comment

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

/lgtm

@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gaocegege, henrysecond1

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 google-oss-robot merged commit cffab07 into kubeflow:master Nov 9, 2021
@henrysecond1 henrysecond1 deleted the fix/wrong-parameter-reference branch November 9, 2021 15:17
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.

8 participants