rl icon indicating copy to clipboard operation
rl copied to clipboard

[Feature] Sequence sample unit with exact boundary policies

Open coder-jayp opened this issue 4 months ago • 1 comments

Description

Implements the Sequence sampling unit to expand sampled anchors into fixed-length sequences.

Key Features:

  • Robust Boundary Recovery: Leverages utils.find_start_stop_traj to accurately map anchors to their trajectory endpoints, cleanly handling ring buffer seams and storage._last_cursor truncations.
  • Strict Boundary Policies:
    • 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 to pad if the episode is shorter than the sequence length).
  • Metadata Flow: Expands existing per-anchor info and injects accurate sequence_id, step_in_sequence, and validity_mask for every frame in the B * length output.

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

  • [x] I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • [x] New feature (non-breaking change which adds core functionality)

Checklist

  • [x] I have read the CONTRIBUTION guide (required)
  • [ ] My change requires a change to the documentation.
  • [x] I have updated the tests accordingly (required for a bug fix or a new feature).
  • [ ] I have updated the documentation accordingly.

coder-jayp avatar Jul 25 '26 13:07 coder-jayp

:link: Helpful Links

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

:warning: 15 Awaiting Approval

As of commit d15fe7c4027f10273f379a85400fe6bbea8f620f with merge base b92de7d1c25439540e2e03ef3e8639b9d27b7c27 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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

pytorch-bot[bot] avatar Jul 25 '26 13:07 pytorch-bot[bot]

Thanks for the contribution — I fixed include_reset for partial/full buffers, non-CPU device handling, storage validation, exports/docs/Hydra configs, and type hints in 6b1b061.

vmoens avatar Aug 05 '26 16:08 vmoens