Torch.empty_like supported in torch MLIR

I am getting the error below when trying to generate torch MLIR for a model. Based on the torch mlir source code, empty_like looks like a supported operator. What did I do wrong?

torch_mlir.compiler_utils.TorchMlirCompilerError: Lowering TorchScript IR → Torch Backend IR failed with the following diagnostics:
error: failed to legalize operation ‘torch.aten.empty_like’ that was explicitly marked illegal
note: see current operation: %1054 = “torch.aten.empty_like”(%1053, %9, %10, %1052, %8, %7) : (!torch.vtensor<*,f32>, !torch.int, !torch.int, !torch.Device, !torch.bool, !torch.none) → !torch.vtensor<[1,3,224,224],f32>

Can you file a bug on github?

Thanks Sean!

I just filed the bug: Failed to legalize operation 'torch.aten.empty_like' that was explicitly marked illegal · Issue #1468 · llvm/torch-mlir · GitHub .

The debug messages are copied below. Does anyone have any suggestion on how to work around this issue while the bug is being looked at?

Legalizing operation : ‘torch.aten.empty_like’(0x8e2cab0) {
%38 = “torch.aten.empty_like”(%37, %12, %13, %36, %11, %10) : (!torch.vtensor<*,f32>, !torch.int, !torch.int, !torch.Device, !torch.bool, !torch.none) → !torch.vtensor<[1,3,224,224],f32>

  • Fold {
    } → FAILURE : unable to fold

  • Pattern : ‘torch.aten.empty_like → ()’ {
    Trying to match “(anonymous namespace)::DecomposeAtenEmptyLikeOp”
    ** Insert : ‘torch.aten.size’(0x8e3e140)
    ** Insert : ‘torch.aten.empty.memory_format’(0x8e464d0)
    ** Replace : ‘torch.aten.empty_like’(0x8e2cab0)
    “(anonymous namespace)::DecomposeAtenEmptyLikeOp” result 1

    //===-------------------------------------------===//
    Legalizing operation : ‘torch.aten.size’(0x8e3e140) {
    %38 = “torch.aten.size”(%37) : (!torch.vtensor<*,f32>) → !torch.list

    • Fold {
      } → FAILURE : unable to fold

    • Pattern : ‘torch.aten.size → ()’ {
      Trying to match “(anonymous namespace)::DecomposeAtenSizeOp”
      ** Failure : Unimplemented: unranked tensor
      “(anonymous namespace)::DecomposeAtenSizeOp” result 0
      } → FAILURE : pattern failed to match
      } → FAILURE : no matched legalization pattern
      //===-------------------------------------------===//
      } → FAILURE : failed to legalize generated operation ‘torch.aten.size’(0x0000000008E3E140)
      } → FAILURE : pattern failed to match
      } → FAILURE : no matched legalization pattern
      //===-------------------------------------------===//

Just wanted to provide an update on this. It turned out the issue is caused by another unsupported custom OP in the MLIR. Once the issue with the unsupported custom OP is resolved, empty_like operator now works.