nod-ai / SHARK-ModelDev

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

'tensor.dim' op unexpected during shape cleanup; dynamic dimensions must have been resolved prior to leaving the flow dialect #876

Open pdhirajkumarprasad opened 3 weeks ago

pdhirajkumarprasad commented 3 weeks ago

for the given IR

module {
  func.func @"torch-jit-export"(%arg0: !torch.vtensor<[?,6],f32>) -> (!torch.vtensor<[?,1],si64> ) attributes {torch.onnx_meta.ir_version = 6 : si64, torch.onnx_meta.opset_version = 21 : si64, torch.onnx_meta.producer_name = "pytorch", torch.onnx_meta.producer_version = "1.7"} {
    %1 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<0> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %2 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<4> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %3 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<1> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %4 = torch.operator "onnx.Slice"(%arg0, %1, %2, %3) : (!torch.vtensor<[?,6],f32>, !torch.vtensor<[1],si64>, !torch.vtensor<[1],si64>, !torch.vtensor<[1],si64>) -> !torch.vtensor<[?,4],f32> 
    %5 = torch.operator "onnx.Softmax"(%4) {torch.onnx.axis = -1 : si64} : (!torch.vtensor<[?,4],f32>) -> !torch.vtensor<[?,4],f32> 
    %6 = torch.operator "onnx.Log"(%5) : (!torch.vtensor<[?,4],f32>) -> !torch.vtensor<[?,4],f32> 
    %7 = torch.operator "onnx.Multinomial"(%6) {torch.onnx.dtype = 7 : si64, torch.onnx.sample_size = 1 : si64} : (!torch.vtensor<[?,4],f32>) -> !torch.vtensor<[?,1],si64> 
    return %7 : !torch.vtensor<[?,1],si64>
  }
}

getting error as

model.torch_onnx.mlir:9:10: error: 'tensor.dim' op unexpected during shape cleanup; dynamic dimensions must have been resolved prior to leaving the flow dialect
    %7 = torch.operator "onnx.Multinomial"(%6) {torch.onnx.dtype = 7 : si64, torch.onnx.sample_size = 1 : si64} : (!torch.vtensor<[?,4],f32>) -> !torch.vtensor<[?,1],si64> 
         ^

command : iree-compile --iree-hal-target-backends=llvm-cpu -o abc.vmfb model.torch_onnx.mlir --iree-llvmcpu-target-cpu=host