Repository navigation
fix: isolate dataset shuffle random state - #2395
Open
LZC-BELIEVER wants to merge 1 commit into
Open
LZC-BELIEVER wants to merge 1 commit into
LZC-BELIEVER wants to merge 1 commit into
Conversation
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.
Summary
random.Randominstance for deterministic prompt shuffling.seed + epochpermutation behavior without mutating Python's process-global RNG state.Problem
Dataset.shuffle()currently reseeds Python's module-level random number generator whenever the dataset changes epoch:RolloutDataSourceinvokes this method during initialization and at epoch boundaries. As a result, shuffling the prompt dataset also resets the random stream observed by unrelated code in the same long-lived rollout process, including custom generation or reward functions that use Python'srandommodule.This creates hidden coupling between dataset ordering and otherwise independent random operations. Adding or moving a shuffle call can therefore change behavior outside the dataset.
Fix
Create a dedicated RNG for each deterministic shuffle:
The local RNG uses the same seed and standard-library shuffle implementation as before, so the dataset permutation remains deterministic for each epoch. Its state is confined to
Dataset.shuffle(), leaving the process-global RNG unchanged.No command-line arguments, dataset APIs, sampling parameters, or GPU code paths are changed.
Testing
The new CPU tests verify that:
Dataset.shuffle()does not modify the process-global RNG state;Relevant CPU regression suite:
Result: 22 passed.
Repository checks:
All pre-commit hooks passed, and
git diff --checkreported no errors.