-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
139 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,38 +1,89 @@ | ||
import pytest | ||
import torch | ||
import torch.nn as nn | ||
from harness import DispatchTestCase | ||
from parameterized import parameterized | ||
from torch.testing._internal.common_utils import run_tests | ||
from torch_tensorrt import Input | ||
from parameterized import parameterized | ||
from .harness import DispatchTestCase | ||
|
||
|
||
class TestGridConverter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
("input_grid_interpolation_nearest_sample_fill", [5,5], [5,2], 0, 0), | ||
("input_grid_interpolation_nearest_sample_clamp", [5,5], [5,2], 0, 1), | ||
("input_grid_interpolation_nearest_sample_reflect", [5,5], [5,2], 0, 2), | ||
("input_grid_interpolation_linear_sample_fill", [5,5], [5,2], 1, 0), | ||
("input_grid_interpolation_linear_sample_clamp", [5,5], [5,2], 1, 1), | ||
("input_grid_interpolation_linear_sample_reflect", [5,5], [5,2], 1, 2), | ||
("input_grid_interpolation_cubic_sample_fill", [5,5], [5,2], 2, 0), | ||
("input_grid_interpolation_cubic_sample_clamp", [5,5], [5,2], 2, 1), | ||
("input_grid_interpolation_cubic_sample_reflect", [5,5], [5,2], 2, 2), | ||
( | ||
"input_grid_interpolation_nearest_sample_fill", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
0, | ||
0, | ||
), | ||
( | ||
"input_grid_interpolation_nearest_sample_clamp", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
0, | ||
1, | ||
), | ||
( | ||
"input_grid_interpolation_nearest_sample_reflect", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
0, | ||
2, | ||
), | ||
( | ||
"input_grid_interpolation_linear_sample_fill", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
1, | ||
0, | ||
), | ||
( | ||
"input_grid_interpolation_linear_sample_clamp", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
1, | ||
1, | ||
), | ||
( | ||
"input_grid_interpolation_linear_sample_reflect", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
1, | ||
2, | ||
), | ||
( | ||
"input_grid_interpolation_cubic_sample_fill", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
2, | ||
0, | ||
), | ||
( | ||
"input_grid_interpolation_cubic_sample_clamp", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
2, | ||
1, | ||
), | ||
( | ||
"input_grid_interpolation_cubic_sample_reflect", | ||
[1, 1, 5, 5], | ||
[1, 5, 2, 2], | ||
2, | ||
2, | ||
), | ||
] | ||
) | ||
def test_grid(self,_, input_shape, dim_shape, interpolation, sample): | ||
def test_grid(self, _, input_shape, dim_shape, interpolation, sample): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
input = torch.randn(10).reshape(input_shape) | ||
grid = torch.randint(-1, 1, dim_shape) | ||
return nn.functional.grid(input, grid, interpolation, sample) | ||
|
||
inputs = [torch.randn(1, 10)] | ||
self.run_test(TestModule(), inputs, expected_ops={torch.ops.aten.grid_sampler.out}) | ||
|
||
|
||
grid = torch.randint(-1, 1, dim_shape, dtype=torch.float32) | ||
return torch.ops.aten.grid_sampler(x, grid, interpolation, sample, True) | ||
|
||
inputs = [torch.randn(input_shape, dtype=torch.float32)] | ||
self.run_test(TestModule(), inputs) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |