Repository navigation
[BugFix] Draw only long-enough trajectories in SliceSamplerWithoutReplacement with strict_length - #4584
Open
Kayvan-Zahiri wants to merge 1 commit into
Open
[BugFix] Draw only long-enough trajectories in SliceSamplerWithoutReplacement with strict_length#4584Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
…lacement with strict_length
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4584
Note: Links to docs will display an error until the docs builds have been completed.
|
This branch has not been deployed
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
With
strict_length=True,SliceSamplerWithoutReplacementpermutes over every trajectory in the storage, short ones included, and_sample_slicesdrops the short ones only after they've been drawn. Two things go wrong:sample()raisesRuntimeError: None of the provided indices pointed to a trajectory of sufficient lengthin the middle of an epoch.With trajectory lengths
[7, 2, 9, 1, 5, 12, 4, 3],slice_len=3andbatch_size=6, on main:The
strict_lengthdocstring says short trajectories are filtered out, and the with-replacementSliceSampleralready filters before it draws. Now the without-replacement sampler permutes only over trajectories withlength >= seq_lengthand maps the drawn positions back to trajectory indices, so an epoch covers exactly the eligible trajectories. If none is long enough, it falls back to the old draw, so the existing "Did not find a single trajectory with sufficient length" error is unchanged. Withstrict_length=False, nothing changes.Tests
test_slice_sampler_without_replacement_strict_skips_shortis parametrized over flat andbatch_time. It checks that 30 draws are all full batches, that no short trajectory is drawn, and that each epoch covers every eligible trajectory. It fails on main and passes here. The 22 without-replacement tests intest/rb/test_samplers.pypass. Across the whole file, the failure set is the same 118 on main and on this branch: all areSumSegmentTreeFp32 is not available, because the C++ extension isn't built in my environment. ufmt (black 22.3.0, usort 1.0.3) and flake8 with the repo config are clean.I found this with a property check over
SliceSamplerconfigurations. No open issue or PR covers it. It is independent of #4583, which fixes theends=/trajectories=boundaries. AI assistance (Claude Code) was used for the investigation and the patch.