-
Notifications
You must be signed in to change notification settings - Fork 538
Add global seed fixture for reproducible tests #516
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
Add global seed fixture for reproducible tests #516
Conversation
Defines a session-scoped fixture in conftest.py that sets seeds for torch, numpy, and random to ensure deterministic test behavior across sessions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a global pytest fixture to set random seeds for torch, numpy, and random, aiming to improve test reproducibility. The implementation is sound and correctly uses a session-scoped, autouse fixture. My feedback includes suggestions to further enhance determinism for CUDA operations, add a docstring for clarity, and improve comments within the fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a very positive change, hope I'm not overlooking anything here. Thanks a lot! (let's wait for Oscars review too)
oscarkey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good idea to me! Thank you. Just a few small suggestions.
- removed unnecessary comment - fixture scope = "function" - return type - removed unnecessary torch.cuda.manual_seed_all call
* Record copied public PR 516 * Add global seed fixture for reproducible tests (#516) Co-authored-by: MagnumMandel <111045718+PufferFishCode@users.noreply.github.com> Co-authored-by: noahho <Noah.homa@gmail.com> --------- Co-authored-by: mirror-bot <mirror-bot@users.noreply.github.com> Co-authored-by: MagnusBuehler <111045718+MagnusBuehler@users.noreply.github.com> Co-authored-by: MagnumMandel <111045718+PufferFishCode@users.noreply.github.com> Co-authored-by: noahho <Noah.homa@gmail.com>
Defines a session-scoped fixture in conftest.py that sets seeds for torch, numpy, and random to ensure deterministic test behavior across sessions.
Motivation and Context
Multiple tests rely on randomly sampled data using random, numpy, and torch. Without a fixed seed, this can lead to non-deterministic and flaky test results. Adding a global seed fixture improves consistent and reproducible test behavior across runs.
Public API Changes
How Has This Been Tested?
On a local machine the randomly sampled data across test runs are consistent.
Checklist
CHANGELOG.md(if relevant for users).