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

[BugFix] Fix Compose input spec transform #2463

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

louisfaury
Copy link
Contributor

@louisfaury louisfaury commented Oct 4, 2024

Description

This PR fixes what I think is a bug in the transform_input_spec method of the Compose transform.

Motivation and Context

The original code goes backward through the list of transforms:

def transform_input_spec(self, input_spec: TensorSpec) -> TensorSpec:
    for t in self.transforms[::-1]:
        input_spec = t.transform_input_spec(input_spec)
    return input_spec

while I believe this should go forward to propagate the input spec of the underlying env.

def transform_input_spec(self, input_spec: TensorSpec) -> TensorSpec:
    for t in self.transforms:
        input_spec = t.transform_input_spec(input_spec)
    return input_spec

I noticed this issue after trying to compose two inverse transformations: DiscretiseAction and RenameTransform -- which broke with a "key" error. I also tried to chain some RenameTransforms that rename the action key. I added this last examples to the tests.

Rq. I have seen that chaining >2 RenameTransform still yields some error, but this seems to be on the RenameTransform side, not Compose. I'll open an issue for this.

  • 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 Oct 4, 2024

🔗 Helpful Links

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

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

❌ 16 New Failures, 6 Unrelated Failures

As of commit 12dd746 with merge base 97ccbb7 (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 Oct 4, 2024
@vmoens vmoens added the bug Something isn't working label Oct 4, 2024
@vmoens
Copy link
Contributor

vmoens commented Oct 4, 2024

The issue is broken because of a bug in tensordict lib - let me fix this and re-run the tests

@louisfaury
Copy link
Contributor Author

I see I forgot to run the linter on the test 🙈 I'll do that asap.

@vmoens
Copy link
Contributor

vmoens commented Oct 4, 2024

just did

@vmoens vmoens merged commit b116151 into pytorch:main Oct 4, 2024
43 of 61 checks passed

# Final check to ensure clean sampling from the action_spec
action = env.rand_action()
assert "action_2"
Copy link
Contributor

Choose a reason for hiding this comment

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

This assert is always true because the string is not empty. Instead, do you want to check if this key is present in the tensordict?

        assert "action_2" in action

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants