-
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] Fix train_batch_size_per_learner
problems.
#49715
Merged
sven1977
merged 2 commits into
ray-project:master
from
sven1977:fix_train_batch_size_per_learner_setting
Jan 9, 2025
Merged
Changes from all commits
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,7 @@ def __init__(self, algo_class: Optional[type] = None): | |
self.grad_clip = None | ||
self.grad_clip_by = "global_norm" | ||
# Simple logic for now: If None, use `train_batch_size`. | ||
self.train_batch_size_per_learner = None | ||
self._train_batch_size_per_learner = None | ||
self.train_batch_size = 32 # @OldAPIStack | ||
|
||
# These setting have been adopted from the original PPO batch settings: | ||
|
@@ -2324,7 +2324,7 @@ def training( | |
) | ||
self.grad_clip_by = grad_clip_by | ||
if train_batch_size_per_learner is not NotProvided: | ||
self.train_batch_size_per_learner = train_batch_size_per_learner | ||
self._train_batch_size_per_learner = train_batch_size_per_learner | ||
if train_batch_size is not NotProvided: | ||
self.train_batch_size = train_batch_size | ||
if num_epochs is not NotProvided: | ||
|
@@ -3763,14 +3763,26 @@ def rl_module_spec(self): | |
return default_rl_module_spec | ||
|
||
@property | ||
def total_train_batch_size(self): | ||
if ( | ||
self.train_batch_size_per_learner is not None | ||
and self.enable_rl_module_and_learner | ||
): | ||
return self.train_batch_size_per_learner * (self.num_learners or 1) | ||
else: | ||
return self.train_batch_size | ||
def train_batch_size_per_learner(self) -> int: | ||
# If not set explicitly, try to infer the value. | ||
if self._train_batch_size_per_learner is None: | ||
return self.train_batch_size // (self.num_learners or 1) | ||
return self._train_batch_size_per_learner | ||
|
||
@train_batch_size_per_learner.setter | ||
def train_batch_size_per_learner(self, value: int) -> None: | ||
self._train_batch_size_per_learner = value | ||
|
||
@property | ||
def total_train_batch_size(self) -> int: | ||
"""Returns the effective total train batch size. | ||
|
||
New API stack: `train_batch_size_per_learner` * [effective num Learners]. | ||
|
||
@OldAPIStack: User never touches `train_batch_size_per_learner` or | ||
`num_learners`) -> `train_batch_size`. | ||
""" | ||
return self.train_batch_size_per_learner * (self.num_learners or 1) | ||
|
||
# TODO: Make rollout_fragment_length as read-only property and replace the current | ||
# self.rollout_fragment_length a private variable. | ||
|
@@ -3905,18 +3917,11 @@ def validate_train_batch_size_vs_rollout_fragment_length(self) -> None: | |
asking the user to set rollout_fragment_length to `auto` or to a matching | ||
value. | ||
|
||
Also, only checks this if `train_batch_size` > 0 (DDPPO sets this | ||
to -1 to auto-calculate the actual batch size later). | ||
|
||
Raises: | ||
ValueError: If there is a mismatch between user provided | ||
`rollout_fragment_length` and `total_train_batch_size`. | ||
""" | ||
if ( | ||
self.rollout_fragment_length != "auto" | ||
and not self.in_evaluation | ||
and self.total_train_batch_size > 0 | ||
): | ||
if self.rollout_fragment_length != "auto" and not self.in_evaluation: | ||
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. Again, is |
||
min_batch_size = ( | ||
max(self.num_env_runners, 1) | ||
* self.num_envs_per_env_runner | ||
|
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
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.
Why do we return here not the private attribute
self.train_batch_size
?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.
B/c
self.train_batch_size
is old API stack. So we should no longer reference it anywhere in the new API stack logic.