iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.86k stars 622 forks source link

Assertion `newMaterialization.getType() == outputType && "materialization callback produced value of incorrect type"' failed #18927

Open pdhirajkumarprasad opened 4 weeks ago

pdhirajkumarprasad commented 4 weeks ago

What happened?

For the given IR

module {
  func.func @torch_jit(%arg0: !torch.vtensor<[1,3,224,224],f32>, %arg1: !torch.vtensor<[4],si64>, %arg2: !torch.vtensor<[8],si64>, %arg3: !torch.vtensor<[?,?,?,?],f32>, %arg4: !torch.vtensor<[1],si64>, %arg5: !torch.vtensor<[?],si64>) -> !torch.vtensor<[?,?,?,?],f32>  attributes {torch.onnx_meta.ir_version = 7 : si64, torch.onnx_meta.opset_version = 21 : si64, torch.onnx_meta.producer_name = "pytorch", torch.onnx_meta.producer_version = "1.12.1"} {
    %none = torch.constant.none
    %1 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<0> : tensor<si64>} : () -> !torch.vtensor<[],si64> 
    %2 = torch.operator "onnx.Sub"(%1, %arg4) : (!torch.vtensor<[],si64>, !torch.vtensor<[1],si64>) -> !torch.vtensor<[1],si64> 
    %3 = torch.operator "onnx.ConstantOfShape"(%2) {torch.onnx.value = dense<0> : tensor<1xsi64>} : (!torch.vtensor<[1],si64>) -> !torch.vtensor<[?],si64> 
    %4 = torch.operator "onnx.Concat"(%arg1, %3) {torch.onnx.axis = 0 : si64} : (!torch.vtensor<[4],si64>, !torch.vtensor<[?],si64>) -> !torch.vtensor<[?],si64> 
    %5 = torch.operator "onnx.Constant"() {torch.onnx.value = dense_resource<__22> : tensor<2xsi64>} : () -> !torch.vtensor<[2],si64> 
    %6 = torch.operator "onnx.Reshape"(%4, %5) : (!torch.vtensor<[?],si64>, !torch.vtensor<[2],si64>) -> !torch.vtensor<[?,2],si64> 
    %7 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<0> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %8 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<-1> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %9 = torch.operator "onnx.Constant"() {torch.onnx.value = dense_resource<__25> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %10 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<-1> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %11 = torch.operator "onnx.Slice"(%6, %8, %9, %7, %10) : (!torch.vtensor<[?,2],si64>, !torch.vtensor<[1],si64>, !torch.vtensor<[1],si64>, !torch.vtensor<[1],si64>, !torch.vtensor<[1],si64>) -> !torch.vtensor<[?,2],si64> 
    %12 = torch.operator "onnx.Transpose"(%11) {torch.onnx.perm = [1 : si64, 0 : si64]} : (!torch.vtensor<[?,2],si64>) -> !torch.vtensor<[2,?],si64> 
    %13 = torch.operator "onnx.Constant"() {torch.onnx.value = dense<-1> : tensor<1xsi64>} : () -> !torch.vtensor<[1],si64> 
    %14 = torch.operator "onnx.Reshape"(%12, %13) : (!torch.vtensor<[2,?],si64>, !torch.vtensor<[1],si64>) -> !torch.vtensor<[?],si64> 
    %15 = torch.operator "onnx.Cast"(%14) {torch.onnx.to = 7 : si64} : (!torch.vtensor<[?],si64>) -> !torch.vtensor<[?],si64> 
    %16 = torch.operator "onnx.Pad"(%arg3, %15, %none) {torch.onnx.mode = "constant"} : (!torch.vtensor<[?,?,?,?],f32>, !torch.vtensor<[?],si64>, !torch.none) -> !torch.vtensor<[?,?,?,?],f32> 
    return %16 : !torch.vtensor<[?,?,?,?],f32>
  }
}

{-#
  dialect_resources: {
    builtin: {
      __22: "0x08000000FFFFFFFFFFFFFFFF0200000000000000",
      __25: "0x080000000100000000000080"
    }
  }
#-}

seeing crash

iree-compile: /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2439: llvm::LogicalResult legalizeUnresolvedMaterialization(mlir::RewriterBase &, (anonymous namespace)::UnresolvedMaterializationRewrite *): Assertion `newMaterialization.getType() == outputType && "materialization callback produced value of incorrect type"' failed.
Please report issues to https://github.com/iree-org/iree/issues and include the crash backtrace.
Stack dump:
0.  Program arguments: iree-compile --iree-hal-target-backends=llvm-cpu -o abc.vmfb crash.mlir
 #0 0x00007f37630c0ba7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x00007f37630bede0 llvm::sys::RunSignalHandlers() /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00007f37630c126a SignalHandler(int) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007f375d3e8520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f375d43c9fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
 #5 0x00007f375d43c9fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
 #6 0x00007f375d43c9fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
 #7 0x00007f375d3e8476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f375d3ce7f3 abort ./stdlib/./stdlib/abort.c:81:7
 #9 0x00007f375d3ce71b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#10 0x00007f375d3dfe96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00007f376756c71f mlir::InFlightDiagnostic& mlir::InFlightDiagnostic::append<char const (&) [53]>(char const (&) [53]) & /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/include/mlir/IR/Diagnostics.h:341:5
#12 0x00007f376756c71f mlir::InFlightDiagnostic&& mlir::InFlightDiagnostic::operator<<<char const (&) [53]>(char const (&) [53]) && /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/include/mlir/IR/Diagnostics.h:335:22
#13 0x00007f376756c71f legalizeUnresolvedMaterialization(mlir::RewriterBase&, (anonymous namespace)::UnresolvedMaterializationRewrite*) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2446:29
#14 0x00007f376756c71f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2513:18
#15 0x00007f3767571cab mlir::applyPartialConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3226:22
#16 0x00007f3767571cab mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3232:10
#17 0x00007f3764ab44e2 mlir::iree_compiler::IREE::VM::ConversionPass::runOnOperation() /proj/xhdhdstaff6/dhirajp/localBuild/iree/compiler/src/iree/compiler/Dialect/VM/Transforms/Conversion.cpp:159:16
#18 0x00007f37632af745 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7::operator()() const /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Pass/Pass.cpp:0:17
#19 0x00007f37632af745 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7>(long) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#20 0x00007f37632af745 llvm::function_ref<void ()>::operator()() const /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#21 0x00007f37632af745 void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/include/mlir/IR/MLIRContext.h:280:7
#22 0x00007f37632af745 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Pass/Pass.cpp:520:21
#23 0x00007f37632afeb8 llvm::LogicalResult::failed() const /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#24 0x00007f37632afeb8 llvm::failed(llvm::LogicalResult) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:71:58
#25 0x00007f37632afeb8 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Pass/Pass.cpp:592:9
#26 0x00007f37632b2209 mlir::PassManager::run(mlir::Operation*) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/mlir/lib/Pass/Pass.cpp:0:0
#27 0x00007f3763013aa0 llvm::LogicalResult::failed() const /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#28 0x00007f3763013aa0 llvm::failed(llvm::LogicalResult) /proj/xhdhdstaff6/dhirajp/localBuild/iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:71:58
#29 0x00007f3763013aa0 mlir::iree_compiler::embed::(anonymous namespace)::Invocation::runPipeline(iree_compiler_pipeline_t) /proj/xhdhdstaff6/dhirajp/localBuild/iree/compiler/src/iree/compiler/API/Internal/CompilerDriver.cpp:997:7

Steps to reproduce your issue

command:

 iree-compile --iree-hal-target-backends=llvm-cpu -o abc.vmfb crash.mlir

What component(s) does this issue relate to?

Compiler

Version information

No response

Additional context

No response

ScottTodd commented 4 weeks ago

Please include version information in all bug reports. Context about the program being compiled here would also be useful to help prioritize.

pdhirajkumarprasad commented 3 weeks ago

Build used : 03c744ead1482abde3ee9e70293215c5b557c629 and this is ONNX model from alt_e2e test suite