-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support cumsum dynamo converter (#2403)
- Loading branch information
Showing
3 changed files
with
139 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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 TestCumsumConverter(DispatchTestCase): | ||
@parameterized.expand( | ||
[ | ||
((1,), 0), | ||
((2,), 0), | ||
((3,), -1), | ||
] | ||
) | ||
def test_cumsum_1D(self, shape, dim): | ||
class Cumsum(nn.Module): | ||
def forward(self, x): | ||
return torch.ops.aten.cumsum.default(x, dim) | ||
|
||
inputs = [torch.randn(shape)] | ||
self.run_test( | ||
Cumsum(), | ||
inputs, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
((3, 1), 0), | ||
((3, 1), 1), | ||
((2, 3), -1), | ||
((2, 3), -2), | ||
] | ||
) | ||
def test_cumsum_2D(self, shape, dims): | ||
class Cumsum(nn.Module): | ||
def forward(self, x): | ||
return torch.ops.aten.cumsum.default(x, dims) | ||
|
||
inputs = [torch.randn(shape)] | ||
self.run_test( | ||
Cumsum(), | ||
inputs, | ||
) | ||
|
||
@parameterized.expand( | ||
[ | ||
((4, 2, 3), 0), | ||
((4, 2, 3), 1), | ||
((1, 2, 3), 2), | ||
((1, 2, 3), -1), | ||
((1, 2, 3), -2), | ||
] | ||
) | ||
def test_cumsum_3D(self, shape, dims): | ||
class Cumsum(nn.Module): | ||
def forward(self, x): | ||
return torch.ops.aten.cumsum.default(x, dims) | ||
|
||
inputs = [torch.randn(shape)] | ||
self.run_test( | ||
Cumsum(), | ||
inputs, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |