[Tests] Add per-item deterministic RNG seeding for pytest - #1645
Open
merkelmarrow wants to merge 7 commits into
Open
[Tests] Add per-item deterministic RNG seeding for pytest#1645merkelmarrow wants to merge 7 commits into
merkelmarrow wants to merge 7 commits into
Conversation
derive a stable per-test seed from each pytest node ID. Seed Python, NumPy and the default CPU Torch generator before each test, expose the resolved seed in JUnit output. Signed-off-by: Marco Blackwell <mblackwe@amd.com>
Remove redundant seed-0 resets from independent fpgadataflow tests so the autouse fixture gives each parametrisation reproducible distinct data. Generate dynamic-convolution weights once before the dimension loop instead of resetting global NumPy state inside the model helper. Signed-off-by: Marco Blackwell <mblackwe@amd.com>
Remove redundant seed resets from rewrite and conversion tests so each parametrisation uses stable distinct data from the autouse fixture. Signed-off-by: Marco Blackwell <mblackwe@amd.com>
Reomove the seed-0 reset from make_quant_test_model so scale and zeropt uses the autouse per-item seed from conftest. Signed-off-by: Marco Blackwell <mblackwe@amd.com>
Signed-off-by: Marco Blackwell <mblackwe@amd.com>
Add a randomness section to tests/README.md describing the per-item seed fixture. Signed-off-by: Marco Blackwell <mblackwe@amd.com>
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 change adds deterministic automatic seeding across all tests. Seeding is derived from each pytest node id which is individual to each test. This is done through an autouse fixture in
tests/conftest.py.This addresses problems we've historically had with determinism. This is a deliberate tradeoff; on the one hand we're losing the feedback that "one particular test fails 1% of the time, thus the reference output calculations aren't perfectly representative". But these kinds of failures add a lot of noise when we're more interested in finding actual regressions.
The intended RNG policy is described in the extension to the testing guidelines doc.
Implementation
sha256(nodeid)intests/rng_seed.py. xdist loadgroup suffixes are stripped using the predefined regex in finn_ci.tests/conftest.pyadds an autouse fixture.tests/util/test_rng_determinism.pycover suffix normalisation and numpy / torch seed behaviourtest_fpgadataflow_convinputgenerator_rtl_dynamic.py)Testing
Other notes
Maintainers, note the guideline in the README that
np.random.default_rng()should be seeded with finn_test_seed.Tests that now fail due to tolerances at the deterministic seed should now be treated as deficient. Either the generator that produces the reference output should be improved to better model simulation outputs or the tolerances should be relaxed.