Skip to content
New issue

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

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

Already on GitHub? # to your account

[Bugfix] fix flaky test #13089

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions tests/test_seed_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,17 @@


def test_seed_behavior():
# Test with seed=None
Platform.seed_everything(None)
# Test with a specific seed
Platform.seed_everything(42)
random_value_1 = random.randint(0, 100)
np_random_value_1 = np.random.randint(0, 100)
torch_random_value_1 = torch.randint(0, 100, (1, )).item()

Platform.seed_everything(None)
Platform.seed_everything(42)
random_value_2 = random.randint(0, 100)
np_random_value_2 = np.random.randint(0, 100)
torch_random_value_2 = torch.randint(0, 100, (1, )).item()

assert random_value_1 != random_value_2
assert np_random_value_1 != np_random_value_2
assert torch_random_value_1 != torch_random_value_2

# Test with a specific seed
Platform.seed_everything(42)
random_value_3 = random.randint(0, 100)
np_random_value_3 = np.random.randint(0, 100)
torch_random_value_3 = torch.randint(0, 100, (1, )).item()

Platform.seed_everything(42)
random_value_4 = random.randint(0, 100)
np_random_value_4 = np.random.randint(0, 100)
torch_random_value_4 = torch.randint(0, 100, (1, )).item()

assert random_value_3 == random_value_4
assert np_random_value_3 == np_random_value_4
assert torch_random_value_3 == torch_random_value_4
assert random_value_1 == random_value_2
assert np_random_value_1 == np_random_value_2
assert torch_random_value_1 == torch_random_value_2