Repository navigation
Fix unseeded shuffle and train/test split entropy (#9097) - #9108
Open
zhengdaodeguL wants to merge 1 commit into
Open
zhengdaodeguL wants to merge 1 commit into
zhengdaodeguL wants to merge 1 commit into
Conversation
Let default_rng(None) draw fresh entropy instead of deriving and consuming NumPy's legacy global state. Use fresh entropy for the corresponding cache fingerprints so unseeded disk-backed operations do not reuse previous results. Cover shuffle and train_test_split in memory and on disk, including global RNG preservation and seeded reproducibility. Reported by PCTEJA: huggingface#9097
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.
Fixes #9097
Dataset.shuffle()andDataset.train_test_split()documented that aNoneseed pulls "fresh, unpredictable entropy from the OS", but both drew the seed from the legacy globalnp.randomstate instead — and consumed one step of it. Anyone who callednp.random.seed(42)earlier got a fully deterministic "unseeded" shuffle, and callingshuffle()silently advanced all subsequentnp.random.*draws in the user's program.The fix removes the legacy-state derivation in both call sites and lets
np.random.default_rng(seed)handleNonedirectly (NumPy draws OS entropy forNone). The same pattern infingerprint.py(cache fingerprints for randomized transforms) is fixed the same way, so unseeded disk-backed operations don't reuse previous results via identical fingerprints. Seeded behavior is unchanged.Thanks to PCTEJA for reporting the issue with a precise root-cause analysis.
Verification
tests/test_arrow_dataset.py: unseeded shuffle/split differ across runs even under the same global seed, callingshuffle()/train_test_split()does not advance the globalnp.randomstate, and seeded runs stay reproducible (in-memory and on-disk). All 10 new cases pass; the 8 unseeded/global-RNG cases fail on base (verified with a source-only base control).rufflint/format clean.temp_seed(42)produce the same order encoded the buggy behavior; it is replaced by the corrected expectation.