Skip to content

[BugFix] Keep real terminations on the last retained step of shifted value estimators - #4790

Open
0xrichardlu wants to merge 1 commit into
pytorch:mainfrom
0xrichardlu:fix/shifted-keep-terminated
Open

0xrichardlu wants to merge 1 commit into
pytorch:mainfrom
0xrichardlu:fix/shifted-keep-terminated

Conversation

@0xrichardlu

@0xrichardlu 0xrichardlu commented Nov 27, 2026 •

Copy link
Copy Markdown

Description

With shifted=True, _prepare_shifted_tensordict marks the last retained transition as a synthetic boundary by setting done=True and terminated=False. Clearing terminated also erased a real termination on that step, so TD0Estimator / TD1Estimator / TDLambdaEstimator / GAE bootstrapped gamma * V(terminal state) there instead of 0, and GAE carried the error backwards through the episode. This keeps the original terminated flag; the boundary only needs done=True. The test reference _shifted_reference had the same overwrite and is fixed too. A new parametrized test covers a real termination on the last retained step for all four estimators.

Motivation and Context

close #4789

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTION guide (required)
  • I have updated the tests accordingly (required for a bug fix or a new feature).

…value estimators

_prepare_shifted_tensordict marks the last retained transition as a synthetic batch boundary by setting done=True and terminated=False. Clearing terminated also erased a real termination on that step, so TD0/TD1/TD(lambda)/GAE with shifted=True bootstrapped gamma * V(terminal state) instead of 0. Keep the original terminated flag; the boundary only needs done=True.
@pytorch-bot

pytorch-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4790

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 16 Awaiting Approval

As of commit e0e2846 with merge base 527edeb (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 commented Nov 27, 2026

Copy link
Copy Markdown

Hi @0xrichardlu!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@0xrichardlu

Copy link
Copy Markdown
Author

Thanks! I’ve signed the individual CLA. Please let me know if anything else is needed.

@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 Nov 28, 2026
@meta-cla

meta-cla Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

This branch has not been deployed

No deployments
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.

[BUG] shifted=True value estimators bootstrap through a real termination on the last retained step

1 participant