-
Notifications
You must be signed in to change notification settings - Fork 362
Reorg for converters elu and selu (FX Converter Refactor [7/N]) <Target: converter_reorg_proto> #1903
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Reorg for converters elu and selu (FX Converter Refactor [7/N]) <Target: converter_reorg_proto> #1903
Changes from all commits
Commits
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 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
51 changes: 51 additions & 0 deletions
51
py/torch_tensorrt/fx/test/converters/aten_op/test_elu_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,51 @@ | ||
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 TestELUConverter(DispatchTestCase): | ||
def test_elu(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.elu(x) | ||
|
||
inputs = [torch.randn(1, 10)] | ||
self.run_test(TestModule(), inputs, expected_ops={torch.ops.aten.elu.default}) | ||
|
||
def test_elu_with_dynamic_shape(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.elu(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.elu.default} | ||
) | ||
|
||
def test_elu_with_dynamic_shape_four_dimensions(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.elu(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.elu.default} | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |
51 changes: 51 additions & 0 deletions
51
py/torch_tensorrt/fx/test/converters/aten_op/test_selu_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,51 @@ | ||
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 TestSeLUConverter(DispatchTestCase): | ||
def test_selu(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.selu(x) | ||
|
||
inputs = [torch.randn(1, 10)] | ||
self.run_test(TestModule(), inputs, expected_ops={torch.ops.aten.elu.default}) | ||
|
||
def test_selu_with_dynamic_shape(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.selu(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.elu.default} | ||
) | ||
|
||
def test_selu_with_dynamic_shape_four_dimensions(self): | ||
class TestModule(nn.Module): | ||
def forward(self, x): | ||
return nn.functional.selu(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.elu.default} | ||
) | ||
|
||
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of this if logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aten trace for both selu and elu comes as torch.ops.aten.elu.default, but with different args. elu has args[0] and args[1] for alpha, while selu has only one arg args[0]. Just a way to differentiate between the two.