-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[RLlib] Change placement group strategy for learner #36929
Merged
kouroshHakha
merged 4 commits into
ray-project:master
from
avnishn:change_placement_groups_learner
Jun 30, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
|
@@ -131,6 +131,42 @@ | |
from ray.util.timer import _Timer | ||
from ray.tune.registry import get_trainable_cls | ||
|
||
|
||
try: | ||
from ray.rllib.extensions import AlgorithmBase | ||
except ImportError: | ||
|
||
class AlgorithmBase: | ||
|
||
@staticmethod | ||
def _get_learner_bundles(cf: AlgorithmConfig): | ||
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. document what it returns? 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. done |
||
"""Selects the right resource bundles for learner workers based off of cf. | ||
|
||
Args: | ||
cf: The algorithm config. | ||
""" | ||
if cf.num_learner_workers > 0: | ||
if cf.num_gpus_per_learner_worker: | ||
learner_bundles = [ | ||
{"GPU": cf.num_learner_workers * cf.num_gpus_per_learner_worker} | ||
] | ||
elif cf.num_cpus_per_learner_worker: | ||
learner_bundles = [ | ||
{ | ||
"CPU": cf.num_cpus_per_learner_worker * cf.num_learner_workers, | ||
} | ||
] | ||
else: | ||
learner_bundles = { | ||
# sampling and training is not done concurrently when local is | ||
# used, so pick the max. | ||
"CPU": max( | ||
cf.num_cpus_per_learner_worker, cf.num_cpus_for_local_worker | ||
), | ||
"GPU": cf.num_gpus_per_learner_worker, | ||
} | ||
return learner_bundles | ||
|
||
tf1, tf, tfv = try_import_tf() | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -146,7 +182,7 @@ def with_common_config(*args, **kwargs): | |
|
||
|
||
@PublicAPI | ||
class Algorithm(Trainable): | ||
class Algorithm(Trainable, AlgorithmBase): | ||
"""An RLlib algorithm responsible for optimizing one or more Policies. | ||
|
||
Algorithms contain a WorkerSet under `self.workers`. A WorkerSet is | ||
|
@@ -2157,30 +2193,26 @@ def default_resource_request( | |
eval_cf.freeze() | ||
|
||
# resources for the driver of this trainable | ||
if cf._enable_learner_api: | ||
if cf.num_learner_workers == 0: | ||
# in this case local_worker only does sampling and training is done on | ||
# local learner worker | ||
driver = { | ||
# sampling and training is not done concurrently when local is | ||
# used, so pick the max. | ||
"CPU": max( | ||
cf.num_cpus_per_learner_worker, cf.num_cpus_for_local_worker | ||
), | ||
"GPU": cf.num_gpus_per_learner_worker, | ||
} | ||
else: | ||
# in this case local_worker only does sampling and training is done on | ||
# remote learner workers | ||
driver = {"CPU": cf.num_cpus_for_local_worker, "GPU": 0} | ||
else: | ||
# Without Learner API, the local_worker can do both sampling and training. | ||
# So, we need to allocate the same resources for the driver as for the | ||
# local_worker. | ||
driver = { | ||
"CPU": cf.num_cpus_for_local_worker, | ||
"GPU": 0 if cf._fake_gpus else cf.num_gpus, | ||
} | ||
# if cf._enable_learner_api: | ||
# if cf.num_learner_workers == 0: | ||
# # in this case local_worker only does sampling and training is done on | ||
# # local learner worker | ||
# driver = { | ||
# # sampling and training is not done concurrently when local is | ||
# # used, so pick the max. | ||
# "CPU": max( | ||
# cf.num_cpus_per_learner_worker, cf.num_cpus_for_local_worker | ||
# ), | ||
# "GPU": cf.num_gpus_per_learner_worker, | ||
# } | ||
# else: | ||
# # in this case local_worker only does sampling and training is done on | ||
# # remote learner workers | ||
# driver = {"CPU": cf.num_cpus_for_local_worker, "GPU": 0} | ||
driver = { | ||
"CPU": cf.num_cpus_for_local_worker, | ||
"GPU": 0 if cf._fake_gpus else cf.num_gpus, | ||
} | ||
|
||
# resources for remote rollout env samplers | ||
rollout_bundles = [ | ||
|
@@ -2222,23 +2254,8 @@ def default_resource_request( | |
|
||
# resources for remote learner workers | ||
learner_bundles = [] | ||
if cf._enable_learner_api and cf.num_learner_workers > 0: | ||
# can't specify cpus for learner workers at the same | ||
# time as gpus | ||
if cf.num_gpus_per_learner_worker: | ||
learner_bundles = [ | ||
{ | ||
"GPU": cf.num_gpus_per_learner_worker, | ||
} | ||
for _ in range(cf.num_learner_workers) | ||
] | ||
elif cf.num_cpus_per_learner_worker: | ||
learner_bundles = [ | ||
{ | ||
"CPU": cf.num_cpus_per_learner_worker, | ||
} | ||
for _ in range(cf.num_learner_workers) | ||
] | ||
if cf._enable_learner_api: | ||
learner_bundles = cls._get_learner_bundles(cf) | ||
|
||
bundles = [driver] + rollout_bundles + evaluation_bundles + learner_bundles | ||
|
||
|
This file contains 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
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.
@avnishn since you change the number of worker, you also need to change the number here https://github.com/ray-project/ray/blob/master/release/release_tests.yaml#L3679 to wait for the correct number of node
This broke this test, and some other rllib test in this latest run https://buildkite.com/ray-project/release-tests-branch/builds/1846
Please cherry pick the fix as well since the branch is cut
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.
I'm putting #37022 to fix