Repository navigation
[Data] vary randomize_block_order and random_shuffle seed across executions - #61426
matthewdeng wants to merge 3 commits into
Conversation
Signed-off-by: Matthew Deng <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request modifies randomize_block_order to use a different seed for each epoch, ensuring that block ordering varies across epochs even when a fixed seed is provided. This is achieved by combining the user-provided seed with the execution index. The logic for generating this per-epoch seed has been extracted into a new utility function, make_epoch_seed, which is also used to refactor FileShuffleConfig, improving code reuse. The changes are well-tested. I have one minor suggestion to improve code style by repositioning some imports.
| from ray.data._internal.util import make_epoch_seed | ||
| from ray.data.context import DataContext |
There was a problem hiding this comment.
|
Hi @matthewdeng , I have this PR doing this approved and pending to be merged: #59662 |
Signed-off-by: Matthew Deng <[email protected]>
Signed-off-by: Matthew Deng <[email protected]>
| elif self.reseed_after_execution: | ||
| # Modulo ensures the result is in valid NumPy seed range [0, 2**32 - 1]. | ||
| return hash((self.seed, execution_idx)) % (2**32) | ||
| return make_epoch_seed(self.seed, execution_idx) |
There was a problem hiding this comment.
FileShuffleConfig.get_seed formula silently changed from hash to addition
High Severity
FileShuffleConfig.get_seed() previously computed hash((self.seed, execution_idx)) % (2**32), which produces well-distributed, uncorrelated seeds across epochs. The refactoring replaced this with make_epoch_seed, which computes (seed + execution_idx) % (2**32) — a completely different formula. This silently changes the seed values returned for all existing users of FileShuffleConfig with reseed_after_execution=True, breaking reproducibility and producing weakly correlated sequential seeds (e.g., 42, 43, 44…) instead of hashed ones.
Additional Locations (1)
| return None | ||
| elif self.reseed_after_execution: | ||
| # Modulo ensures the result is in valid NumPy seed range [0, 2**32 - 1]. | ||
| return hash((self.seed, execution_idx)) % (2**32) |
There was a problem hiding this comment.
Note that this now changes the behavior from using a hash to just incrementing.
randomize_block_order seed across executionsrandomize_block_order and random_shuffle seed across executions
|
@wingkitlee0 oh nice, I'll close this one, thanks! |


Description
randomize_block_order(seed=X)produces the same block ordering every epoch because it always seeds with the fixed user seed.This varies the seed per epoch by combining it with
DataContext._execution_idx, matching the existing pattern inFileShuffleConfig.get_seed().Extracts the shared formula into
make_epoch_seed()inutil.py.