Skip to content

[bugfix]: honor collector masks in loss reductions - #4057

Open
gtnv wants to merge 5 commits into
pytorch:mainfrom
gtnv:fix/loss-mask
Open

[bugfix]: honor collector masks in loss reductions#4057
gtnv wants to merge 5 commits into
pytorch:mainfrom
gtnv:fix/loss-mask

Conversation

@gtnv

@gtnv gtnv commented Aug 2, 2026

Copy link
Copy Markdown

#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

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.
@pytorch-bot

pytorch-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

🔗 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.

⚠️ 15 Awaiting Approval

As of commit abb96df with merge base ae421b9 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 2, 2026
@gtnv
gtnv marked this pull request as ready for review August 2, 2026 01:23

@theap06 theap06 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @vmoens - can you trigger github workflows?

@theap06 theap06 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some feedback cc @vmoens

Comment thread torchrl/objectives/common.py
Comment thread torchrl/objectives/redq.py
Comment thread torchrl/objectives/common.py Outdated
Unify unreduced mask behavior. Apply collector masks to REDQ under reduction="none". Remove unreachable mask-shape handling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BugFix CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Objectives

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] Mask-aware reduction across LossModule subclasses

2 participants