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

[FEATURE] TensorDictModule in_keys allowed as Dict[str, tuple | list] to enable multi use of a sample feature #1101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bachdj-px
Copy link

Description

See feature request #1099

Motivation and Context

Close issue #1099

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

Types of changes

  • New feature (non-breaking change which adds core functionality)
  • Documentation (update in the documentation)
  • Example inside the code documentation

Checklist

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

@facebook-github-bot
Copy link

Hi @bachdj-px!

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 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 Nov 22, 2024
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.

Hello, thanks for this PR!

IIUC your change is to allow one element of the input tensordict to be used multiple times within the module inputs.

That would be a good addition.

I think the tests would need to be a bit more extensive. We also need to check this works with other TD modules, like ProbabilisticTensorDictModule.

tensordict/nn/common.py Outdated Show resolved Hide resolved
test/test_nn.py Outdated
Comment on lines 164 to 170
def test_tuple_input_keys(self):
in_keys = {"1": "first", "2": ("second", "third")}
fn = lambda x, y, z: x + y + z
module = TensorDictModule(fn, in_keys=in_keys, out_keys=["out"])

kword_in_keys = sorted(zip(module._kwargs, module.in_keys))
assert kword_in_keys == [("first", "1"), ("second", "2"), ("third", "2")]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really get this example:
the modue is not run, what would the input tensordict look like?
Could the example be a bit more extensive?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, it's a good point - I updated that test. I also added another test that tests the integration of TensorDictModule within a ProbabilisticTensorDictSequential.

Copy link
Author

Choose a reason for hiding this comment

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

@vmoens Thanks for your feedback.
Could you clarify how you would see the change with ProbabilisticTensorDictModule? It seems to me that this feature will only impact TensorDictModule. ProbabilisticTensorDictModule inherits from TensorDictModuleBase and is not affected. Also I don't see the use of implementing my suggested feature in ProbabilisticTensorDictModule - its input have to be unique as far I see it.
Please let me know your thoughts

tensordict/nn/common.py Outdated Show resolved Hide resolved
@bachdj-px bachdj-px force-pushed the support_tuple_in_keys_dispatch branch from 0af7100 to 198404e Compare November 25, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants