From 5119232f91b7bf2351f1562e980af609bf440d67 Mon Sep 17 00:00:00 2001 From: Ryutaro Okada <1015ryu88@gmail.com> Date: Mon, 13 Oct 2025 17:37:36 +0900 Subject: [PATCH 1/2] Add 1D-empty tensor support for AtenCatOp::getCanonicalizationPatterns --- lib/Dialect/Torch/IR/TorchOps.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Dialect/Torch/IR/TorchOps.cpp b/lib/Dialect/Torch/IR/TorchOps.cpp index a4888a218fae..cf80829bf1a5 100644 --- a/lib/Dialect/Torch/IR/TorchOps.cpp +++ b/lib/Dialect/Torch/IR/TorchOps.cpp @@ -4147,6 +4147,10 @@ void AtenCatOp::getCanonicalizationPatterns(RewritePatternSet &patterns, if (!operandTy || !operandTy.hasSizes()) return failure(); int64_t adim = dim < 0 ? dim + operandTy.getSizes().size() : dim; + bool is1DEmptyTensor = + operandTy.getSizes().size() == 1 && operandTy.getSizes()[0] == 0; + if (is1DEmptyTensor) + continue; if (operandTy.getSizes()[adim] != 0) filtered.push_back(operand); } From 276571a2e7328694a71154701f5a45b5fb8f3c15 Mon Sep 17 00:00:00 2001 From: Ryutaro Okada <1015ryu88@gmail.com> Date: Mon, 13 Oct 2025 17:39:35 +0900 Subject: [PATCH 2/2] Add test for aten.cat with 1-D empty tensor --- test/Dialect/Torch/canonicalize.mlir | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/Dialect/Torch/canonicalize.mlir b/test/Dialect/Torch/canonicalize.mlir index 48092b71a875..57bdc3db6555 100644 --- a/test/Dialect/Torch/canonicalize.mlir +++ b/test/Dialect/Torch/canonicalize.mlir @@ -3242,6 +3242,16 @@ func.func @aten_cat_zero(%arg0 : !torch.vtensor<[4,5,6],f32>, %arg1 : !torch.vte // ----- +// CHECK-LABEL: @aten_cat_empty +func.func @aten_cat_empty(%arg0 : !torch.vtensor<[4,5,6],f32>, %arg1 : !torch.vtensor<[0],f32>) -> !torch.vtensor<[4,5,6],f32> { + // CHECK: return %arg0 : !torch.vtensor<[4,5,6],f32> + %list = torch.prim.ListConstruct %arg0, %arg1 : (!torch.vtensor<[4,5,6],f32>, !torch.vtensor<[0],f32>) -> !torch.list + %dim = torch.constant.int -2 + %0 = torch.aten.cat %list, %dim : !torch.list, !torch.int -> !torch.vtensor<[4,5,6],f32> + return %0 : !torch.vtensor<[4,5,6],f32> +} +// ----- + // CHECK-LABEL: @aten_tensor_scalar_lt func.func @aten_tensor_scalar_lt() -> (!torch.vtensor<[4],i1>, !torch.vtensor<[4],i1>) { // CHECK: %[[CST:.+]] = torch.vtensor.literal(dense : tensor<4xi1>) : !torch.vtensor<[4],i1>