rl icon indicating copy to clipboard operation
rl copied to clipboard

[BugFix] Fixes to RenameTransform

Open thomasbbrunner opened this issue 1 year ago • 9 comments

Description

Addresses some of the issues documented in https://github.com/pytorch/rl/issues/2441. These are:

  1. Specs are only modified if the key is in in_keys. Keys specified in in_keys_inv don't lead to a change in the specs.
  2. The behavior of the _inv keys is different to the documented behavior.

This MR does not target the remaining bug (Only the full_action_spec is modified in the transform, but not the action_spec.), as I'm not sure if this is a bug or intended behavior.

Motivation and Context

close https://github.com/pytorch/rl/issues/2441

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

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds core functionality)
  • [x] 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!

  • [x] 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.

thomasbbrunner avatar Sep 19 '24 08:09 thomasbbrunner

:link: Helpful Links

:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/2442

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

:x: 2 New Failures, 12 Unrelated Failures

As of commit 48f160692997295e75b849c9f3327a5b6a1a2907 with merge base e294c68ca8ac1794b19398b07a1cc42cca586ea1 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

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.

pytorch-bot[bot] avatar Sep 19 '24 08:09 pytorch-bot[bot]

Hi @thomasbbrunner!

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!

facebook-github-bot avatar Sep 19 '24 08:09 facebook-github-bot

The tests are currently failing. Before I dive into them, could you take a look at the changes @vmoens and let me know if my assumptions are correct?

thomasbbrunner avatar Sep 19 '24 08:09 thomasbbrunner

Sure having a look now Do you mind signing the CLA? Otherwise I can't merge it

vmoens avatar Sep 19 '24 15:09 vmoens

Thanks!

Do you mind signing the CLA? Otherwise I can't merge it

Currently clarifying this with my employer. Should not be a blocker, but could take a couple of days.

thomasbbrunner avatar Sep 19 '24 15:09 thomasbbrunner

I edited the PR a bit, to comply with the logic of in_keys_inv and out_keys_inv as explained by this figure: image Hope that makes sense. Happy to provide a version of this in the docstrings in that helps understanding what the transform is doing. LMK if in its current form you still see issues with the transform.

vmoens avatar Sep 19 '24 16:09 vmoens

Hope that makes sense.

Yes, it does! And thanks for the diagram. Really useful to understand.

LMK if in its current form you still see issues with the transform.

IMO there's some room for improvement in the docstrings:

    A transform to rename entries in the output tensordict.

    Args:
        in_keys (sequence of NestedKey): the entries to rename
        out_keys (sequence of NestedKey): the name of the entries after renaming.
        in_keys_inv (sequence of NestedKey, optional): the entries to rename before
            passing the input tensordict to :meth:`EnvBase._step`.
        out_keys_inv (sequence of NestedKey, optional): the names of the renamed
            entries passed to :meth:`EnvBase._step`.
        create_copy (bool, optional): if ``True``, the entries will be copied
            with a different name rather than being renamed. This allows for
            renaming immutable entries such as ``"reward"`` and ``"done"``.

Can I suggest something along the lines of (unformatted):

   A transform to rename entries in the output tensordict (or input tensordict via the inverse keys).

    Args:
        in_keys (sequence of NestedKey): the entries to rename.
        out_keys (sequence of NestedKey): the name of the entries after renaming.
        in_keys_inv (sequence of NestedKey, optional): the entries to rename
            in the input tensordict, which will be passed to :meth:`EnvBase._step`.
        out_keys_inv (sequence of NestedKey, optional): the names of the entries in the
            input tensordict after renaming.

This way it is clear:

  • Which name is going to ultimately going to be passed to the _step method.
  • What the original and what the renamed keys are.

Hope that this was helpful!

thomasbbrunner avatar Sep 19 '24 17:09 thomasbbrunner

Yeah sure feel free to add this to the PR

vmoens avatar Sep 19 '24 17:09 vmoens

Done!

thomasbbrunner avatar Sep 19 '24 17:09 thomasbbrunner

Hi @vmoens, we've signed the CLA. I guess this should be ready to merge! (Together maybe with https://github.com/pytorch/rl/pull/2443)

thomasbbrunner avatar Sep 27 '24 07:09 thomasbbrunner