-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[tune] Avoid scheduler blocking, add reuse_actors optimization #4218
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b7331f2
fpbt
ericl 7369fb6
add runner caching
ericl f64328e
reset config
ericl b2d825b
make it optional
ericl 5b50218
trial doc
ericl c56c9cd
Merge remote-tracking branch 'upstream/master' into faster-pbt
ericl 7665d88
add test
ericl fd115b0
fix
ericl 1ba7336
don't reuse on trial start
ericl 9a9221f
fix tests
ericl 6cb0dc9
forgot to restore weights
ericl 566d8c2
Merge branch 'master' into faster-pbt
ericl 3327e3a
Update error.py
ericl d3146cd
Merge remote-tracking branch 'upstream/master' into faster-pbt
ericl 1ba204a
merge
ericl c1015fa
Merge branch 'faster-pbt' of github.com:ericl/ray into faster-pbt
ericl 1ce6f74
run reuse in jenkins only
ericl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,4 +96,5 @@ def reset_config(self, new_config): | |
| } | ||
| }, | ||
| scheduler=pbt, | ||
| reuse_actors=True, | ||
| verbose=False) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
|
|
||
| import unittest | ||
|
|
||
| import ray | ||
| from ray.tune import Trainable, run_experiments | ||
| from ray.tune.error import TuneError | ||
| from ray.tune.schedulers.trial_scheduler import FIFOScheduler, TrialScheduler | ||
|
|
||
|
|
||
| class FrequentPausesScheduler(FIFOScheduler): | ||
| def on_trial_result(self, trial_runner, trial, result): | ||
| return TrialScheduler.PAUSE | ||
|
|
||
|
|
||
| class MyResettableClass(Trainable): | ||
| def _setup(self, config): | ||
| self.config = config | ||
| self.num_resets = 0 | ||
| self.iter = 0 | ||
|
|
||
| def _train(self): | ||
| self.iter += 1 | ||
| return {"num_resets": self.num_resets, "done": self.iter > 1} | ||
|
|
||
| def _save(self, chkpt_dir): | ||
| return {"iter": self.iter} | ||
|
|
||
| def _restore(self, item): | ||
| self.iter = item["iter"] | ||
|
|
||
| def reset_config(self, new_config): | ||
| if "fake_reset_not_supported" in self.config: | ||
| return False | ||
| self.num_resets += 1 | ||
| return True | ||
|
|
||
|
|
||
| class ActorReuseTest(unittest.TestCase): | ||
| def setUp(self): | ||
| ray.init(num_cpus=1, num_gpus=0) | ||
|
|
||
| def tearDown(self): | ||
| ray.shutdown() | ||
|
|
||
| def testTrialReuseDisabled(self): | ||
| trials = run_experiments( | ||
| { | ||
| "foo": { | ||
| "run": MyResettableClass, | ||
| "num_samples": 4, | ||
| "config": {}, | ||
| } | ||
| }, | ||
| reuse_actors=False, | ||
| scheduler=FrequentPausesScheduler()) | ||
| self.assertEqual([t.last_result["num_resets"] for t in trials], | ||
| [0, 0, 0, 0]) | ||
|
|
||
| def testTrialReuseEnabled(self): | ||
| trials = run_experiments( | ||
| { | ||
| "foo": { | ||
| "run": MyResettableClass, | ||
| "num_samples": 4, | ||
| "config": {}, | ||
| } | ||
| }, | ||
| reuse_actors=True, | ||
| scheduler=FrequentPausesScheduler()) | ||
| self.assertEqual([t.last_result["num_resets"] for t in trials], | ||
| [1, 2, 3, 4]) | ||
|
|
||
| def testTrialReuseEnabledError(self): | ||
| def run(): | ||
| run_experiments( | ||
| { | ||
| "foo": { | ||
| "run": MyResettableClass, | ||
| "max_failures": 1, | ||
| "num_samples": 4, | ||
| "config": { | ||
| "fake_reset_not_supported": True | ||
| }, | ||
| } | ||
| }, | ||
| reuse_actors=True, | ||
| scheduler=FrequentPausesScheduler()) | ||
|
|
||
| self.assertRaises(TuneError, lambda: run()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main(verbosity=2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -310,6 +310,9 @@ def restore(self, checkpoint_path): | |
| self._restore(checkpoint_dict) | ||
| else: | ||
| self._restore(checkpoint_path) | ||
| self._time_since_restore = 0.0 | ||
| self._timesteps_since_restore = 0 | ||
| self._iterations_since_restore = 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch |
||
| self._restored = True | ||
|
|
||
| def restore_from_object(self, obj): | ||
|
|
@@ -350,12 +353,16 @@ def export_model(self, export_formats, export_dir=None): | |
| def reset_config(self, new_config): | ||
| """Resets configuration without restarting the trial. | ||
|
|
||
| This method is optional, but can be implemented to speed up algorithms | ||
| such as PBT, and to allow performance optimizations such as running | ||
| experiments with reuse_actors=True. | ||
|
|
||
| Args: | ||
| new_config (dir): Updated hyperparameter configuration | ||
| for the trainable. | ||
|
|
||
| Returns: | ||
| True if configuration reset successfully else False. | ||
| True if reset was successful else False. | ||
| """ | ||
| return False | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@arcelien is this ok?
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.
Let me try it on a single gpu machine both with time mutliplexing and also with a small population size.