[Feature] Forward generator kwarg through ProbabilisticActor#3704
Merged
Conversation
Surfaces the new ``generator`` kwarg added in pytorch/tensordict#1689 through ``SafeProbabilisticModule`` so ``ProbabilisticActor(..., generator=...)`` works as advertised. Without this, the kwarg flows from ``ProbabilisticActor`` into ``SafeProbabilisticModule`` via ``**kwargs`` but is rejected because ``SafeProbabilisticModule.__init__`` enumerates its kwargs explicitly. The generator may be a ``torch.Generator`` (used in place), an ``int`` (shorthand for ``Generator().manual_seed(int)``), or a ``NestedKey`` to fetch the generator from the input tensordict on every call. See the tensordict PR for the full sampling implementation; this PR is a thin forward + docstring entries on ``SafeProbabilisticModule`` and ``ProbabilisticActor``. Motivated by pytorch#3701 (separating agent and environment RNG streams in a meta-environment).
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3704
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit 36c2e71 with merge base 9a8dbae ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced May 6, 2026
vmoens
added a commit
that referenced
this pull request
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to pytorch/tensordict#1689, which added a
generatorkwarg toProbabilisticTensorDictModule. That PR shipped the actual sampling implementation; this PR is the thin pass-through layer needed in TorchRL so thatProbabilisticActor(..., generator=...)actually works.Without this change, the kwarg flows from
ProbabilisticActorintoSafeProbabilisticModulevia**kwargsand is rejected, becauseSafeProbabilisticModule.__init__enumerates its kwargs explicitly and forwards them by name toProbabilisticTensorDictModule.Closes the action item from the discussion in pytorch/rl#3701 — separating an agent's RNG stream from its environment's, motivated by Patterson et al., Empirical Design in Reinforcement Learning (arXiv:2304.01315).
Change
SafeProbabilisticModule.__init__(torchrl/modules/tensordict_module/probabilistic.py): adds thegeneratorkwarg and forwards it tosuper().__init__. Adds a docstring entry.ProbabilisticActor(torchrl/modules/tensordict_module/actors.py): adds a docstring entry.**kwargsalready forwardsgenerator, so no signature change is needed.TestProbabilisticActorGeneratorintest/test_actors.pywith 7 tests covering Generator object, int seed, isolation fromtorch.manual_seed, in-place advancement, tensordict-key form (Generator and int / JAX-PRNG variants), and the default (generator=None) path.Test plan
pytest test/test_actors.py::TestProbabilisticActorGenerator -q— 7 passedpytest test/test_actors.py -k 'probabilistic or Probabilistic or Prob' -q— 15 passed (the 7 new + 8 existing)