Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to legalize operation 'torch.operator' that was explicitly marked illegal : onnx.Resize #915

Open
pravg-amd opened this issue Feb 10, 2025 · 2 comments
Assignees

Comments

@pravg-amd
Copy link

For the below IR,

module {
  func.func @resize(%arg0: !torch.vtensor<[1,3,224,224],f32>) -> !torch.vtensor<[1,3,800,800],f32> attributes {torch.onnx_meta.ir_version = 8 : si64, torch.onnx_meta.opset_version = 21 : si64, torch.onnx_meta.opset_versions = {ai.onnx.ml = 5 : si64, ai.onnx.preview.training = 1 : si64, ai.onnx.training = 1 : si64, com.microsoft = 1 : si64, com.microsoft.experimental = 1 : si64, com.microsoft.nchwc = 1 : si64, org.pytorch.aten = 1 : si64}, torch.onnx_meta.producer_name = "pytorch", torch.onnx_meta.producer_version = "2.1.0"} {
    %none = torch.constant.none
    %cst = torch.operator "onnx.Constant"() {torch.onnx.value = dense_resource<__transform_Concat_1_output_0> : tensor<4xsi64>} : () -> !torch.vtensor<[4],si64>
    %0 = torch.operator "onnx.Resize"(%arg0, %none, %none, %cst) {torch.onnx.antialias = 0 : si64, torch.onnx.coordinate_transformation_mode = "half_pixel", torch.onnx.cubic_coeff_a = -7.500000e-01 : f32, torch.onnx.exclude_outside = 0 : si64, torch.onnx.extrapolation_value = 0.000000e+00 : f32, torch.onnx.keep_aspect_ratio_policy = "stretch", torch.onnx.mode = "linear", torch.onnx.nearest_mode = "floor"} : (!torch.vtensor<[1,3,224,224],f32>, !torch.none, !torch.none, !torch.vtensor<[4],si64>) -> !torch.vtensor<[1,3,800,800],f32>
    return %0 : !torch.vtensor<[1,3,800,800],f32>
  }
}

{-#
  dialect_resources: {
    builtin: {
      __transform_Concat_1_output_0: "0x080000000100000000000000030000000000000020030000000000002003000000000000"
    }
  }
#-}

Getting error as

model_torch_onnx.mlir:5:10: error: failed to legalize operation 'torch.operator' that was explicitly marked illegal
    %0 = torch.operator "onnx.Resize"(%arg0, %none, %none, %cst) {torch.onnx.antialias = 0 : si64, torch.onnx.coordinate_transformation_mode = "half_pixel", torch.onnx.cubic_coeff_a = -7.500000e-01 : f32, torch.onnx.exclude_outside = 0 : si64, torch.onnx.extrapolation_value = 0.000000e+00 : f32, torch.onnx.keep_aspect_ratio_policy = "stretch", torch.onnx.mode = "linear", torch.onnx.nearest_mode = "floor"} : (!torch.vtensor<[1,3,224,224],f32>, !torch.none, !torch.none, !torch.vtensor<[4],si64>) -> !torch.vtensor<[1,3,800,800],f32>
         ^

Command

 iree-compile --iree-hal-target-backends=llvm-cpu --iree-llvmcpu-target-cpu=host -o test.vmfb model_torch_onnx.mlir 

Models Impacted:

fcos_resnet50_fpn_Opset18_torchvision
fasterrcnn_mobilenet_v3_large_320_fpn_Opset18_torchvision
fasterrcnn_mobilenet_v3_large_fpn_Opset18_torchvision
fasterrcnn_resnet50_fpn_v2_Opset18_torchvision
maskrcnn_resnet50_fpn_v2_Opset18_torchvision
retinanet_resnet50_fpn_v2_Opset18_torchvision

@zjgarvey
Copy link
Collaborator

The keep aspect ratio policy attribute is mis-handled. The value "stretch" is default, so we shouldn't be erroring out.

The code in https://github.com/llvm/torch-mlir/blob/a265d283357f572c5437f9217ea85fa9770d374c/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp#L2714-L2719
should be merged into the subsequent if statement as:

std::string keepAspectRatioPolicy;

if (... ||
     ... ||
     binder.customOpNameStringAttr(keepAspectRatioPolicy, "keep_aspect_ratio_policy", "stretch") ||
     ...)
         return failure();

// near other similar checks:

if (keepAspectRatioPolicy != "stretch")
     return rewriter.notifyMatchFailure(binder.op, "unimplemented: non-default keep_aspect_ratio_policy attribute");

@pravg-amd
Copy link
Author

Review llvm/torch-mlir#4044

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants