-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fixed unit tests with random function #7702
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
Closed
juampatronics
wants to merge
3
commits into
Project-MONAI:dev
from
juampatronics:7697-assertion_error_in_test_regularization
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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.
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.
While this check might help mitigate the issue, it's not addressing the core problem. After
set_determinism(seed=0), we should guarantee consistent transform results every time.cc @ericspod
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.
If we're setting a seed before the test then we should get the same results every time. Any behaviour dependent on a random variable should be dependent by this seed so that we can enforce determinism in cases like this. These transforms should inherit form
RandomizableTransformbut also set the random state of the internal delegate transform appropriately like here. This ensures the seed value is propagated to the delegate.Sorry this wasn't discussed in the initial PR for these transforms, it's something we missed.
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.
Thank you @ericspod for the detailed explanation of how to correctly implement it
Also, I still think that the unit test was missing the case that no transform happens when the mixing only considers one of the samples. Now this is exactly tested and it is checked that it happens as often as expected, so I would leave it as it is now.
Best
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 does test that the mixing is a no-op an expected number of times, but I feel that's a problem with the tests not being deterministic. The issue is that for a given seed we should see the exact behaviour, so be able to choose a seed that gives a no-op for a fixed input and test that this continues to happen (changing the seed as needed). This test may pass if the no-op occurs correctly a known number of times, but could also pass if there's a bug causing no-ops at the wrong time but within your threshold. We aren't directly testing that a no-op occurs. Tests should always be deterministic, if we fix the Mixup/CutMix classes to be so we can do that here as well.