MCPcopy
hub / github.com/ray-project/ray / test_random_api_reseed_behavior

Function test_random_api_reseed_behavior

python/ray/data/tests/test_random_api.py:115–151  ·  view source on GitHub ↗

Test reseed_after_execution behavior across multiple epochs. For shuffle/block_order we compare full row order (no sort); for random_sample we compare sorted items so we only assert same set of sampled rows.

(base_dataset)

Source from the content-addressed store, hash-verified

113
114
115def test_random_api_reseed_behavior(base_dataset):
116 """Test reseed_after_execution behavior across multiple epochs.
117
118 For shuffle/block_order we compare full row order (no sort); for random_sample
119 we compare sorted items so we only assert same set of sampled rows.
120 """
121 seed_value = 42
122 seed_false = RandomSeedConfig(seed=seed_value, reseed_after_execution=False)
123 seed_true = RandomSeedConfig(seed=seed_value, reseed_after_execution=True)
124
125 # Test random_shuffle with reseed_after_execution=False
126 ds = base_dataset.random_shuffle(seed=seed_false)
127 epochs = collect_batches_from_epochs(ds, num_epochs=3, batch_size=5)
128 assert (
129 epochs[0] == epochs[1] == epochs[2]
130 ), "reseed_after_execution=False should produce same results"
131
132 # Test random_shuffle with reseed_after_execution=True
133 ds = base_dataset.random_shuffle(seed=seed_true)
134 epochs = collect_batches_from_epochs(ds, num_epochs=3, batch_size=5)
135 assert (epochs[0] != epochs[1]) or (
136 epochs[1] != epochs[2]
137 ), "reseed_after_execution=True should produce different results per epoch"
138
139 # Test random_sample with reseed_after_execution=False
140 ds = base_dataset.random_sample(fraction=0.5, seed=seed_false)
141 epochs = collect_batches_from_epochs(ds, num_epochs=2, batch_size=5)
142 assert sorted(epochs[0]) == sorted(
143 epochs[1]
144 ), "reseed_after_execution=False should produce same sampled items"
145
146 # Test randomize_block_order with reseed_after_execution=False
147 ds = base_dataset.randomize_block_order(seed=seed_false)
148 epochs = collect_batches_from_epochs(ds, num_epochs=2, batch_size=5)
149 assert (
150 epochs[0] == epochs[1]
151 ), "reseed_after_execution=False should produce same block order"
152
153
154@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 5

RandomSeedConfigClass · 0.90
random_sampleMethod · 0.80
randomize_block_orderMethod · 0.80
random_shuffleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…