|
| 1 | +import torch |
| 2 | +import torch.nn as nn |
| 3 | +from harness import DispatchTestCase |
| 4 | +from parameterized import parameterized |
| 5 | +from torch.testing._internal.common_utils import run_tests |
| 6 | + |
| 7 | + |
| 8 | +class TestAmaxConverter(DispatchTestCase): |
| 9 | + @parameterized.expand( |
| 10 | + [ |
| 11 | + ((3, 2, 4), 1, True), |
| 12 | + ((2, 3, 4, 5), 3, True), |
| 13 | + ((2, 3, 4, 5), 2, False), |
| 14 | + ((6, 7, 5, 4, 5), 4, False), |
| 15 | + ] |
| 16 | + ) |
| 17 | + def test_amax_dim_int_default(self, input_shape, dim, keep_dims): |
| 18 | + class Amax(nn.Module): |
| 19 | + def forward(self, x): |
| 20 | + return torch.amax(x, dim=dim, keepdim=keep_dims) |
| 21 | + |
| 22 | + inputs = [torch.randn(*input_shape)] |
| 23 | + self.run_test( |
| 24 | + Amax(), |
| 25 | + inputs, |
| 26 | + expected_ops={torch.ops.aten.amax.default}, |
| 27 | + ) |
| 28 | + |
| 29 | + @parameterized.expand( |
| 30 | + [ |
| 31 | + ((3, 2, 4), [1], True), |
| 32 | + ((2, 1, 4, 5), [0, 3], True), |
| 33 | + ((2, 3, 4, 5), [0, 1, 2, 3], False), |
| 34 | + ((6, 7, 5, 4, 5), [1, 3, 4], False), |
| 35 | + ] |
| 36 | + ) |
| 37 | + def test_amax_dim_tuple_default(self, input_shape, dim, keep_dims): |
| 38 | + class Amax(nn.Module): |
| 39 | + def forward(self, x): |
| 40 | + return torch.amax(x, dim=dim, keepdim=keep_dims) |
| 41 | + |
| 42 | + inputs = [torch.randn(*input_shape)] |
| 43 | + self.run_test( |
| 44 | + Amax(), |
| 45 | + inputs, |
| 46 | + expected_ops={torch.ops.aten.amax.default}, |
| 47 | + ) |
| 48 | + |
| 49 | + @parameterized.expand( |
| 50 | + [ |
| 51 | + ((3, 2, 4), 1, True, torch.int, 0, 5), |
| 52 | + ((2, 3, 4, 5), 3, True, torch.int, -10, 10), |
| 53 | + ((2, 3, 4, 5), 2, False, torch.int32, -5, 0), |
| 54 | + ((6, 7, 5, 4, 5), 4, False, torch.int32, -5, 5), |
| 55 | + ] |
| 56 | + ) |
| 57 | + def test_amax_dim_int_int(self, input_shape, dim, keep_dims, dtype, low, high): |
| 58 | + class Amax(nn.Module): |
| 59 | + def forward(self, x): |
| 60 | + return torch.amax(x, dim=dim, keepdim=keep_dims) |
| 61 | + |
| 62 | + inputs = [torch.randint(low, high, input_shape, dtype=dtype)] |
| 63 | + self.run_test( |
| 64 | + Amax(), |
| 65 | + inputs, |
| 66 | + expected_ops={torch.ops.aten.amax.default}, |
| 67 | + check_dtype=False, |
| 68 | + ) |
| 69 | + |
| 70 | + @parameterized.expand( |
| 71 | + [ |
| 72 | + ((3, 2, 4), [1], True, torch.int, 0, 5), |
| 73 | + ((2, 1, 4, 5), [0, 3], True, torch.int, -10, 10), |
| 74 | + ((2, 3, 4, 5), [0, 1, 2, 3], False, torch.int32, -5, 0), |
| 75 | + ((6, 7, 5, 4, 5), [1, 3, 4], False, torch.int32, -5, 5), |
| 76 | + ] |
| 77 | + ) |
| 78 | + def test_amax_dim_tuple_int(self, input_shape, dim, keep_dims, dtype, low, high): |
| 79 | + class Amax(nn.Module): |
| 80 | + def forward(self, x): |
| 81 | + return torch.amax(x, dim=dim, keepdim=keep_dims) |
| 82 | + |
| 83 | + inputs = [torch.randint(low, high, input_shape, dtype=dtype)] |
| 84 | + self.run_test( |
| 85 | + Amax(), |
| 86 | + inputs, |
| 87 | + expected_ops={torch.ops.aten.amax.default}, |
| 88 | + check_dtype=False, |
| 89 | + ) |
| 90 | + |
| 91 | + |
| 92 | +if __name__ == "__main__": |
| 93 | + run_tests() |
0 commit comments