Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy rngs when seed is None #3641

Merged
merged 6 commits into from
Jan 27, 2022
Merged

Fix numpy rngs when seed is None #3641

merged 6 commits into from
Jan 27, 2022

Conversation

mariosasko
Copy link
Collaborator

Fixes the NumPy RNG when seed is None.

The problem becomes obvious after reading the NumPy notes on RNG (returned by np.random.get_state()):

The MT19937 state vector consists of a 624-element array of 32-bit unsigned integers plus a single integer value between 0 and 624 that indexes the current position within the main array.

The MT19937 state vector: the seed which we currently index, but this value stays the same for multiple rounds.
plus a single integer value: the pos value in this PR (is 624 if seed is set to a fixed value with np.random.seed, so we take the first value in the seed array returned by np.random.get_state(): https://stackoverflow.com/questions/32172054/how-can-i-retrieve-the-current-seed-of-numpys-random-number-generator)

NumPy notes: https://numpy.org/doc/stable/reference/random/bit_generators/mt19937.html

Fix #3634

Copy link
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ! That makes total sense :)

cc @Rocketknight1 I recall you had a similar issue a few months ago, when shuffling several times wouldn't change anything

@mariosasko mariosasko merged commit 42f6241 into master Jan 27, 2022
@mariosasko mariosasko deleted the fix-3634 branch January 27, 2022 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dataset.shuffle(seed=None) gives fixed row permutation
2 participants