-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorg for converters in hardtanh(FX Converter Refactor [5/N]) <Target…
…: converter_reorg_proto> (#1901)
- Loading branch information
1 parent
7864865
commit ae564d7
Showing
5 changed files
with
117 additions
and
12 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
53 changes: 53 additions & 0 deletions
53
py/torch_tensorrt/fx/test/converters/aten_op/test_hardtanh_aten.py
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import torch | ||
import torch.nn as nn | ||
from torch.testing._internal.common_utils import run_tests | ||
from torch_tensorrt.fx.tools.common_fx2trt import DispatchTestCase, InputTensorSpec | ||
|
||
|
||
class TestHardTanHConverter(DispatchTestCase): | ||
def test_hardtanh(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.hardtanh(x) | ||
|
||
inputs = [torch.randn(1, 10)] | ||
self.run_test( | ||
TestModule(), inputs, expected_ops={torch.ops.aten.hardtanh.default} | ||
) | ||
|
||
def test_hardtanh_with_dynamic_shape(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.hardtanh(x) | ||
|
||
input_specs = [ | ||
InputTensorSpec( | ||
shape=(-1, -1, -1), | ||
dtype=torch.float32, | ||
shape_ranges=[((1, 1, 1), (1, 2, 3), (3, 3, 3))], | ||
), | ||
] | ||
self.run_test_with_dynamic_shape( | ||
TestModule(), input_specs, expected_ops={torch.ops.aten.hardtanh.default} | ||
) | ||
|
||
def test_hardtanh_with_dynamic_shape_four_dimensions(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.hardtanh(x) | ||
|
||
input_specs = [ | ||
InputTensorSpec( | ||
shape=(-1, -1, -1, -1), | ||
dtype=torch.float32, | ||
shape_ranges=[((1, 1, 1, 5), (1, 2, 3, 5), (3, 3, 3, 5))], | ||
), | ||
] | ||
|
||
self.run_test_with_dynamic_shape( | ||
TestModule(), input_specs, expected_ops={torch.ops.aten.hardtanh.default} | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |