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 add points_to_evaluate #12207

Merged
merged 8 commits into from
Nov 23, 2020
Merged

[tune] nevergrad add points_to_evaluate #12207

merged 8 commits into from
Nov 23, 2020

Conversation

viotemp1
Copy link
Contributor

@viotemp1 viotemp1 commented Nov 20, 2020

Why are these changes needed?

Add points_to_evaluate to NevergradSearch

Related issue number

Checks

  • 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 :(

@krfricke
Copy link
Contributor

Great, that worked, thanks! I'll look into it shortly

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 for this contribution!

Besides the minor comments it would be good if you could add a test (e.g. in test_sample.py). This test should instantiate a nevergrad searcher with a list of e.g. 3 points to evaluate and confirm that the first three sampled configurations are indeed these points.

Let me know if you need any help with that.

Comment on lines 72 to 77

current_best_params = [{
'width': 10,
'height': 0,
'activation': 0, # The index of "relu"
}]
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use our usual quotes here (" instead of ')

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

point_to_evaluate = self._points_to_evaluate.pop(0)
for key in self._space.value:
if isinstance(self._space[key], ng.p.Choice):
point_to_evaluate[key] = self._space[key].choices.value[point_to_evaluate[key]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Couldn't we pass e.g. activation: "relu" in the points_to_evaluate dict directly and omit this lookup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's for sure. I did like this in the beginning, but I change it to be compatible with points_to_evaluate from HyperOptSearch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do it with strings then (e.g. activation: "relu") and we'll change the hyperoptsearch implementation in a different PR.

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 129 to 134
if points_to_evaluate is None:
self._points_to_evaluate = None
else:
assert isinstance(points_to_evaluate, (list, tuple))
self._points_to_evaluate = points_to_evaluate

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's raise an actionable error message here.I'd suggest something like:

if not isinstance(points_to_evaluate, Sequence):
    raise ValueError(
        f"Invalid object type passed for `points_to_evaluate`: {type(points_to_evaluate)}. "
        f"Please pass a list of points (dictionaries) instead.")
self._points_to_evaluate = list(points_to_evaluate)

(This would have to be linted)

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

@viotemp1
Copy link
Contributor Author

Should I add one more test in test_sample.py - something like testConvertNevergrad_best_params?

@krfricke
Copy link
Contributor

Yep, let's call it testNevergradBestParams to follow the naming conventions. That's great, thanks!

@viotemp1
Copy link
Contributor Author

added new test in test_sample.py

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.

Almost done - just one final one line change

f"Invalid object type passed for `points_to_evaluate`: {type(points_to_evaluate)}. "
f"Please pass a list of points (dictionaries) instead.")
else:
self._points_to_evaluate = points_to_evaluate
Copy link
Contributor

Choose a reason for hiding this comment

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

We will either have to convert to a list here (i.e. self._points_to_evaluate = list(points_to_evaluate)) or check for MutableSequence above, as this implements the pop() interface we use in the code below.

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

krfricke
krfricke previously approved these changes Nov 23, 2020
@krfricke
Copy link
Contributor

That's awesome! Thanks! We'll let the tests run and assuming they pass we should be ready to merge.

@krfricke
Copy link
Contributor

There's a few linting errors:

python/ray/tune/suggest/nevergrad.py:133:80: E501 line too long (100 > 79 characters)

python/ray/tune/tests/test_sample.py:592:9: F841 local variable 'best_params0' is assigned to but never used

python/ray/tune/tests/test_sample.py:592:23: F841 local variable 'best_params1' is assigned to but never used

Could you fix them? (And run ./scripts/format.sh afterwards to confirm).

The other failing tests seem unrelated to this PR.

@krfricke krfricke dismissed their stale review November 23, 2020 14:50

(wait for tests)

@krfricke
Copy link
Contributor

Perfect! Thanks @viotemp1, that's a very useful contribution!

This should be ready to merge cc @richardliaw

@richardliaw richardliaw merged commit 4c4f189 into ray-project:master Nov 23, 2020
@richardliaw
Copy link
Contributor

thanks!

@viotemp1
Copy link
Contributor Author

Should I delete this branch? Sorry for the question ...
Also this suggestion should be implemented: "Let's do it with strings then (e.g. activation: "relu") and we'll change the hyperoptsearch implementation in a different PR"? I have seen that internally hyperoptsearch is using categorical for choices...
Thanks!

@krfricke
Copy link
Contributor

Hi, you can delete the branch as the changes are included in the master now. So next time if you want to contribute something, you'd do the following steps:

  1. (If you haven't already): git remote add upstream https://github.com/ray-project/ray.git
  2. git checkout master (will switch to your local master branch)
  3. git pull upstream master (will pull the most recent version from the official ray repository)
  4. git push origin master (optional, will push the most recent version to your own fork)

You can then git checkout -b branch-name to checkout a new branch, develop, push to your own fork (git push origin branch-name) and file a new PR!

Yep, I'll file an issue to track the HyperOptSearch categorical feature! Thanks again!

@viotemp1
Copy link
Contributor Author

Thank you too!

@viotemp1 viotemp1 deleted the tune-nevergrad branch November 24, 2020 09:08
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.

None yet

3 participants