[Feature] Dispatch RandomSampler/SliceSampler to without-replacement variants via replacement=False#3749
Open
vmoens wants to merge 1 commit into
Open
[Feature] Dispatch RandomSampler/SliceSampler to without-replacement variants via replacement=False#3749vmoens wants to merge 1 commit into
vmoens wants to merge 1 commit into
Conversation
…variant via replacement=False A metaclass on Sampler intercepts the ``replacement`` keyword: when False, ``RandomSampler(...)`` is dispatched to ``SamplerWithoutReplacement(...)`` and ``SliceSampler(...)`` to ``SliceSamplerWithoutReplacement(...)``. Additional kwargs (``drop_last``, ``shuffle``) are forwarded to the variant constructor. Subclasses without a registered variant raise ``TypeError`` when invoked with ``replacement=False``. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3749
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 2 New Failures, 1 PendingAs of commit 5c12071 with merge base cc31dc3 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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
Adds a
replacementkeyword to the with-replacement sampler classes so users can opt into the without-replacement variant from the simpler constructor:Implementation:
Samplergains anABCMeta-derived metaclass_SamplerMetawhose__call__popsreplacementfrom kwargs and dispatches via a small registry_REPLACEMENT_DISPATCH({RandomSampler: SamplerWithoutReplacement, SliceSampler: SliceSamplerWithoutReplacement}). Whenreplacement=True(default) the metaclass is a transparent no-op. Samplers that have no without-replacement variant (e.g.PrioritizedSampler) raiseTypeErroronreplacement=False.The existing
SamplerWithoutReplacement/SliceSamplerWithoutReplacement/PrioritizedSliceSamplerclasses are untouched and remain the canonical entry points; the new keyword is purely additive.Test plan
test/test_rb.py::TestSamplers::test_replacement_kwarg_*(6 new tests covering type identity, default forwarding, kwarg forwarding,isinstanceinvariants, subclass non-interference, error on unsupported variants, and end-to-end use in aReplayBufferfor bothRandomSamplerandSliceSamplerdispatch).test/test_rb.pysuite passes (3929 passed, no regressions).🤖 Generated with Claude Code