[Feature] Sequence sample unit with exact boundary policies - #4050
Open
coder-jayp wants to merge 3 commits into
Open
[Feature] Sequence sample unit with exact boundary policies#4050coder-jayp wants to merge 3 commits into
coder-jayp wants to merge 3 commits 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.
Executable contract for piece 2 of the pytorch#4039 split: Sequence(length, episode_boundary, done_key) expands each anchor into the length records that follow it in stored-time order, wrapping ring indices across the storage seam. Boundary policies: pad keeps the anchor and marks the tail past an episode end invalid with indices clamped inside the episode; stop shifts the anchor backward to end exactly at the boundary, falling back to pad for episodes shorter than length; include_reset crosses the boundary with all entries valid. The unit adds per-record sequence_id, step_in_sequence and validity_mask info entries that surface as TensorDict sample keys, expands per-anchor sampler entries such as prioritized weights to the record count, and sample(batch_size=B) returns B*length records. Constructor validates length and the boundary policy. Tests are expected to fail until the implementation lands.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4050
Note: Links to docs will display an error until the docs builds have been completed. ❌ 39 New Failures, 19 Unrelated Failures, 1 Unclassified FailureAs of commit 78b3225 with merge base ae421b9 ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
BROKEN TRUNK - The following jobs failed but were 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. |
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
Implements the
Sequencesampling unit to expand sampled anchors into fixed-length sequences.Key Features:
utils.find_start_stop_trajto accurately map anchors to their trajectory endpoints, cleanly handling ring buffer seams andstorage._last_cursortruncations.include_reset: Blindly sweeps forward crossing boundaries.pad: Clamps the sequence at the episode termination and masks trailing steps as invalid.stop: Shifts the anchor backward so the sequence ends exactly on the boundary (falls back topadif the episode is shorter than the sequence length).sequence_id,step_in_sequence, andvalidity_maskfor every frame in theB * lengthoutput.Motivation and Context
This change separates the trajectory-range mechanics (sequence generation) from the anchor probability distributions (like Prioritized or Random Sampling), solving the problem where individual samplers previously had to handle both. It enables combinations such as prioritized sequence starts and consistent padding/boundary policies.
Addresses piece 2 of #4039
Types of changes
Checklist