Skip to content
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

[Bug] Fixes bug in GAE advantage estimation when gammalmbda is a Tensor #2773

Closed
wants to merge 2 commits into from

Conversation

louisfaury
Copy link
Contributor

Description

Describe your changes in detail.

Motivation and Context

The vectorial implementation of GAE was using done to compute the exponential averaging weights instead of terminated.

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

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of examples)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

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

Copy link

pytorch-bot bot commented Feb 7, 2025

🔗 Helpful Links

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

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

❌ 13 New Failures, 2 Unrelated Failures

As of commit 5411dd9 with merge base 75f113f (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@facebook-github-bot facebook-github-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 Feb 7, 2025
@vmoens vmoens added bug Something isn't working Suitable for minor Suitable to be integrated in minor release (no new feature) labels Feb 7, 2025
Copy link
Contributor

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

LGTM thanks

@@ -332,6 +332,8 @@ def vec_generalized_advantage_estimate(
lmbda=lmbda,
)

not_terminated = (~terminated).to(dtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't comment outside of the diff but ~15 lines below not_terminated is redefined. Maybe worth removing it as part of this PR.

Copy link
Contributor Author

@louisfaury louisfaury Feb 7, 2025

Choose a reason for hiding this comment

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

Good catch, its actually the reason why I re-arranged some stuff (and forgot to remove the second occurrence).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used the occasion for some typos, sorry for the noise.

if isinstance(value, torch.Tensor) and value.numel() > 1:
# create tensor while ensuring that gradients are passed
not_done = (~done).to(dtype)
gammalmbdas = not_done * value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exponential averaging weights were computed with done which I believe is a mistake -- we want to use terminated here.

@@ -332,6 +332,8 @@ def vec_generalized_advantage_estimate(
lmbda=lmbda,
)

not_terminated = (~terminated).to(dtype)
Copy link
Contributor Author

@louisfaury louisfaury Feb 7, 2025

Choose a reason for hiding this comment

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

Good catch, its actually the reason why I re-arranged some stuff (and forgot to remove the second occurrence).

@vmoens
Copy link
Contributor

vmoens commented Feb 7, 2025

We have a few errors in test_cost.py :)

@louisfaury
Copy link
Contributor Author

Looking more closely at broken test, I'm actually now understanding how the previous approach was sound. Classic Chesterton's fence I guess 🙃

@louisfaury louisfaury closed this Feb 9, 2025
@vmoens
Copy link
Contributor

vmoens commented Feb 10, 2025

Gotcha, though it saddens me that people lose time making sense of things like that... That's bad UX/devex

Anything we can do to avoid the confusion? Eg, more comments in the code etc?

@louisfaury
Copy link
Contributor Author

louisfaury commented Feb 10, 2025

I guess here a comment would have gone a long way -- basically simply reminding that a single sequence can hold distinct trajectories, hence we need to make sure to cut the "eligibility traces" not only on terminated but also on truncated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Suitable for minor Suitable to be integrated in minor release (no new feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants