Skip to content

Commit f18bd27

Browse files
authored
[Torch] Lower AtenLogsumexpOp via exp/sum/log decomposition (#4606)
Closes #4578 This PR fixes AtenLogsumexpOp lowering in the Torch-to-Linalg path, resolving the legalization failure in the linalg-on-tensors backend pipeline. Updates TorchToLinalg reduction handling for logsumexp. Adds a regression test to cover conversion behavior and full backend pipeline execution.
1 parent 9450063 commit f18bd27

3 files changed

Lines changed: 120 additions & 0 deletions

File tree

projects/pt1/e2e_testing/xfail_sets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,6 +3047,8 @@
30473047
"ReduceL1NormComplexModule_basic",
30483048
"ReduceL2NormComplexModule_basic",
30493049
"ReduceL3NormKeepDimComplexModule_basic",
3050+
"ReduceLogSumExpDimIntListBoolModule_basic",
3051+
"ReduceLogSumExpDimIntListIntModule_basic",
30503052
"ReflectionPad3dModule_basic",
30513053
"ReflectionPad3dModuleFront_basic",
30523054
"ReflectionPad3dModuleBack_basic",

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

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,123 @@ def ReduceSumDimIntListKeepDimIntModule_basic(module, tu: TestUtils):
858858
# ==============================================================================
859859

860860

861+
class ReduceLogSumExpDimIntListFloatModule(torch.nn.Module):
862+
def __init__(self):
863+
super().__init__()
864+
865+
@export
866+
@annotate_args(
867+
[
868+
None,
869+
([-1, -1, -1], torch.float32, True),
870+
]
871+
)
872+
def forward(self, a):
873+
return torch.ops.aten.logsumexp(a, [0, 1], False)
874+
875+
876+
@register_test_case(module_factory=lambda: ReduceLogSumExpDimIntListFloatModule())
877+
def ReduceLogSumExpDimIntListFloatModule_basic(module, tu: TestUtils):
878+
module.forward(tu.rand(3, 4, 5))
879+
880+
881+
# ==============================================================================
882+
883+
884+
class ReduceLogSumExpDimIntListEmptyDimKeepDimModule(torch.nn.Module):
885+
def __init__(self):
886+
super().__init__()
887+
888+
@export
889+
@annotate_args(
890+
[
891+
None,
892+
([-1, -1, -1], torch.float32, True),
893+
]
894+
)
895+
def forward(self, a):
896+
return torch.ops.aten.logsumexp(a, [], True)
897+
898+
899+
@register_test_case(
900+
module_factory=lambda: ReduceLogSumExpDimIntListEmptyDimKeepDimModule()
901+
)
902+
def ReduceLogSumExpDimIntListEmptyDimKeepDimModule_basic(module, tu: TestUtils):
903+
module.forward(tu.rand(3, 4, 5))
904+
905+
906+
# ==============================================================================
907+
908+
909+
class ReduceLogSumExpDimIntListNegativeDimModule(torch.nn.Module):
910+
def __init__(self):
911+
super().__init__()
912+
913+
@export
914+
@annotate_args(
915+
[
916+
None,
917+
([-1, -1, -1], torch.float32, True),
918+
]
919+
)
920+
def forward(self, a):
921+
return torch.ops.aten.logsumexp(a, [-1], True)
922+
923+
924+
@register_test_case(module_factory=lambda: ReduceLogSumExpDimIntListNegativeDimModule())
925+
def ReduceLogSumExpDimIntListNegativeDimModule_basic(module, tu: TestUtils):
926+
module.forward(tu.rand(3, 4, 5))
927+
928+
929+
# ==============================================================================
930+
931+
932+
class ReduceLogSumExpDimIntListIntModule(torch.nn.Module):
933+
def __init__(self):
934+
super().__init__()
935+
936+
@export
937+
@annotate_args(
938+
[
939+
None,
940+
([-1, -1, -1], torch.int64, True),
941+
]
942+
)
943+
def forward(self, a):
944+
return torch.ops.aten.logsumexp(a, [-1], False)
945+
946+
947+
@register_test_case(module_factory=lambda: ReduceLogSumExpDimIntListIntModule())
948+
def ReduceLogSumExpDimIntListIntModule_basic(module, tu: TestUtils):
949+
module.forward(tu.randint(3, 4, 5, low=0, high=100))
950+
951+
952+
# ==============================================================================
953+
954+
955+
class ReduceLogSumExpDimIntListBoolModule(torch.nn.Module):
956+
def __init__(self):
957+
super().__init__()
958+
959+
@export
960+
@annotate_args(
961+
[
962+
None,
963+
([-1, -1, -1], torch.bool, True),
964+
]
965+
)
966+
def forward(self, a):
967+
return torch.ops.aten.logsumexp(a, [-1], False)
968+
969+
970+
@register_test_case(module_factory=lambda: ReduceLogSumExpDimIntListBoolModule())
971+
def ReduceLogSumExpDimIntListBoolModule_basic(module, tu: TestUtils):
972+
module.forward(tu.randint(3, 4, 5, high=2).to(torch.bool))
973+
974+
975+
# ==============================================================================
976+
977+
861978
class ReduceProdDimIntFloatModule(torch.nn.Module):
862979
def __init__(self):
863980
super().__init__()

python/torch_mlir/extras/fx_decomp_util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
torch.ops.aten.grid_sampler_2d,
2222
torch.ops.aten._adaptive_avg_pool2d,
2323
torch.ops.aten.full,
24+
torch.ops.aten.logsumexp,
2425
torch.ops.aten._log_softmax,
2526
torch.ops.aten._to_copy,
2627
torch.ops.aten.diag,

0 commit comments

Comments
 (0)