rl icon indicating copy to clipboard operation
rl copied to clipboard

[Feature] Add SampleUnit composition point for replay sampling

Open theap06 opened this issue 4 months ago • 1 comments

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.

  • SampleUnit abstract 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 into sample(return_info=True) and becomes keys of TensorDict samples through the existing info-copy path.
  • Transition: the identity unit and implicit default. sample_unit=None and sample_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 on ReplayBuffer, threaded through PrioritizedReplayBuffer and TensorDictPrioritizedReplayBuffer; 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.

theap06 avatar Jul 24 '26 09:07 theap06

:link: Helpful Links

:test_tube: 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.

:hourglass_flowing_sand: 26 Pending, 2 Unrelated Failures

As of commit 1d73bb99e85590421918c41f987b9cc2f491124e with merge base 7330afbe01946b9980544ca765eedc6fd1d4f756 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

pytorch-bot[bot] avatar Jul 24 '26 09:07 pytorch-bot[bot]