nod-ai / SHARK-ModelDev

Unified compiler/runtime for interfacing with PyTorch Dynamo.
Apache License 2.0
92 stars 46 forks source link

Failed to legalize operation `onnx.AveragePool`. #816

Open vinayakdsci opened 2 weeks ago

vinayakdsci commented 2 weeks ago

The ONNX operator onnx.AveragePool fails during lowering with the error Failed to legalize operation 'onnx.AveragePool' , as reported in https://github.com/nod-ai/SHARK-Turbine/issues/812.

module {
  func.func @inception_v1 (%arg1: !torch.vtensor<[1,1024,6,6],f32>) -> !torch.vtensor<[1,1024,1,1],f32>  attributes {torch.onnx_meta.ir_version = 3 : si64, torch.onnx_meta.opset_version = 17 : si64, torch.onnx_meta.producer_name = "onnx-caffe2", torch.onnx_meta.producer_version = ""} {
    %256 = torch.operator "onnx.AveragePool"(%arg1) {torch.onnx.kernel_shape = [7 : si64, 7 : si64], torch.onnx.pads = [0 : si64, 0 : si64, 1 : si64, 1 : si64], torch.onnx.strides = [1 : si64, 1 : si64]} : (!torch.vtensor<[1,1024,6,6],f32>) -> !torch.vtensor<[1,1024,1,1],f32> 
    return %256 : !torch.vtensor<[1,1024,1,1],f32>
  }
}

commands:

torch-mlir-opt -split-input-file -verify-diagnostics -convert-torch-onnx-to-torch --mlir-print-ir-after-all t1.mlir

error:

within split at t1.mlir:1 offset :3:12: error: unexpected error: failed to legalize operation 'torch.operator' that was explicitly marked illegal
    %256 = torch.operator "onnx.AveragePool"(%arg1) {torch.onnx.kernel_shape = [7 : si64, 7 : si64], torch.onnx.pads = [0 : si64, 0 : si64, 1 : si64, 1 : si64], torch.onnx.strides = [1 : si64, 1 : si64]} : (!torch.vtensor<[1,1024,6,6],f32>) -> !torch.vtensor<[1,1024,1,1],f32> 
           ^
kumardeepakamd commented 2 weeks ago

@vivekkhandelwal1 worked on AveragePool (https://github.com/llvm/torch-mlir/commit/6844c847025a81458a391ffba9a36c9474c392e6)