-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add aten.topk implementation (#2841)
- Loading branch information
1 parent
2b4d699
commit 92575a0
Showing
4 changed files
with
126 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ def forward(self, x): | |
self.run_test( | ||
Sort(), | ||
inputs, | ||
enable_passes=True, | ||
) | ||
|
||
|
||
|
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,38 @@ | ||
import torch | ||
import torch.nn as nn | ||
from parameterized import parameterized | ||
from torch.testing._internal.common_utils import run_tests | ||
|
||
from .harness import DispatchTestCase | ||
|
||
|
||
class TestSortConverter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
((3, 2, 4), 1, 0, True, True), | ||
((3, 3, 4), 2, -1, True, True), | ||
((3, 3, 4), 2, -1, False, True), | ||
((3850, 2), 3840, 0, False, True), | ||
((3, 3), 2, 0, True, True), | ||
((3, 3), 2, 1, True, False), | ||
((5, 3), 2, 1, False, False), | ||
((6, 4), 2, 1, False, False), | ||
# default dim:-1 largest:True, sorted:True | ||
((3, 5, 12), 3), | ||
] | ||
) | ||
def test_topk(self, input_shape, k, dim=-1, largest=True, sorted=True): | ||
class Topk(nn.Module): | ||
def forward(self, x): | ||
return torch.ops.aten.topk.default(x, k, dim, largest, sorted) | ||
|
||
inputs = [torch.randn(*input_shape)] | ||
self.run_test( | ||
Topk(), | ||
inputs, | ||
enable_passes=True, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |
@narendasan If TRT doesn't have
sorted
flag, the outputs of TRT and pytorch might be different. e.g.,Is the current implementation acceptable?