Skip to content

Commit 4ec8b9f

Browse files
afalkenberg1root
andauthored
[onnx] add support for onnx.LessOrEqual (#2639)
Added the less or equal operation to OnnxToTorch. onnx.LessOrEqual --------- Co-authored-by: root <[email protected]>
1 parent 65f517b commit 4ec8b9f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/Conversion/TorchOnnxToTorch/DefaultDomainGtoP.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,17 @@ void mlir::torch::onnx_c::populateDefaultDomainGtoP(
3939
binder.op, resultType, lhs, rhs);
4040
return success();
4141
});
42-
}
42+
patterns.onOp("LessOrEqual", 1,
43+
[](OpBinder binder, ConversionPatternRewriter &rewriter) {
44+
Torch::ValueTensorType resultType;
45+
Value lhs, rhs;
46+
if (binder.tensorOperands(lhs, rhs) ||
47+
binder.tensorResultType(resultType)) {
48+
return failure();
49+
}
50+
rewriter.replaceOpWithNewOp<Torch::AtenLeTensorOp>(
51+
binder.op, resultType, lhs, rhs);
52+
return success();
53+
});
54+
55+
}

test/Conversion/TorchOnnxToTorch/simple_ops_g_to_p.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ func.func @test_matmul_4d(%arg0: !torch.vtensor<[1,2,3,4],f32>, %arg1: !torch.vt
2323
// CHECK: torch.aten.matmul %arg0, %arg1 : !torch.vtensor<[1,2,3,4],f32>, !torch.vtensor<[1,2,4,3],f32> -> !torch.vtensor<[1,2,3,3],f32>
2424
%0 = torch.operator "onnx.MatMul"(%arg0, %arg1) : (!torch.vtensor<[1,2,3,4],f32>, !torch.vtensor<[1,2,4,3],f32>) -> !torch.vtensor<[1,2,3,3],f32>
2525
return %0 : !torch.vtensor<[1,2,3,3],f32>
26+
}
27+
28+
// CHECK-LABEL: func.func @test_less_or_equal
29+
func.func @test_less_or_equal(%arg0: !torch.vtensor<[3,4,5],f32>, %arg1: !torch.vtensor<[3,4,5],f32>) -> !torch.vtensor<[3,4,5],i1> attributes {torch.onnx_meta.ir_version = 7 : si64, torch.onnx_meta.opset_version = 13 : si64, torch.onnx_meta.producer_name = "backend-test", torch.onnx_meta.producer_version = ""} {
30+
// CHECK-SAME: %[[ARG0:[a-zA-Z0-9]+]]: !torch.vtensor<[3,4,5],f32>
31+
// CHECK-SAME: %[[ARG1:[a-zA-Z0-9]+]]: !torch.vtensor<[3,4,5],f32>
32+
// CHECK: torch.aten.le.Tensor %[[ARG0]], %[[ARG1]] : !torch.vtensor<[3,4,5],f32>, !torch.vtensor<[3,4,5],f32> -> !torch.vtensor<[3,4,5],i1>
33+
%0 = torch.operator "onnx.LessOrEqual"(%arg0, %arg1) : (!torch.vtensor<[3,4,5],f32>, !torch.vtensor<[3,4,5],f32>) -> !torch.vtensor<[3,4,5],i1>
34+
return %0 : !torch.vtensor<[3,4,5],i1>
2635
}

0 commit comments

Comments
 (0)