-
Notifications
You must be signed in to change notification settings - Fork 365
feat: support aten.roll dynamo converter #2569
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import torch | ||
import torch.nn as nn | ||
from parameterized import parameterized | ||
from torch.testing._internal.common_utils import run_tests | ||
from torch_tensorrt import Input | ||
|
||
from .harness import DispatchTestCase | ||
|
||
|
||
class TestRollConverter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
((4,), (2,), 0), | ||
((4,), [2], [0]), | ||
((4,), [3], [0]), | ||
((4,), [-3, 2], [0, 0]), | ||
((4,), [-2], []), | ||
((4, 2), [2, 1], [0, 1]), | ||
((3, 3), [2, 1], [1, 1]), | ||
((4, 2), [2, -1], [-2, -1]), | ||
((4, 2), [4], []), | ||
((3, 4, 2), [1, 0, 2], [2, 0, -2]), | ||
((3, 4, 2), [1, -0, 2], [1, 1, 1]), | ||
( | ||
(3, 4, 2), | ||
[ | ||
5, | ||
], | ||
[], | ||
), | ||
] | ||
) | ||
def test_roll(self, shape, shifts, dims): | ||
class Roll(nn.Module): | ||
def forward(self, x): | ||
return torch.ops.aten.roll.default(x, shifts, dims) | ||
|
||
inputs = [torch.randn(shape)] | ||
self.run_test(Roll(), inputs) | ||
|
||
|
||
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.
Consider adding a case where both
shifts
anddims
are single integers, which is a supported case in the docstring. These may be casted to lists in the operator before the converter ever gets them, but it is still a valid input I believe.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.
Thanks for your review! I found the schema is:
Does this mean
shifts
anddims
should be a 1d list?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.
roll(tensor, 2, 3)
-->roll(tensor, [2], [3])
pool(3)
-->pool([3, 3])
To share additional documentation
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.
@zewenli98 see the comment here:
https://github.com/pytorch/pytorch/blob/40dbd567e04483c671f9c897171bf9d1e7162b68/torch/csrc/jit/frontend/schema_matching.cpp#L173-L180
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.
@gs-olive Thanks for the details!
Unfortunately, when testing
shifts=2, dims=0
, I got error:Then, I also tested
shifts=(2,), dims=0
, it works.It seems that pytorch requires
shifts
to be a list.According to the schema
- func: roll(Tensor self, SymInt[1] shifts, int[1] dims=[]) -> Tensor
, I guessSymInt[1]
andint[1]
may have different behaviors?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 might be so, yes, though that is strange - thanks for the update.
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.
Yes, I'm working on
adaptive_avg_pool2d(Tensor self, SymInt[2] output_size) -> Tensor
converter,output_size
expectsList[int]
as well: