From 41d04a89959d9197e167302fcae375f947848a88 Mon Sep 17 00:00:00 2001 From: Suraj Sudhir Date: Wed, 12 Jun 2024 09:23:42 -0700 Subject: [PATCH] [onnx] Resize supports default-valued attributes (#3450) Handles onnx exporters emitting default-valued attributes. Signed-off-by: Suraj Sudhir --- .../TorchOnnxToTorch/DefaultDomainQtoZ.cpp | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp b/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp index 381063096776..6b003b1259c0 100644 --- a/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp +++ b/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp @@ -2771,28 +2771,15 @@ void mlir::torch::onnx_c::populateDefaultDomainQtoZ( Torch::ValueTensorType resultType; llvm::SmallVector operands; std::string mode, nearest_mode, coordTfMode; + int64_t antialias, exclude_outside; + float extrapolation_value; Value noneVal = rewriter.create(binder.getLoc()); - if (auto attr = binder.op->getAttr("torch.onnx.antialias")) { - return rewriter.notifyMatchFailure( - binder.op, - "unimplemented: support not present for antialias attribute"); - } if (auto attr = binder.op->getAttr("torch.onnx.axes")) { return rewriter.notifyMatchFailure( binder.op, "unimplemented: support not present for axes attribute"); } - if (auto attr = binder.op->getAttr("torch.onnx.exclude_outside")) { - return rewriter.notifyMatchFailure( - binder.op, "unimplemented: support not present for " - "exclude_outside attribute"); - } - if (auto attr = binder.op->getAttr("torch.onnx.extrapolation_value")) { - return rewriter.notifyMatchFailure( - binder.op, "unimplemented: support not present for " - "extrapolation_value attribute"); - } if (auto attr = binder.op->getAttr("torch.onnx.keep_aspect_ratio_policy")) { return rewriter.notifyMatchFailure( @@ -2805,9 +2792,28 @@ void mlir::torch::onnx_c::populateDefaultDomainQtoZ( binder.customOpNameStringAttr(mode, "mode", "nearest") || binder.customOpNameStringAttr( coordTfMode, "coordinate_transformation_mode", "half_pixel") || + binder.s64IntegerAttr(antialias, "antialias", 0) || + binder.s64IntegerAttr(exclude_outside, "exclude_outside", 0) || + binder.f32FloatAttr(extrapolation_value, "extrapolation_value", + 0.0) || binder.customOpNameStringAttr(nearest_mode, "nearest_mode", "round_prefer_floor")) return failure(); + if (antialias != 0) { + return rewriter.notifyMatchFailure( + binder.op, + "unimplemented: support not present for antialias attribute"); + } + if (exclude_outside != 0) { + return rewriter.notifyMatchFailure( + binder.op, "unimplemented: support not present for " + "exclude_outside attribute"); + } + if (extrapolation_value != 0.0) { + return rewriter.notifyMatchFailure( + binder.op, "unimplemented: support not present for " + "extrapolation_value attribute"); + } if (coordTfMode == "tf_crop_and_resize") return rewriter.notifyMatchFailure( binder.op, "unimplemented: coordinate transformation mode: "