-
Notifications
You must be signed in to change notification settings - Fork 364
Rand converter - evaluator #2580
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f0a4721
rand converters
apbose f02e744
rand converters
apbose 885f04c
Correcting rand test cases
apbose 01aa347
linting fixes
apbose df4aad0
adding validators to rand() test
apbose 77e626d
moving the error output to validator
apbose 25ebdba
consolidating the two validators and removing assertion check from ev…
apbose 787aa4f
correcting rand test
apbose 3e4fbeb
removing device kwargs since not used
apbose 578c1f6
changing the test to compare size instead of elements
apbose f503b61
changing the data type in interpretor setting
apbose 2ee77fa
Change name of run_test_comparator function in harness.py
apbose 3710b86
removing precision in harness.py interpreter compilationsettings and …
apbose 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
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import torch | ||
import torch.nn as nn | ||
import torch_tensorrt | ||
from parameterized import parameterized | ||
from torch.testing._internal.common_utils import TestCase, run_tests | ||
|
||
from .harness import DispatchTestCase | ||
|
||
rand_ops = [ | ||
( | ||
"rand_one_dimension", | ||
(lambda shape: torch.ops.aten.rand(shape)), | ||
[1], | ||
), | ||
( | ||
"rand_two_dimension", | ||
(lambda shape: torch.ops.aten.rand(shape)), | ||
[1, 2], | ||
), | ||
( | ||
"rand_three_dimension", | ||
(lambda shape: torch.ops.aten.rand(shape)), | ||
[2, 3, 4], | ||
), | ||
( | ||
"randn_one_dimension", | ||
(lambda shape: torch.ops.aten.randn(shape)), | ||
[1], | ||
), | ||
( | ||
"randn_two_dimension", | ||
(lambda shape: torch.ops.aten.randn(shape)), | ||
[2, 3], | ||
), | ||
( | ||
"randn_three_dimension", | ||
(lambda shape: torch.ops.aten.randn(shape)), | ||
[2, 3, 4], | ||
), | ||
] | ||
|
||
|
||
rand_perm_ops = [ | ||
( | ||
"randperm_one_case", | ||
(lambda x: torch.ops.aten.randperm(x)), | ||
[1], | ||
), | ||
( | ||
"randperm_two_case", | ||
(lambda x: torch.ops.aten.randperm(x)), | ||
[150], | ||
), | ||
( | ||
"randperm_three_case", | ||
(lambda x: torch.ops.aten.randperm(x)), | ||
[1500], | ||
), | ||
] | ||
|
||
|
||
class TestRandConverter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
( | ||
rand_op[0], | ||
rand_op[1], | ||
rand_op[2], | ||
) | ||
for rand_op in rand_ops | ||
] | ||
) | ||
def test_rand(self, name, op, shape_or_input): | ||
class TestModule(nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, x): | ||
shape_or_input[0] = x.shape[0] | ||
return op(shape_or_input) | ||
|
||
rand_model = TestModule() | ||
|
||
inputs = [torch.randint(1, 3, shape_or_input, dtype=torch.int32)] | ||
comparator_shape = lambda x, y, check_dtype: x.shape == y.shape and ( | ||
x.dtype == y.dtype if check_dtype else True | ||
) | ||
expected_ops = [] | ||
self.run_test_compare_tensor_attributes_only( | ||
rand_model, | ||
inputs, | ||
expected_ops, | ||
[(comparator_shape, [True])], | ||
use_dynamo_tracer=True, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
( | ||
rand_op[0], | ||
rand_op[1], | ||
rand_op[2], | ||
) | ||
for rand_op in rand_perm_ops | ||
] | ||
) | ||
def test_rand(self, name, op, shape_or_input): | ||
class TestModule(nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, x): | ||
shape_or_input[0] = x.shape[0] | ||
return op(shape_or_input[0]) | ||
|
||
rand_model = TestModule() | ||
# cannot use self.run_test() since it expects input in form of tensor | ||
|
||
inputs = [torch.randint(1, 3, shape_or_input, dtype=torch.int32)] | ||
comparator_shape = lambda x, y, check_dtype: x.shape == y.shape and ( | ||
x.dtype == y.dtype if check_dtype else True | ||
) | ||
expected_ops = [] | ||
# TRT-TRT returns int32 while torch returns int64 | ||
self.run_test_compare_tensor_attributes_only( | ||
rand_model, | ||
inputs, | ||
expected_ops, | ||
[(comparator_shape, [False])], | ||
use_dynamo_tracer=True, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |
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.
Uh oh!
There was an error while loading. Please reload this page.