-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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] Implement BOHB #5382
[tune] Implement BOHB #5382
Conversation
|
||
import ray | ||
from ray.tune import Trainable, run, sample_from | ||
from ray.tune.schedulers import TuneBOHB, HyperBandForBOHB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TuneBOHB should go to ray.tune.suggest
config_space, | ||
max_concurrent=4, | ||
# num_concurrent=100, | ||
reward_attr="episode_reward_mean", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reward_attr => metric
python/ray/tune/schedulers/bohb.py
Outdated
@@ -0,0 +1,62 @@ | |||
import ray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this file to tune/suggest
?
and add the three __future__
imports to the top?
python/ray/tune/schedulers/bohb.py
Outdated
self.paused = set() | ||
self.reward_attr = reward_attr | ||
bohb_config = bohb_config or {} | ||
self.bohber = BOHB(space, **bohb_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, we need to import BOHB from HpBandSter
Test PASSed. |
How much more needs to be done before this can be merged? Seems almost complete and it's a major feature to be missing. I'm willing to help if needed. @lisadunlap |
doc/source/tune-searchalg.rst
Outdated
|
||
.. code-block:: python | ||
|
||
tune.run(... , search_alg=TuneBOHB(config_space, ... )) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you also need HyperBand right?
python/ray/tune/suggest/bohb.py
Outdated
from ray.tune.suggest import SuggestionAlgorithm | ||
|
||
|
||
class BOHB(base_config_generator): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry, I meant “importing BOHB from hpbandster” is ideal
doc/source/tune-searchalg.rst
Outdated
@@ -181,6 +182,30 @@ An example of this can be found in `ax_example.py <https://github.com/ray-projec | |||
:show-inheritance: | |||
:noindex: | |||
|
|||
BOHB (Bayesian optimization and Hyperband) | |||
--------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should align with the above string
python/ray/tune/suggest/bohb.py
Outdated
from __future__ import division | ||
from __future__ import print_function | ||
|
||
from hpbandster import BOHB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do a soft import here? like in suggest/ax.py
; and correspondingly raise an error in init if not found?
python/ray/tune/suggest/bohb.py
Outdated
self.running.add(trial_id) | ||
if "budget" in result.get("hyperband_info", {}): | ||
hbs_wrapper = self.to_wrapper(trial_id, result) | ||
print("adding new result", vars(hbs_wrapper)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove this?
python/ray/tune/suggest/bohb.py
Outdated
elif trial_id in self.running: | ||
self.running.remove(trial_id) | ||
else: | ||
import ipdb; ipdb.set_trace() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove this?
class HyperBandForBOHB(HyperBandScheduler): | ||
"""Implements the HyperBand early stopping algorithm. | ||
|
||
@!!!!!!!!!!!!!! Key changes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@!!!!!!!!!!!!!! Key changes: | |
Key changes: |
|
||
|
||
class HyperBandForBOHB(HyperBandScheduler): | ||
"""Implements the HyperBand early stopping algorithm. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Implements the HyperBand early stopping algorithm. | |
"""Extends HyperBand early stopping algorithm for BOHB. |
print(Counter([status for _, status in statuses])) | ||
trial_runner._search_alg.on_pause(trial.trial_id) | ||
return TrialScheduler.PAUSE | ||
# import ipdb; ipdb.set_trace() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
if not bracket.filled() or any( | ||
status != Trial.PAUSED for t, status in statuses | ||
if t is not trial): | ||
print(Counter([status for _, status in statuses])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove?
bracket.cleanup_full(trial_runner) | ||
return TrialScheduler.STOP | ||
|
||
good, bad = bracket.successive_halving(self._reward_attr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no more _reward_attr
, so this should be _metric
. HyperBand
also takes in a mode
from its superclass, so I think we just need to do the negation here or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Two last things (in addition to above comments):
Can you add bohb_example
as a line in ray/ci/jenkins_tests/run_tune_tests.sh
with --smoke-test
?
Can you run scripts/format.sh
? You'll need flake8 and yapf==0.23.0 and flake8-quotes. This will run formatting.
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test FAILed. |
Test PASSed. |
Test PASSed. |
@20zinnm thanks for offering! This is now merged. Could you try it out and let us know how it goes? |
What do these changes do?
Added TuneBOHB (search), HyperBandForBOHB (early stopping), and an example.
Related issue number
Closes #5100
Linter
scripts/format.sh
to lint the changes in this PR.