Skip to content

[Feature] Add selected_out_keys to ProbabilisticTensorDictSequential.#1497

Merged
vmoens merged 4 commits intopytorch:mainfrom
tobiabir:feature/probabilistic_sequential_selected_out_keys
Jan 9, 2026
Merged

[Feature] Add selected_out_keys to ProbabilisticTensorDictSequential.#1497
vmoens merged 4 commits intopytorch:mainfrom
tobiabir:feature/probabilistic_sequential_selected_out_keys

Conversation

@tobiabir
Copy link
Copy Markdown
Contributor

Description

Describe your changes in detail.

  • Added the selected_out_keys argument to the __init__ of ProbabilisticTensorDictSequential and pass it through to the parent TensorDictSequential.
  • Added two tests testing that argument and intended functionality.

Motivation and Context

Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax close #15213 if this solves the issue #15213

close #1496

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

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Dec 24, 2025

Hi @tobiabir!

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 cla@meta.com. Thanks!

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented Dec 24, 2025

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

@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 Dec 24, 2025
Copy link
Copy Markdown
Collaborator

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

Hey @tobiabir!

Thanks for this and sorry for the delay to review!

I hope you don't mind: I added a couple of small fixes to handle some edge cases:

  • Passing selected_out_keys through the recursive call (line ~1003) — When a dict is passed to the constructor, the code recursively calls self.__init__() but wasn't forwarding selected_out_keys. Now it does!
  • Fixed the "no probabilistic modules" fallback (line ~1034-1047) — The original code used return TensorDictSequential(...) which doesn't work in Python 3.12+ (__init__ must return None). I rewrote this to properly initialize self via TensorDictSequential.__init__() and set the required attributes (_requires_sample, _det_part, return_composite). Also added selected_out_keys here.
  • Set return_composite=True for the no-prob-modules case so that forward() just iterates through modules normally without trying to find a distribution to sample from.

All your original tests pass, and I verified the edge cases work too. LGTM otherwise — nice clean implementation! 🎉

@vmoens vmoens force-pushed the feature/probabilistic_sequential_selected_out_keys branch from 929b437 to fdf28f6 Compare January 8, 2026 17:29
@vmoens vmoens force-pushed the feature/probabilistic_sequential_selected_out_keys branch from 87f6030 to ee1f422 Compare January 8, 2026 17:41
@vmoens vmoens merged commit 26b87bf into pytorch:main Jan 9, 2026
72 of 84 checks passed
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.

[Feature Request] Add selected_out_keys to ProbabilisticTensorDictSequential.

2 participants