[Feature] Add SampleUnit composition point for replay sampling
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 Sequence unit with boundary policies, burn-in/bootstrap, priority semantics — a stable target to build against.
Testing
TestSampleUnit in test/rb/test_rb_core.py: seeded-generator equivalence of default vs Transition() (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 including update_tensordict_priority after sampling through a unit. Full test/rb/ suite passes (4189 tests).
Part of #4039.
:link: Helpful Links
:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4045
- :page_facing_up: Preview Python docs built from this PR
Note: Links to docs will display an error until the docs builds have been completed.
:hourglass_flowing_sand: 26 Pending, 2 Unrelated Failures
As of commit 1d73bb99e85590421918c41f987b9cc2f491124e with merge base 7330afbe01946b9980544ca765eedc6fd1d4f756 ():
FLAKY - The following job failed but was likely due to flakiness present on trunk:
- Unit-tests on Linux / tests-cpu (3.13, bulk) / linux-job (gh) (similar failure)
test/test_configs.py::TestLoggerConfigs::test_trackio_logger_config_instantiation
BROKEN TRUNK - The following job failed but was present on the merge base:
👉 Rebase onto the `viable/strict` branch to avoid these failures
- Unit-tests on Linux / tests-cpu (3.14, bulk) / linux-job (gh) (trunk failure)
test/test_configs.py::TestLoggerConfigs::test_trackio_logger_config_instantiation
This comment was automatically generated by Dr. CI and updates every 15 minutes.