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

Support for grid search algorithm in Optuna Suggestion Service #2060

Merged

Conversation

tenzen-y
Copy link
Member

@tenzen-y tenzen-y commented Dec 13, 2022

Signed-off-by: Yuki Iwai yuki.iwai.tz@gmail.com

What this PR does / why we need it:
I added a mechanism to support grid search in Optuna Suggestion Service since we will remove Chocolate Suggestion Service as mentioned in #2058.

Also, I switched the default Suggestion Service for grid search to Optuna Suggestion Service in katib-config.

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

Checklist:

  • Docs included if any changes are user facing

@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tenzen-y

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

@tenzen-y tenzen-y changed the title [WIP] Support grid search in Optuna Suggestion Service [WIP] Support for grid search algorithm in Optuna Suggestion Service Dec 13, 2022
@tenzen-y tenzen-y force-pushed the support-for-grid-search-in-optuna branch from 04b7d02 to 31b2d82 Compare December 13, 2022 19:07
@tenzen-y tenzen-y force-pushed the support-for-grid-search-in-optuna branch from 6ba7852 to 9990aca Compare December 13, 2022 20:54
@tenzen-y tenzen-y changed the title [WIP] Support for grid search algorithm in Optuna Suggestion Service Support for grid search algorithm in Optuna Suggestion Service Dec 13, 2022
@tenzen-y
Copy link
Member Author

/hold for the review

/assign @andreyvelich @johnugeorge @anencore94

assert code == grpc.StatusCode.INVALID_ARGUMENT

# [RANDOM] Invalid random_state
@pytest.mark.parametrize(
Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, we would be good to do refactoring unit tests using @pytest.mark.parametrize in other suggestion services, same as this.

We can follow up with other PRs.

Copy link
Member

Choose a reason for hiding this comment

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

I like this feature of PyTest, thanks!

pkg/suggestion/v1beta1/optuna/service.py Show resolved Hide resolved
pkg/suggestion/v1beta1/internal/search_space.py Outdated Show resolved Hide resolved
Comment on lines +212 to +213
if max_trial_count > num_combinations:
return False, "Max Trial Count: {max_trial} > all possible search combinations: {combinations}".\
format(max_trial=max_trial_count, combinations=num_combinations)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar with optuna, Is it ok to set max_trial_count < num_combinations ? since with the documentation GridSampler looks like always trying to search all possible combinations.

Copy link
Member Author

@tenzen-y tenzen-y Dec 17, 2022

Choose a reason for hiding this comment

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

Yes, that's right about optuna behavior. Although optuna suggestion-service creates trials using already used parameters after all combinations used.

for _ in range(current_request_number):
optuna_trial = self.study.ask(fixed_distributions=self._get_optuna_search_space())
assignments = [Assignment(k, v) for k, v in optuna_trial.params.items()]
list_of_assignments.append(assignments)
assignments_key = self._get_assignments_key(assignments)
self.assignments_to_optuna_number[assignments_key].append(optuna_trial.number)

This does not mean the optuna suggestion service can remove duplicated suggestions in the above section since the suggestionclient faces the error in the following:

logger.Info("Getting suggestions", "endpoint", endpoint, "Number of current request parameters", currentRequestNum, "Number of response parameters", len(responseSuggestion.ParameterAssignments))
if len(responseSuggestion.ParameterAssignments) != currentRequestNum {
err := fmt.Errorf("The response contains unexpected trials")
logger.Error(err, "The response contains unexpected trials")
return err
}

Also, if users want to run experiments using all combinations, users can skip setting maxTrialCount in the Experiment.

For these reasons, it would be good to provide that validation.

@anencore94 Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Yeap I see now. Thanks for your kind reply :)

@tenzen-y tenzen-y force-pushed the support-for-grid-search-in-optuna branch from 2f94b40 to f661f59 Compare December 17, 2022 16:14
@tenzen-y
Copy link
Member Author

PTAL
/assign @kubeflow/wg-automl-leads

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.

combinations[parameter.name] = range(int(parameter.min), int(parameter.max)+1, int(parameter.step))
elif parameter.type == DOUBLE:
if parameter.step == "" or parameter.step is None:
raise Exception("Param {} step is nil".format(parameter.name))
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 also say that: "For discrete search space all parameters must include step" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good. It helps to debug parameters.

assert code == grpc.StatusCode.INVALID_ARGUMENT

# [RANDOM] Invalid random_state
@pytest.mark.parametrize(
Copy link
Member

Choose a reason for hiding this comment

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

I like this feature of PyTest, thanks!

@tenzen-y tenzen-y force-pushed the support-for-grid-search-in-optuna branch from e7ac972 to 2cb4d86 Compare December 23, 2022 15:07
@tenzen-y
Copy link
Member Author

tenzen-y commented Dec 23, 2022

Thank you for this effort @tenzen-y! We should also update the docs:

@andreyvelich Thanks for the review and pointing out sections we need to update the documentation!
I will add a PR to update the documentation.

Comment on lines +52 to +55
raise Exception(
"Param {} step is nil; For discrete search space, all parameters must include step".
format(parameter.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.

@andreyvelich I updated this error message.

@tenzen-y
Copy link
Member Author

@andreyvelich I addressed your comments; please take another look.

@andreyvelich
Copy link
Member

Thank you @tenzen-y! We are going to remove Chocolate references in the following PRs, right ?
/lgtm
/assign @johnugeorge @anencore94

@google-oss-prow google-oss-prow bot added the lgtm label Dec 23, 2022
@tenzen-y
Copy link
Member Author

Thank you @tenzen-y! We are going to remove Chocolate references in the following PRs, right ? /lgtm /assign @johnugeorge @anencore94

Yes, I will create another PR to remove all codes for Chocolate after this PR is merged.

@tenzen-y
Copy link
Member Author

Blocked by: #2070

Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
@tenzen-y tenzen-y force-pushed the support-for-grid-search-in-optuna branch from 2cb4d86 to 339e67f Compare December 24, 2022 04:23
@google-oss-prow google-oss-prow bot removed the lgtm label Dec 24, 2022
@tenzen-y
Copy link
Member Author

@johnugeorge @anencore94 I rebased to take #2070. PTAL.

@johnugeorge
Copy link
Member

/lgtm

Thanks @tenzen-y

@google-oss-prow google-oss-prow bot added the lgtm label Dec 24, 2022
@tenzen-y
Copy link
Member Author

Thanks for all reviews and comments.
/hold cancel

@google-oss-prow google-oss-prow bot merged commit 7c509ba into kubeflow:master Dec 24, 2022
@tenzen-y tenzen-y deleted the support-for-grid-search-in-optuna branch December 24, 2022 06:35
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.

4 participants