iree icon indicating copy to clipboard operation
iree copied to clipboard

iree-compile fails with `ElementsAttr does not provide iteration facilities for type 'mlir::Attribute'` on int8 models at the last op in IR.

Open vinayakdsci opened this issue 5 months ago • 1 comments

What happened?

While compiling int8 models, the generated IR gets converted to linalg and is canonicalized successfully. However, iree-compile crashes with the error

ElementsAttr does not provide iteration facilities for type 'mlir::Attribute', see attribute: dense_resource<key2> : tensor<i8>
invalid 'T' for ElementsAttr::getValues
UNREACHABLE executed at iree/third_party/llvm-project/mlir/include/mlir/IR/BuiltinAttributeInterfaces.h:306!

The crash is observed at a dense resource(which is a scalar), which is passed in as an input to the QuantizeLinear op in all cases. The IR generated with --mlir-print-ir-after-all is attached as a text file below.

mlir_dump.txt

Steps to reproduce your issue

The following input IR is a minimal reproducer for this issue.

 module {
  func.func @test_elements_failure(%arg0: !torch.vtensor<[1,21,28,28],f32>) -> !torch.vtensor<[1,21,224,224],si8> attributes {torch.onnx_meta.ir_version = 7 : si64, torch.onnx_meta.opset_version = 19 : si64, torch.onnx_meta.producer_name = "backend-test", torch.onnx_meta.producer_version = ""} {
    %none = torch.constant.none
    %4 = torch.vtensor.literal(dense_resource<key0> : tensor<4xsi64>) : !torch.vtensor<[4],si64>
    %0 = torch.vtensor.literal(dense_resource<key1> : tensor<f32>) : !torch.vtensor<[],f32>
    %1 = torch.vtensor.literal(dense_resource<key2> : tensor<si8>) : !torch.vtensor<[],si8>
    %2 = torch.operator "onnx.Resize"(%arg0, %none, %none, %4) {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.mode = "linear", torch.onnx.nearest_mode = "floor"} : (!torch.vtensor<[1,21,28,28],f32>, !torch.none, !torch.none, !torch.vtensor<[4],si64>) -> !torch.vtensor<[1,21,224,224],f32> 
    %3 = torch.operator "onnx.QuantizeLinear"(%2, %0, %1) {torch.onnx.axis = 1 : si64} : (!torch.vtensor<[1,21,224,224],f32>, !torch.vtensor<[],f32>, !torch.vtensor<[],si8>) -> !torch.vtensor<[1,21,224,224],si8> 
    return %3 : !torch.vtensor<[1,21,224,224], si8>
  }
}

{-#
  dialect_resources: {
    builtin: {
      key0: "0x08000000173680B2655F00001500000000000000E000000000000000E000000000000000",
      key1: "0x0800000000008039",
      key2: "0x0800000000"
    }
  }
#-}

This fails with the error given above. The command used to compile this error is given below:

$ iree-compile --iree-llvmcpu-target-cpu=host --iree-llvmcpu-target-cpu-features=host --iree-input-type=onnx --iree-hal-target-backends=llvm-cpu ./test.mlir >test.vmfb

What component(s) does this issue relate to?

MLIR.

vinayakdsci avatar Sep 06 '24 13:09 vinayakdsci