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

[GSOC] optuna suggestion service logic update #2446

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

shashank-iitbhu
Copy link
Contributor

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #2374

Checklist:

  • Docs included if any changes are user facing

Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign gaocegege for approval. For more information see the Kubernetes Code Review Process.

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

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@mahdikhashan
Copy link
Contributor

I started reviewing this pr

cc: @andreyvelich

@mahdikhashan
Copy link
Contributor

/rerun-all

@mahdikhashan
Copy link
Contributor

@shashank-iitbhu would you please rerun the ci?

@shashank-iitbhu shashank-iitbhu force-pushed the feat/optuna-suggestion-service-update branch from edf98f0 to f263b26 Compare January 30, 2025 10:36
@shashank-iitbhu shashank-iitbhu marked this pull request as ready for review January 30, 2025 10:40
@shashank-iitbhu
Copy link
Contributor Author

@mahdikhashan still working on this PR, need some time. This is based on #2412 , so it makes sense to merge this once #2412 is merged.

@mahdikhashan
Copy link
Contributor

@mahdikhashan still working on this PR, need some time. This is based on #2412 , so it makes sense to merge this once #2412 is merged.

ok, take your time, are there any place which I can offer you help?

@Electronic-Waste
Copy link
Member

Hi @shashank-iitbhu, #2412 has been merged. We can work on this now!

But before that, could you please rebase your PR and resolve the errors in CI?

@mahdikhashan
Copy link
Contributor

Hi @shashank-iitbhu, #2412 has been merged. We can work on this now!

But before that, could you please rebase your PR and resolve the errors in CI?

@shashank-iitbhu shall we start reviewing it?

shashank-iitbhu and others added 4 commits February 3, 2025 18:13
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Co-authored-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
@shashank-iitbhu shashank-iitbhu force-pushed the feat/optuna-suggestion-service-update branch from f263b26 to 6b18e9b Compare February 3, 2025 12:46
@google-oss-prow google-oss-prow bot added size/M and removed size/XL labels Feb 3, 2025
@shashank-iitbhu
Copy link
Contributor Author

Hi @shashank-iitbhu, #2412 has been merged. We can work on this now!
But before that, could you please rebase your PR and resolve the errors in CI?

@shashank-iitbhu shall we start reviewing it?

Sure, I have rebased this PR also, I will let you know once this is ready for review.

@mahdikhashan
Copy link
Contributor

Hi @shashank-iitbhu, #2412 has been merged. We can work on this now!
But before that, could you please rebase your PR and resolve the errors in CI?

@shashank-iitbhu shall we start reviewing it?

Sure, I have rebased this PR also, I will let you know once this is ready for review.

thank you! feel free to ping me when you're ready. btw, we can also do a progressive review. would it work for you to review the existing code before finalizing it?

@andreyvelich
Copy link
Member

Hi @shashank-iitbhu, we have time until this Wednesday to merge this PR before we cut Katib RC.0.
Do you have enough time to finish it ?

Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
@google-oss-prow google-oss-prow bot added size/L and removed size/M labels Feb 3, 2025
@@ -50,7 +50,7 @@ def setup_method(self):
],
["cmaes", {"restart_strategy": "ipop", "sigma": "2", "random_state": "71"}],
["random", {"random_state": "71"}],
["grid", {"random_state": "71"}],
# ["grid", {"random_state": "71"}],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mahdikhashan @andreyvelich The unit tests are failing for this grid algorithm setting for param-11 and param-12 as here I am not specifying the step in parameters for param_type DOUBLE.
An Exception Error keeps raising due to call to convert_to_combinations method

elif parameter.type == DOUBLE:
if parameter.step == "" or parameter.step is None:
raise Exception(
"Param {} step is nil; For discrete search space, all parameters "
"must include step".format(parameter.name)
)

elif self.algorithm_name == "grid":
combinations = HyperParameterSearchSpace.convert_to_combinations(
self.search_space
)

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 tried to explicitly check for nil and set parameter.step to default 1 but then getting this error while running the unit tests.
E AssertionError: assert <StatusCode.DEADLINE_EXCEEDED: (4, 'deadline exceeded')> == <StatusCode.OK: (0, 'ok')>
How to deal with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can look into this tomorrow in early morning, hope its fine with you.

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems, to my current understanding of Optuna docs, that for grid algo, we need to have step defined. I'll investigate further with setting step and the second error.

Copy link
Contributor

Choose a reason for hiding this comment

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

image

I ran a deubg session and it seems that not all params are available in the search space - there should be param 10 and 11 - (i commented out 12s)

Copy link
Contributor

@mahdikhashan mahdikhashan Feb 4, 2025

Choose a reason for hiding this comment

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

I tried to explicitly check for nil and set parameter.step to default 1 but then getting this error while running the unit tests. E AssertionError: assert <StatusCode.DEADLINE_EXCEEDED: (4, 'deadline exceeded')> == <StatusCode.OK: (0, 'ok')> How to deal with this?

I could not figure out where we can change to handle it - will try to dig deeper later.

@shashank-iitbhu
Copy link
Contributor Author

shashank-iitbhu commented Feb 3, 2025

Hi @shashank-iitbhu, we have time until this Wednesday to merge this PR before we cut Katib RC.0. Do you have enough time to finish it ?

Hey @andreyvelich, I just pushed the changes for the unit tests and e2e tests. I’m facing an issue while testing the grid algorithm setting. Also, one more thing to note: Optuna does not directly support the normal distribution. Once the above issue is resolved, I believe we’re good to merge this.

https://optuna.readthedocs.io/en/stable/reference/distributions.html
cc @mahdikhashan

pkg/suggestion/v1beta1/hyperopt/base_service.py Outdated Show resolved Hide resolved
pkg/suggestion/v1beta1/optuna/base_service.py Outdated Show resolved Hide resolved
pkg/suggestion/v1beta1/optuna/base_service.py Outdated Show resolved Hide resolved
@@ -50,7 +50,7 @@ def setup_method(self):
],
["cmaes", {"restart_strategy": "ipop", "sigma": "2", "random_state": "71"}],
["random", {"random_state": "71"}],
["grid", {"random_state": "71"}],
# ["grid", {"random_state": "71"}],
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems, to my current understanding of Optuna docs, that for grid algo, we need to have step defined. I'll investigate further with setting step and the second error.

@@ -50,7 +50,7 @@ def setup_method(self):
],
["cmaes", {"restart_strategy": "ipop", "sigma": "2", "random_state": "71"}],
["random", {"random_state": "71"}],
["grid", {"random_state": "71"}],
# ["grid", {"random_state": "71"}],
Copy link
Contributor

Choose a reason for hiding this comment

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

image

I ran a deubg session and it seems that not all params are available in the search space - there should be param 10 and 11 - (i commented out 12s)

@Electronic-Waste
Copy link
Member

Thanks @shashank-iitbhu! And also thanks for reviewing this @mahdikhashan!

I have no extra comments on this PR. As for the normal distribution, does optuna have plans to support it? If the answer is yes, I would suggest that we could create a separate issue tracking this. If no, we could declare in the user doc that optuna algorithm only supports uniform and logUniform.

WDYT @kubeflow/wg-automl-leads @shashank-iitbhu @mahdikhashan @helenxie-bit

Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
elif param.distribution == api_pb2.LOG_UNIFORM:
# Log-uniform integer distribution: used for exponentially varying integers.
search_space[param.name] = optuna.distributions.IntDistribution(
low=max(1, int(param.min)),
Copy link
Member

Choose a reason for hiding this comment

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

Would this always be equal to 1 since values are always int 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.

Not always. The condition ensures that low is at least 1, which is required for log distributions. It prevents invalid cases where param.min could be 0 or negative.
As specified in the optuna documentation, If log is True, low must be larger than or equal to 1.

step=None,
)

elif param.type in {CATEGORICAL, DISCRETE}:
Copy link
Member

Choose a reason for hiding this comment

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

Should we use array here ?

Suggested change
elif param.type in {CATEGORICAL, DISCRETE}:
elif param.type in [CATEGORICAL, DISCRETE]:

min: "0.001"
max: "1"
step: "0.1"
distribution: uniform
Copy link
Member

Choose a reason for hiding this comment

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

Please add one parameters for Float and LogUniform

Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GSOC] Project 8: Support various Parameter Distribution in Katib
4 participants