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

[Tune] Nevergrad optimizer with extra parameters #31015

Merged
merged 14 commits into from
Jan 23, 2023

Conversation

yhna940
Copy link
Contributor

@yhna940 yhna940 commented Dec 12, 2022

Why are these changes needed?

Some Nevergrad search algorithms have required inputs, such as budget for the NgOpt search algorithm, but it is not possible with the NevergradSearch class to pass these parameters down to the search algorithm. I would propose adding something like optimizer_kwargs to the NevergradSearch that get passed to the optimizer when instantiating it.

Related issue number

#26305

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@stale
Copy link

stale bot commented Jan 17, 2023

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

  • If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@stale stale bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jan 17, 2023
@yhna940
Copy link
Contributor Author

yhna940 commented Jan 17, 2023

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

  • If you'd like to keep this open, just leave any comment, and the stale label will be removed.

.

@krfricke
Copy link
Contributor

cc @justinvyu can you help shepherd this?

@stale stale bot removed the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jan 17, 2023
Copy link
Contributor

@justinvyu justinvyu left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution! I have a few minor suggestions, and a note about the failing test:

We should fix this test. Currently, it's passing in a parameter_names argument that's not being used at all and is being filled in as the optimizer_kwargs, causing the error. We should just remove this.

class NevergradWarmStartTest(AbstractWarmStartTest, unittest.TestCase):

Also, while we're at it, can we not accept **kwargs in the NevergradSearch constructor? It's currently not used at all and would create some confusion between the added optimizer_kwargs and the regular kwargs.

python/ray/tune/search/nevergrad/nevergrad_search.py Outdated Show resolved Hide resolved
python/ray/tune/search/nevergrad/nevergrad_search.py Outdated Show resolved Hide resolved

out = tune.run(
_invalid_objective,
search_alg=NevergradSearch(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we limit the test to just the searcher initialization? Just making sure that initializing NevergradSearch with an optimizer that requires args without erroring should be good enough.

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 totally agree with you. Therefore, for this test case, only verify that nevergrad is instantiated. thanks.

@yhna940
Copy link
Contributor Author

yhna940 commented Jan 19, 2023

We should fix this test. Currently, it's passing in a parameter_names argument that's not being used at all and is being filled in as the optimizer_kwargs, causing the error. We should just remove this.

class NevergradWarmStartTest(AbstractWarmStartTest, unittest.TestCase):

Fixed by specifying parameter_names. I am so sorry.

@yhna940
Copy link
Contributor Author

yhna940 commented Jan 19, 2023

Also, while we're at it, can we not accept **kwargs in the NevergradSearch constructor? It's currently not used at all and would create some confusion between the added optimizer_kwargs and the regular kwargs.

**kwargs is only used to call __init__ of NevergradSearch's parent class.
The parameters used to build the optimizer used in NevergradSearch need to be defined separately.
As you said, optimizer_kwargs is too confusing, so we have replaced it with optimizer_configs.
Thank you so much for your review.

@yhna940 yhna940 requested review from justinvyu and removed request for krfricke January 19, 2023 00:59
Copy link
Contributor

@justinvyu justinvyu left a comment

Choose a reason for hiding this comment

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

Thanks!

In my comment early, I meant removing this **kwargs entirely and not passing it into the super().__init__(). The base Searcher class doesn't actually take in any args other than metric and mode, so it's not needed. Sorry for the confusion!

Could you also merge with the latest master? (Make sure not to rebase! It will introduce a bunch of commits to this PR.)

python/ray/tune/search/nevergrad/nevergrad_search.py Outdated Show resolved Hide resolved
python/ray/tune/search/nevergrad/nevergrad_search.py Outdated Show resolved Hide resolved
python/ray/tune/search/nevergrad/nevergrad_search.py Outdated Show resolved Hide resolved
python/ray/tune/search/nevergrad/nevergrad_search.py Outdated Show resolved Hide resolved
python/ray/tune/tests/test_searchers.py Outdated Show resolved Hide resolved
@yhna940
Copy link
Contributor Author

yhna940 commented Jan 23, 2023

Thanks!

In my comment early, I meant removing this **kwargs entirely and not passing it into the super().__init__(). The base Searcher class doesn't actually take in any args other than metric and mode, so it's not needed. Sorry for the confusion!

Could you also merge with the latest master? (Make sure not to rebase! It will introduce a bunch of commits to this PR.)

Thank you for your review. There were 3 major changes.

  1. Renamed back to optimizer_kwargs.

  2. Merged with latest branch changes.

  3. Removed kwargs in super __init__ method.

Copy link
Contributor

@justinvyu justinvyu 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 the contribution! I am retrying a few of the failed tests - they shouldn't be affected by these changes. Should be good to merge after they pass!

Copy link
Contributor

@krfricke krfricke left a comment

Choose a reason for hiding this comment

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

Thanks!

@krfricke krfricke merged commit 33d4b14 into ray-project:master Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants