[Feature] Extend Sequence with burn-in, bootstrap, stride and per-anchor priority semantics
Description
Pieces 3 and 4 (first half) of the split proposed in #4039, built on top of the Sequence unit from #4050.
Burn-in, bootstrap, stride (piece 3): the window around each anchor becomes burn_in records before the anchor, the learning region of length records starting at it, and bootstrap records after it, with stride spacing the whole window uniformly. A per-record learning_mask info entry is True exactly on the learning region (recurrent burn-in states get replayed but masked out of the loss). Burn-in never shifts the anchor: entries before the episode start are invalid and clamp to it. Bootstrap entries obey the episode_boundary policy at episode ends. Defaults reproduce the existing Sequence behavior exactly, pinned by a test comparing the two.
Priority semantics + distribution invariance (piece 4, first half): priorities live per anchor. A per-record anchor_index info entry reports the storage index of each record's sampled anchor — the original anchor, not the stop-shifted one, since that is what the sampler's distribution selected — so priorities of sampled sequences update through the ordinary update_priority path. Per-anchor sampler entries such as importance weights expand block-constant across the window. Seeded statistical tests pin the RFC acceptance criterion that range expansion does not change the anchor selection distribution, for uniform and prioritized sampling, and that a priority update through anchor_index steers subsequent sampling.
The SliceSampler compatibility adapters and the structured [B, T] layout remain the second half of piece 4 and will follow separately.
Testing
Spec-first: TestSequenceBurnInBootstrap (8 tests) and TestSequencePrioritySemantics (5 tests) were written as the contract before the implementation, with deterministic direct-expand calls for every boundary case and wide-band seeded statistical tests for the distribution properties. The piece-2 spec from #4050 stays green (10/10), and one of its tests was hardened against a legitimate sampling flake (anchors near the storage cursor produce valid-prefix sequences; the test now asserts the prefix property instead of full validity). Full test/rb/ suite passes (4212 tests).
Note
Stacked on #4050 (@coder-jayp's Sequence unit): its commits are included here and only the last three commits are new. Will rebase once #4050 lands.
Part of #4039.
:link: Helpful Links
:test_tube: See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4051
- :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.
:white_check_mark: You can merge normally! (4 Unrelated Failures)
As of commit 600c60d652693303abe5ef3718a81eb18901a2e7 with merge base 678520e3a7ce61d9730232fda369f825d16d96cb ():
FLAKY - The following job failed but was likely due to flakiness present on trunk:
- SOTA Tests on Linux / tests (3.10, 13.0, 2) / linux-job (gh) (matched linux rule in flaky-rules.json)
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/noble-updates/main/binary-amd64/Packages.gz Hash Sum mismatch
BROKEN TRUNK - The following jobs 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.10, bulk) / linux-job (gh) (trunk failure)
test/test_configs.py::TestConfigClassParity::test_wrapped_class_kwargs_have_config_fields[LBFGSConfig] - Unit-tests on Linux / tests-cpu (3.13, bulk) / linux-job (gh) (trunk failure)
test/test_configs.py::TestConfigClassParity::test_wrapped_class_kwargs_have_config_fields[LBFGSConfig] - Unit-tests on Linux / tests-cpu (3.14, bulk) / linux-job (gh) (trunk failure)
test/test_configs.py::TestConfigClassParity::test_wrapped_class_kwargs_have_config_fields[LBFGSConfig]
This comment was automatically generated by Dr. CI and updates every 15 minutes.
Thanks for the contribution — I routed priority updates through anchors (max over valid records), kept burn-in inside the ring seam, and documented index/anchor_index semantics in b719832.
Thanks @theap06!
I think that performance and multidimensional-storage support can be handled in follow-up PRs rather than blocking this one, so I'll leave it as TODOs for you (please let me know if you'd rather have someone else do it).
I pushed the missing documentation, including a recurrent Q-learning use case and an explanation of how learning_mask and validity_mask should be consumed. I also renamed stride to dilation: the parameter spaces records inside a window and does not control spacing or overlap between independently sampled windows. The PR title/body should be updated accordingly.
For follow-ups, I suggest:
- Design shared, efficient replay-boundary detection used by Sequence, SliceSampler, and other trajectory-aware components, including caching/invalidation, ring wraparound, device placement, and benchmarks.
- Add ndim > 1 support by expanding the time coordinate while preserving lane coordinates, including multidimensional anchor-priority reduction.
The boundary-detection work should be holistic rather than a local optimization of Sequence (we have that problem in many places in torchrl). Compile can help, it worked nicely with SliceSampler back in the days IIRC.
That's a high difficulty task so I'm happy to take it over.