|
| 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 TestSigmoidConverter(DispatchTestCase): |
| 8 | + def test_sigmoid(self): |
| 9 | + class TestModule(nn.Module): |
| 10 | + def forward(self, x): |
| 11 | + return nn.functional.sigmoid(x) |
| 12 | + |
| 13 | + inputs = [torch.randn(1, 10)] |
| 14 | + self.run_test( |
| 15 | + TestModule(), inputs, expected_ops={torch.ops.aten.sigmoid.default} |
| 16 | + ) |
| 17 | + |
| 18 | + def test_sigmoid_with_dynamic_shape(self): |
| 19 | + class TestModule(nn.Module): |
| 20 | + def forward(self, x): |
| 21 | + return nn.functional.sigmoid(x) |
| 22 | + |
| 23 | + input_specs = [ |
| 24 | + InputTensorSpec( |
| 25 | + shape=(-1, -1, -1), |
| 26 | + dtype=torch.float32, |
| 27 | + shape_ranges=[((1, 1, 1), (1, 2, 3), (3, 3, 3))], |
| 28 | + ), |
| 29 | + ] |
| 30 | + self.run_test_with_dynamic_shape( |
| 31 | + TestModule(), input_specs, expected_ops={torch.ops.aten.sigmoid.default} |
| 32 | + ) |
| 33 | + |
| 34 | + def test_sigmoid_with_dynamic_shape_four_dimensions(self): |
| 35 | + class TestModule(nn.Module): |
| 36 | + def forward(self, x): |
| 37 | + return nn.functional.sigmoid(x) |
| 38 | + |
| 39 | + input_specs = [ |
| 40 | + InputTensorSpec( |
| 41 | + shape=(-1, -1, -1, -1), |
| 42 | + dtype=torch.float32, |
| 43 | + shape_ranges=[((1, 1, 1, 5), (1, 2, 3, 5), (3, 3, 3, 5))], |
| 44 | + ), |
| 45 | + ] |
| 46 | + |
| 47 | + self.run_test_with_dynamic_shape( |
| 48 | + TestModule(), input_specs, expected_ops={torch.ops.aten.sigmoid.default} |
| 49 | + ) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + run_tests() |
0 commit comments