Repository navigation
[Train] [Data] Add inter-execution file shuffling to enable deterministic multi-epoch training - #59528
Merged
alexeykudinkin merged 15 commits intoDec 18, 2025
Conversation
The GIL makes checking s`elf._serialize_cache is not None` atomic, so we don't need lock. Signed-off-by: Xinyuan <[email protected]>
Signed-off-by: xgui <[email protected]>
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature for deterministic multi-epoch training by enabling execution-aware file shuffling. The implementation is well-structured, with the core logic encapsulated in FileShuffleConfig and a new _shuffle_file_metadata helper function. The use of an ExecutionCallback to manage the execution index is a clean approach. The changes are propagated consistently across various datasources. I have a couple of suggestions to improve the robustness of seed generation and to align an implementation with its type hint. Overall, this is a solid contribution.
alexeykudinkin
approved these changes
Dec 18, 2025
matthewdeng
approved these changes
Dec 18, 2025
richardliaw
pushed a commit
that referenced
this pull request
Mar 24, 2026
## Description Adding two new expressions: * `random()` for generating a column of uniform random number. * `uuid()` for generating UUID (a column of unique strings) `random()` accepts two arguments, related to reproducibility: * `seed`: a "base" random seed. Default is `None`. * `reseed_after_execution`: This is a flag that affects the random number generation across different iteration of `iter_batches` (i.e., across different epochs in the context of epochs). See also, #59528. It only matters when the `seed` is set. If False, each dataset execution will generate the same set of random number. If True, each dataset execution (i.e., training epoch) will give a new but reproducible set of random number. `uuid()` takes no argument. ## Related issues Related to #55275 Related to #59662 as well. I did this PR first...so probably I could use the same `RandomSeedConfig` in that PR. ## Additional information [Random seed business] The actual seed sequence used to initialize the random number generator is `[block_idx, task_idx, execution_idx, base_seed]`. The block idx is tracked by a counter (like in `monotonically_increasing_id()`). The task and execution indices are coming from `TaskContext` and `DataContext`, respectively. The way I used `execution_idx` is slightly different to what `FileShuffleConfig` is doing, but I think all these random seed business could be consolidated in the future (e.g., random_sample) [Independent visit functions] Following the discussion in #59290, there are separate `visit_uuid()` and `visit_random` for these expressions. Signed-off-by: Kit Lee <[email protected]>
ryanaoleary
pushed a commit
to ryanaoleary/ray
that referenced
this pull request
Mar 25, 2026
## Description Adding two new expressions: * `random()` for generating a column of uniform random number. * `uuid()` for generating UUID (a column of unique strings) `random()` accepts two arguments, related to reproducibility: * `seed`: a "base" random seed. Default is `None`. * `reseed_after_execution`: This is a flag that affects the random number generation across different iteration of `iter_batches` (i.e., across different epochs in the context of epochs). See also, ray-project#59528. It only matters when the `seed` is set. If False, each dataset execution will generate the same set of random number. If True, each dataset execution (i.e., training epoch) will give a new but reproducible set of random number. `uuid()` takes no argument. ## Related issues Related to ray-project#55275 Related to ray-project#59662 as well. I did this PR first...so probably I could use the same `RandomSeedConfig` in that PR. ## Additional information [Random seed business] The actual seed sequence used to initialize the random number generator is `[block_idx, task_idx, execution_idx, base_seed]`. The block idx is tracked by a counter (like in `monotonically_increasing_id()`). The task and execution indices are coming from `TaskContext` and `DataContext`, respectively. The way I used `execution_idx` is slightly different to what `FileShuffleConfig` is doing, but I think all these random seed business could be consolidated in the future (e.g., random_sample) [Independent visit functions] Following the discussion in ray-project#59290, there are separate `visit_uuid()` and `visit_random` for these expressions. Signed-off-by: Kit Lee <[email protected]>
Lucas61000
pushed a commit
to Lucas61000/ray
that referenced
this pull request
May 15, 2026
## Description Adding two new expressions: * `random()` for generating a column of uniform random number. * `uuid()` for generating UUID (a column of unique strings) `random()` accepts two arguments, related to reproducibility: * `seed`: a "base" random seed. Default is `None`. * `reseed_after_execution`: This is a flag that affects the random number generation across different iteration of `iter_batches` (i.e., across different epochs in the context of epochs). See also, ray-project#59528. It only matters when the `seed` is set. If False, each dataset execution will generate the same set of random number. If True, each dataset execution (i.e., training epoch) will give a new but reproducible set of random number. `uuid()` takes no argument. ## Related issues Related to ray-project#55275 Related to ray-project#59662 as well. I did this PR first...so probably I could use the same `RandomSeedConfig` in that PR. ## Additional information [Random seed business] The actual seed sequence used to initialize the random number generator is `[block_idx, task_idx, execution_idx, base_seed]`. The block idx is tracked by a counter (like in `monotonically_increasing_id()`). The task and execution indices are coming from `TaskContext` and `DataContext`, respectively. The way I used `execution_idx` is slightly different to what `FileShuffleConfig` is doing, but I think all these random seed business could be consolidated in the future (e.g., random_sample) [Independent visit functions] Following the discussion in ray-project#59290, there are separate `visit_uuid()` and `visit_random` for these expressions. Signed-off-by: Kit Lee <[email protected]>
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.
This PR renamed #59044
Description
This PR adds execution-aware shuffling to Ray Data's file-based datasources, enabling different file orders across different executions while maintaining determinism.
Changes
Core functionality:
execution_idxfield toDataContextto track the current epochFileShuffleConfigcan receivebase_seedto automatically increment seed after each executionFileShuffleConfigstill usesseed, the random seed is still the same for each execution.FileBasedDatasource.get_read_tasks()to acceptexecution_idxparameter and pass it through the shuffle logicBenefits:
base_seedis provided