|
| 1 | +import torch |
| 2 | +import torch.nn as nn |
| 3 | +from torch.testing._internal.common_utils import run_tests |
| 4 | +from torch_tensorrt.fx.tools.common_fx2trt import DispatchTestCase, InputTensorSpec |
| 5 | + |
| 6 | + |
| 7 | +class TestSeLUConverter(DispatchTestCase): |
| 8 | + def test_selu(self): |
| 9 | + class TestModule(nn.Module): |
| 10 | + def forward(self, x): |
| 11 | + return nn.functional.selu(x) |
| 12 | + |
| 13 | + inputs = [torch.randn(1, 10)] |
| 14 | + self.run_test(TestModule(), inputs, expected_ops={torch.ops.aten.elu.default}) |
| 15 | + |
| 16 | + def test_selu_with_dynamic_shape(self): |
| 17 | + class TestModule(nn.Module): |
| 18 | + def forward(self, x): |
| 19 | + return nn.functional.selu(x) |
| 20 | + |
| 21 | + input_specs = [ |
| 22 | + InputTensorSpec( |
| 23 | + shape=(-1, -1, -1), |
| 24 | + dtype=torch.float32, |
| 25 | + shape_ranges=[((1, 1, 1), (1, 2, 3), (3, 3, 3))], |
| 26 | + ), |
| 27 | + ] |
| 28 | + self.run_test_with_dynamic_shape( |
| 29 | + TestModule(), input_specs, expected_ops={torch.ops.aten.elu.default} |
| 30 | + ) |
| 31 | + |
| 32 | + def test_selu_with_dynamic_shape_four_dimensions(self): |
| 33 | + class TestModule(nn.Module): |
| 34 | + def forward(self, x): |
| 35 | + return nn.functional.selu(x) |
| 36 | + |
| 37 | + input_specs = [ |
| 38 | + InputTensorSpec( |
| 39 | + shape=(-1, -1, -1, -1), |
| 40 | + dtype=torch.float32, |
| 41 | + shape_ranges=[((1, 1, 1, 5), (1, 2, 3, 5), (3, 3, 3, 5))], |
| 42 | + ), |
| 43 | + ] |
| 44 | + |
| 45 | + self.run_test_with_dynamic_shape( |
| 46 | + TestModule(), input_specs, expected_ops={torch.ops.aten.elu.default} |
| 47 | + ) |
| 48 | + |
| 49 | + |
| 50 | +if __name__ == "__main__": |
| 51 | + run_tests() |
0 commit comments