-
Notifications
You must be signed in to change notification settings - Fork 81
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
[UnitTests] Parametrized Unit Tests #7
Conversation
@Lunderberg I think there were two open items from the discuss post:
on 1, it sounds like you had found a solution, so I think we're resolved there. on 2, you'd suggested to table the discussion of how to cache non-serializable objects and just cache serializable ones. that sounds great to me. so then, the real reason I was having this debate with you: i'd like to propose that in all cases (cache hot or cold), we always provide test functions with a brand-new deserialized copy of the data. i think that solves all of my concerns around tests poisoning downstream tests with cached data, and hopefully has not-too-significant performance impact. what are your thoughts? |
I think that makes sense for now, and is a good way to maintain separation between unit tests. Running through I ran a few quick benchmarks for numpy arrays, since I think those would be the most frequently cached result. |
@Lunderberg I was thinking you could just require tests provide |
How would we deserialize the objects in that case? I thought that |
.gitignore
Outdated
@@ -0,0 +1,2 @@ | |||
# Emacs temporary files |
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 these should go in your global .gitignore not the project-specific one
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.
Fair enough, and I can remove it if that is preferable. I try to avoid using the global .gitignore
in most cases, so that git add .
is safe to use in general, and not just on my environment. The tvm repo already has this line in its .gitignore
, so I figured it was good to add here. (Though in retrospect it probably should have been a separate PR.)
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.
okay, please remove this from the change then. we can debate it on another RFC
Copying some notes from a 1:1, along with commentary at the bottom. Caching options listed below, arranged from most flexibility at the top to least flexibility at the bottom.
Overall, @areusch 's concern is avoiding hidden failure modes, especially where there could be tests that only appear to pass due to cross-talk. As such, he is more comfortable with more explicit usage. and would be comfortable with any of implementations 3-5. @Lunderberg 's main concern is usability and ease of enabling, such that a slow test can have caching enabled with minimal effort where it is needed, and would be comfortable with any of implementations 2-3. One key point that we came up with is that we expect fixtures to be uncached by default ( Since #3 is the overlap we both like between having opt-in caching, both on a per-return-value and per-fixture basis, I've put together a test implementation. It calls @areusch Can you check this over to make sure I've given an accurate description of your comments? |
@Lunderberg i think that sounds right. i agree #3 is the overlap between our positions. i'd like for others to comment whether it may be too complex to understand in debugging; otherwise i think we can proceed here. to be explicit: we intend to copy only whitelisted types, and not allow |
@areusch Any status changes on this? |
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.
hi @Lunderberg sorry for the long delay here. I reread this and just have a few minor clarifications I'd like you to make on the wording. Other than that, looks great! Feel free to ping aggressively when these are addressed and we can merge right away.
.gitignore
Outdated
@@ -0,0 +1,2 @@ | |||
# Emacs temporary files |
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.
okay, please remove this from the change then. we can debate it on another RFC
rfcs/0007-parametrized-unit-tests.md
Outdated
|
||
Some unit tests should be tested along a variety of parameters for | ||
better coverage. For example, a unit test that does not depend on | ||
target-specific features should be tested on all targets that the test |
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.
nit: "could be tested"
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.
Good point, and changed. The "should" is a stronger statement, and was what I initially intended, but I'd changed my mind given the current impact to CI runtime.
rfcs/0007-parametrized-unit-tests.md
Outdated
The simplest implementation would be to write a test function that | ||
loops over all parameters, throwing an exception if any parameter | ||
fails the test. However, this does not give full information to a | ||
developer, as a failure from any parameter results in the entire test | ||
to be marked as failing. A unit-test that fails for all targets |
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.
The simplest implementation would be to write a test function that | |
loops over all parameters, throwing an exception if any parameter | |
fails the test. However, this does not give full information to a | |
developer, as a failure from any parameter results in the entire test | |
to be marked as failing. A unit-test that fails for all targets | |
The simplest implementation would be to write a test function that | |
internally loops over all parameters and throws an exception when the | |
test fails. However, this does not give full information to a | |
developer because `pytest` does not necessarily include the parameter | |
value in the test report (even when it does, the value is in a different place | |
depending on the way the internal loop is written). A unit-test that fails for all targets |
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.
Updated, mostly following your modified wording.
rfcs/0007-parametrized-unit-tests.md
Outdated
To make a new parameter for unit tests to use, define it with the | ||
`tvm.testing.parameter` function. For example, the following will |
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.
To make a new parameter for unit tests to use, define it with the | |
`tvm.testing.parameter` function. For example, the following will | |
Before you can use a parameter in a test case, you need to register it with `pytest`. | |
Do this using the `tvm.testing.parameter` function. For example, the following will |
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.
Updated as suggested.
rfcs/0007-parametrized-unit-tests.md
Outdated
``` | ||
|
||
To use a parameter, define a test function that accepts the parameter | ||
as an input. This test will be run once for each value of the |
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.
as an input. This test will be run once for each value of the | |
as an input (use the same name for the argument as you used above in the | |
parameter registration). This test will be run once for each value of the |
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.
Updated, but with a comma instead of a parenthetical.
rfcs/0007-parametrized-unit-tests.md
Outdated
useful to re-run tests that failed, to check whether the failure is | ||
due to modification/re-use of a cached value. | ||
|
||
A fixture can depend on parameters, or on other fixtures. This is |
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.
A fixture can depend on parameters, or on other fixtures. This is | |
A fixture can also depend on parameters or other fixtures. This is |
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.
Updated as suggested.
rfcs/0007-parametrized-unit-tests.md
Outdated
|
||
## Target/Device Parametrization | ||
|
||
The TVM test configuration contains definitions for `target` and |
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.
The TVM test configuration contains definitions for `target` and | |
The global TVM test configuration contains definitions for `target` and |
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.
Updated as suggested.
|
||
# After | ||
if __name__=='__main__': | ||
sys.exit(pytest.main(sys.argv)) |
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.
we should ideally split this out into a helper function and eventually add a pylint plugin to enforce, but good to document standard right now
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.
Agreed, and that would help with readability. I've added it to my todo list, though it's low on the priority.
rfcs/0007-parametrized-unit-tests.md
Outdated
# Prior art | ||
[prior-art]: #prior-art | ||
|
||
Discuss prior art, both the good and the bad, in relation to this proposal. |
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.
can you remove the boilerplate and just add a reference to i guess pytest.mark.parametrize
and functools.lru_cache
or whatever that is now?
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.
Updated with a reference to pytest.mark.parametrize
and pytest.fixture
's caching using the scope
parameter.
Following comments, I agree that it doesn't belong in this PR, and may include in a separate PR.
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.
thanks @Lunderberg !
Update 00xx_UMA_Unified_Modular_Accelerator_Interface.md
Migrating earlier conversation from https://discuss.tvm.apache.org/t/rfc-parametrized-unit-tests/9946. RFC should be up to date with all changes/conversations that occurred in that thread.
@areusch Let's continue any discussion here, to avoid having multiple places to check for the same RFC.