-
Notifications
You must be signed in to change notification settings - Fork 365
Aten scatter converter #2664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Aten scatter converter #2664
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
628fab7
aten::select
apbose 6fbc0ec
scatter_value and scatter_src converter
apbose bfd3498
Linting fix
apbose 870b79f
scatter adding test cases for scatter.value and scatter.src
apbose 812114e
addressing review comments and changing test names
apbose 6afbb8d
uncommenting the tests
apbose 19049bc
Removing the int64 casting to int32 in harness.py since native int64 …
apbose 0449068
Dynamo test cases error correction and adding support for int64 indic…
apbose 0318b33
code cleanup
apbose 487906d
Addressing review comments
apbose 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,177 @@ | ||
import torch | ||
from parameterized import parameterized | ||
from torch.testing._internal.common_utils import run_tests | ||
from torch_tensorrt import Input | ||
|
||
from .harness import DispatchTestCase | ||
|
||
|
||
class TestScatterValueConverter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
( | ||
"scatter_zero_dim_indexOne_constant_value", | ||
0, | ||
torch.tensor([[0, 1, 2, 0]]), | ||
1, | ||
), | ||
( | ||
"scatter_zero_dim_indexTwo_constant_value", | ||
0, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
1, | ||
), | ||
( | ||
"scatter_one_dim_indexOne_constant_value", | ||
1, | ||
torch.tensor([[0, 1, 2, 0]]), | ||
1, | ||
), | ||
( | ||
"scatter_one_dim_indexTwo_costant_value", | ||
1, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
1, | ||
), | ||
] | ||
) | ||
def test_scatter_index_constant(self, _, dim, index, value): | ||
class TestModule(torch.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, input): | ||
return torch.ops.aten.scatter.value(input, dim, index, value) | ||
|
||
input = torch.zeros(3, 5, dtype=torch.int32) | ||
inputs = [input] | ||
self.run_test(TestModule(), inputs, int32_reqd=True) | ||
|
||
@parameterized.expand( | ||
[ | ||
("scatter_zero_dim_indexOne_value", 0, torch.tensor([[0, 1, 2, 0]]), 1), | ||
( | ||
"scatter_zero_dim_indexTwo_value", | ||
0, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
1, | ||
), | ||
("scatter_one_dim_indexOne_value", 1, torch.tensor([[0, 1, 2, 0]]), 1), | ||
( | ||
"scatter_one_dim_indexTwo_value", | ||
1, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
1, | ||
), | ||
] | ||
) | ||
def test_scatter_index_input(self, _, dim, index, value): | ||
class TestModule(torch.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, input, index): | ||
return torch.ops.aten.scatter.value(input, dim, index, value) | ||
|
||
input = torch.zeros(3, 5, dtype=torch.int32) | ||
inputs = [input, index] | ||
self.run_test(TestModule(), inputs, int32_reqd=True) | ||
|
||
|
||
class TestScatterSrcConverter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
( | ||
"scatter_zero_dim_indexOne_src", | ||
0, | ||
torch.tensor([[0, 1, 2, 0]]), | ||
torch.tensor([[1, 2, 3, 4]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_zero_dim_indexTwo_src", | ||
0, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_one_dim_indexOne_src", | ||
1, | ||
torch.tensor([[0, 1, 2, 0]]), | ||
torch.tensor([[1, 2, 3, 1]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_one_dim_indexTwo_src", | ||
1, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
torch.tensor([[1, 2, 3, 1], [5, 6, 5, 5]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_one_dim_indexOne_constant_src", | ||
1, | ||
torch.tensor([[0, 1, 2, 0]]), | ||
torch.tensor([[1, 2, 3, 4]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_one_dim_indexTwo_constant_src", | ||
1, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=torch.int32), | ||
), | ||
] | ||
) | ||
def test_scatter_index_constant(self, _, dim, index, src): | ||
class TestModule(torch.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, input): | ||
return torch.ops.aten.scatter.src(input, dim, index, src) | ||
|
||
input = torch.zeros(3, 5, dtype=torch.int32) | ||
inputs = [input] | ||
scatter = TestModule() | ||
self.run_test(TestModule(), inputs, int32_reqd=True) | ||
|
||
@parameterized.expand( | ||
[ | ||
( | ||
"scatter_zero_dim_indexOne_constant_src", | ||
0, | ||
torch.tensor([[0, 1, 2, 0]]), | ||
torch.tensor([[1, 2, 3, 4]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_zero_dim_indexTwo_constant_src", | ||
0, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_one_dim_indexOne_constant_src", | ||
1, | ||
torch.tensor([[0, 1, 2, 0]]), | ||
torch.tensor([[1, 2, 3, 1]], dtype=torch.int32), | ||
), | ||
( | ||
"scatter_one_dim_indexTwo_constant_src", | ||
1, | ||
torch.tensor([[0, 1, 2, 0], [1, 2, 1, 1]]), | ||
torch.tensor([[1, 2, 3, 1], [5, 6, 5, 5]], dtype=torch.int32), | ||
), | ||
] | ||
) | ||
def test_scatter_index_input(self, _, dim, index, src): | ||
class TestModule(torch.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def forward(self, input, index): | ||
return torch.ops.aten.scatter.src(input, dim, index, src) | ||
|
||
input = torch.zeros(3, 5, dtype=torch.int32) | ||
inputs = [input, index] | ||
self.run_test(TestModule(), inputs, int32_reqd=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |
Oops, something went wrong.
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.
If the index must be
trt.int32
and no other types (trt.float32
,trt.float16
, etc.) are acceptable, then it is fine to remove theif
statement, as thecast_trt_tensor
function will not insert a cast if the type is alreadyint32
, as here:TensorRT/py/torch_tensorrt/dynamo/conversion/converter_utils.py
Line 147 in 4b993f8
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.
It would be required for
trt.int64
cases, which will be the case in our test cases since torch requires int64 inputs.