[Feature] Add SampleUnit composition point for replay sampling - #4045
Open
theap06 wants to merge 1 commit into
Open
[Feature] Add SampleUnit composition point for replay sampling#4045theap06 wants to merge 1 commit into
theap06 wants to merge 1 commit into
Conversation
Introduces the interface layer of the sampler-decomposition RFC: sampling combines an anchor distribution (the sampler) with a range expansion (the sample unit), and this PR adds the composition point without changing any behavior. A SampleUnit receives the anchor index, the sampler info dict and the storage inside the buffer's sampling critical section, after the anchor sampler ran and before the storage read or index bookkeeping, and returns the expanded index plus (possibly augmented) info. Unit metadata added to info flows into sample(return_info=True) and becomes keys of TensorDict samples through the existing info-copy path. Transition is the identity unit and the implicit default: sample_unit=None and sample_unit=Transition() are behaviorally identical, which the tests pin under seeded generators. The sample_unit keyword is exposed on ReplayBuffer and threaded through the prioritized variants; Hydra config companions gain the matching field. This settles the RFC's first open question (units are buffer-owned) and gives the Sequence unit, boundary policies and priority-semantics follow-ups a stable target. Part of pytorch#4039.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4045
Note: Links to docs will display an error until the docs builds have been completed.
|
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.
Description
PR 1 of the split proposed in #4039: the interface layer of the sampler decomposition. Replay sampling combines two orthogonal decisions — which anchors the sampler's distribution selects, and what each anchor expands into. This PR adds the composition point for the second decision without changing any behavior.
SampleUnitabstract base:expand(index, info, storage)runs inside the buffer's sampling critical section, after the anchor sampler and before the storage read or any index bookkeeping, and returns the expanded index plus (possibly augmented) info. Units own the alignment of per-anchor info entries they change; metadata they add flows intosample(return_info=True)and becomes keys of TensorDict samples through the existing info-copy path.Transition: the identity unit and implicit default.sample_unit=Noneandsample_unit=Transition()are behaviorally identical — pinned by tests under seeded generators, so this PR is a pure no-op for existing users.sample_unit=keyword onReplayBuffer, threaded throughPrioritizedReplayBufferandTensorDictPrioritizedReplayBuffer; Hydra config companions gain the matching field.This settles the RFC's first open question (units are buffer-owned, matching the illustrative API in the issue) and gives the follow-ups from the #4039 split — the
Sequenceunit with boundary policies, burn-in/bootstrap, priority semantics — a stable target to build against.Testing
TestSampleUnitintest/rb/test_rb_core.py: seeded-generator equivalence of default vsTransition()(data, info keys, indices), no metadata leakage from the identity unit, a toy expanding unit proving the composition end-to-end (expanded batch,info["index"]reflects expansion, metadata surfaces as TensorDict sample keys), constructor type validation, and the prioritized-buffer path includingupdate_tensordict_priorityafter sampling through a unit. Fulltest/rb/suite passes (4189 tests).Part of #4039.