[bugfix]: honor collector masks in loss reductions - #4057
Open
gtnv wants to merge 5 commits into
Open
Conversation
PR pytorch#3888 routed objectives through _reduce_loss, but the helper still ignored ("collector", "mask") because the corresponding change in pytorch#3850 never merged. This fix excludes padded timesteps from loss reduction so they do not affect the loss or gradients.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4057
Note: Links to docs will display an error until the docs builds have been completed.
|
gtnv
marked this pull request as ready for review
August 2, 2026 01:23
theap06
suggested changes
Aug 2, 2026
Unify unreduced mask behavior. Apply collector masks to REDQ under reduction="none". Remove unreachable mask-shape handling.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#3888 refactored objectives to route through _reduce_loss but the collector mask change from #3850 never merged, leaving a gap. The relevant code changed as well. This made it so padded timesteps from collector, mask were still included and could change the final loss and grads.
BC & RND use it directly. A2C, ppo and reinforce pass input via TensorDict and REDQ/OnlineDT deal with shape-specific cases their own way.
closes #3866.
Ran tests; 9314 passed.
cc @vmoens