This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 814
Parameterize jit and non-jit model integration tests #1502
Merged
Nayef211
merged 10 commits into
pytorch:main
from
Nayef211:test/parameterize_integration_tests
Jan 11, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94a3349
Updated max seq length for truncate in xlmr base. Updated xlmr docs. …
60bb626
Removing changes to truncate transform
514e9fc
Merge branch 'main' into update_xlmr_encoder
b6f08ed
Remove documentation changes from PR
e2c79e7
Parameterized model tests
964b30b
Merge branch 'main' into update_xlmr_encoder
226d5ca
Added nested_params helper method. Updated model integration test to …
3529e7e
Merge branch 'main' into test/parameterize_integration_tests
7727838
Added docstring for unit tests
fdd1528
Merge branch 'main' into test/parameterize_integration_tests
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,53 @@ | ||
| import json | ||
| from itertools import product | ||
|
|
||
| from parameterized import param | ||
| from parameterized import param, parameterized | ||
|
|
||
| from .assets import get_asset_path | ||
|
|
||
|
|
||
| def load_params(*paths): | ||
| with open(get_asset_path(*paths), "r") as file: | ||
| return [param(json.loads(line)) for line in file] | ||
|
|
||
|
|
||
| def _name_func(func, _, params): | ||
| strs = [] | ||
| for arg in params.args: | ||
| if isinstance(arg, tuple): | ||
| strs.append("_".join(str(a) for a in arg)) | ||
| else: | ||
| strs.append(str(arg)) | ||
| # sanitize the test name | ||
| name = "_".join(strs).replace(".", "_") | ||
| return f"{func.__name__}_{name}" | ||
|
|
||
|
|
||
| def nested_params(*params_set): | ||
| """Generate the cartesian product of the given list of parameters. | ||
| Args: | ||
| params_set (list of parameters): Parameters. When using ``parameterized.param`` class, | ||
| all the parameters have to be specified with the class, only using kwargs. | ||
| """ | ||
| flatten = [p for params in params_set for p in params] | ||
|
|
||
| # Parameters to be nested are given as list of plain objects | ||
| if all(not isinstance(p, param) for p in flatten): | ||
| args = list(product(*params_set)) | ||
| return parameterized.expand(args, name_func=_name_func) | ||
|
|
||
| # Parameters to be nested are given as list of `parameterized.param` | ||
| if not all(isinstance(p, param) for p in flatten): | ||
| raise TypeError( | ||
| "When using ``parameterized.param``, " | ||
| "all the parameters have to be of the ``param`` type." | ||
| ) | ||
| if any(p.args for p in flatten): | ||
| raise ValueError( | ||
| "When using ``parameterized.param``, " | ||
| "all the parameters have to be provided as keyword argument." | ||
| ) | ||
| args = [param()] | ||
| for params in params_set: | ||
| args = [param(**x.kwargs, **y.kwargs) for x in args for y in params] | ||
| return parameterized.expand(args) |
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.
nit: This test is rather self-explanatory, so I think it's okay, but I recommend writing a short docstrings for tests so that future maintainers can tell what was my intention and see if the implementation makes sense.
Writing docstring helps defining what consists of a correct test, what's the definition, when there is no intuitive test criteria for a new feature.
Uh oh!
There was an error while loading. Please reload this page.
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 for the feedback. Just added a short docstring to describe what's being tested