Skip to content

Commit 9450063

Browse files
authored
DecomposeAtenAminAmaxOp negative axis fix (#4556)
Fixes #4553 Fixed support for negative axis in DecomposeAtenAminAmaxOp
1 parent 418ff49 commit 9450063

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

lib/Dialect/Torch/Transforms/DecomposeComplexOps.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,12 +2824,13 @@ class DecomposeAtenAminAmaxOp : public OpRewritePattern<OpTy> {
28242824
dims = llvm::to_vector(llvm::seq<int64_t>(0, inputTy.getSizes().size()));
28252825
}
28262826

2827+
int64_t inputRank = inputTy.getSizes().size();
2828+
llvm::for_each(dims, [&](int64_t &d) { d = toPositiveDim(d, inputRank); });
2829+
28272830
// For every dimension included in `dim` of the op, iterated over in
28282831
// reverse order, we create a call to aten.max.dim.
28292832
std::sort(dims.rbegin(), dims.rend());
28302833
for (int64_t dimInt : dims) {
2831-
int64_t inputRank = inputTy.getSizes().size();
2832-
dimInt = toPositiveDim(dimInt, inputRank);
28332834
if (!isValidDim(dimInt, inputRank))
28342835
return rewriter.notifyMatchFailure(op, "dim is statically invalid");
28352836
Value dim = Torch::ConstantIntOp::create(

projects/pt1/python/torch_mlir_e2e_test/test_suite/reduction.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,29 @@ def ReduceAmaxOutOfOrderDim_basic(module, tu: TestUtils):
15261526
# ==============================================================================
15271527

15281528

1529+
class ReduceAmaxOutOfOrderWithNegDim(torch.nn.Module):
1530+
def __init__(self):
1531+
super().__init__()
1532+
1533+
@export
1534+
@annotate_args(
1535+
[
1536+
None,
1537+
([-1, -1, -1, -1], torch.float32, True),
1538+
]
1539+
)
1540+
def forward(self, a):
1541+
return torch.ops.aten.amax(a, (2, 1, -1))
1542+
1543+
1544+
@register_test_case(module_factory=lambda: ReduceAmaxOutOfOrderWithNegDim())
1545+
def ReduceAmaxOutOfOrderWithNegDim_basic(module, tu: TestUtils):
1546+
module.forward(tu.rand(3, 4, 5, 6, high=100))
1547+
1548+
1549+
# ==============================================================================
1550+
1551+
15291552
class ReduceAmaxKeepDim(torch.nn.Module):
15301553
def __init__(self):
15311554
super().__init__()

0 commit comments

Comments
 (0)