Skip to content

[TORCH] Support aten.logaddexp & aten.logaddexp2 ops via torch decomposition #4194

Open
@zahidwx

Description

@zahidwx

aten.logaddexp & aten.logaddexp2 ops are not supported in torch dialect and there is no decomposition for such ops to enable lowering to backend contract.

TORCH_VERSION_FOR_COMPARISON = 2.8.0.dev20250512
Running tests sequentially with progress status
*** RUNNING TEST: LogaddexpModule_basic ***
Compiling LogaddexpModule_basic...
Running LogaddexpModule_basic...

====================

TorchFX IR
module {
  func.func @LogaddexpModule(%arg0: !torch.vtensor<[3,4],f32>, %arg1: !torch.vtensor<[3,4],f32>) -> !torch.vtensor<[3,4],f32> {
    %0 = torch.operator "torch.aten.logaddexp"(%arg0, %arg1) : (!torch.vtensor<[3,4],f32>, !torch.vtensor<[3,4],f32>) -> !torch.vtensor<[3,4],f32> 
    return %0 : !torch.vtensor<[3,4],f32>
  }
}
loc("/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir_e2e_test/test_suite/basic.py":97:0): error: failed to legalize operation 'torch.operator' that was explicitly marked illegal
TORCH_VERSION_FOR_COMPARISON = 2.8.0.dev20250512
loc("/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir_e2e_test/test_suite/basic.py":97:0): error: failed to legalize operation 'torch.operator' that was explicitly marked illegal
FAIL - "LogaddexpModule_basic"

Unexpected outcome summary: (fx_importer)

****** Failed tests - 1 tests
    FAIL - "LogaddexpModule_basic"
        Runtime error: Traceback (most recent call last):
          File "/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir_e2e_test/framework.py", line 354, in compile_and_run_test
            trace = config.run(compiled, golden_trace)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir_e2e_test/configs/fx_importer_backend.py", line 61, in run
            self._export_run(artifact, trace)
          File "/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir_e2e_test/configs/fx_importer_backend.py", line 140, in _export_run
            module = fx.export_and_import(
                     ^^^^^^^^^^^^^^^^^^^^^
          File "/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir/fx.py", line 124, in export_and_import
            return _module_lowering(
                   ^^^^^^^^^^^^^^^^^
          File "/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir/fx.py", line 61, in _module_lowering
            run_pipeline_with_repro_report(
          File "/home/zahidw/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir/compiler_utils.py", line 127, in run_pipeline_with_repro_report
            raise TorchMlirCompilerError(trimmed_message) from None
        torch_mlir.compiler_utils.TorchMlirCompilerError: Lowering TorchFX IR -> Torch Backend IR failed with the following diagnostics:


        python exception: Failure while executing pass pipeline

        For Torch-MLIR developers, the error can be reproduced with:
        $ torch-mlir-opt -pass-pipeline='builtin.module(func.func(torch-match-quantized-custom-ops), torchdynamo-export-to-torch-backend-pipeline{backend-legal-ops=aten.adaptive_max_pool2d extra-library=})' /tmp/UnnammedModule.mlir
        Add '-mlir-print-ir-after-all -mlir-disable-threading' to get the IR dump for debugging purpose.



Summary:
    Failed: 1

Minimal repro steps:

import torch
import torch.nn as nn
from torch_mlir import fx

def run(f):
    print(f"{f.__name__}")
    print("-" * len(f.__name__))
    f()
    print()

@run
def test_logaddexp():
    class LogaddexpModule(nn.Module):
        def __init__(self):
            super().__init__()

        def forward(self, x, y):
            return torch.logaddexp(x,y)

    x = torch.randn(3, 4)
    y = torch.randn(3, 4)
    exported = fx.export_and_import(LogaddexpModule(), x, y, output_type="torch")
    print(exported)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions