[Bug][ONNX] Found null pointer node while traversing AST

Description:

TVM loads onnx model with OptionalHasElement operater lead to crash. the crash meesage are following.

Crash Message/Traceback:

File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/onnx.py", line 7346, in from_onnx
    mod, params = g.from_onnx(graph, opset)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/onnx.py", line 6963, in from_onnx
    self._construct_nodes(graph)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/onnx.py", line 7078, in _construct_nodes
    op = self._convert_operator(op_name, inputs, attr, self.opset)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/onnx.py", line 7204, in _convert_operator
    sym = convert_map[op_name](inputs, attrs, self._params)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/onnx.py", line 2333, in _impl_v15
    shape = infer_shape(inputs[0])
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/common.py", line 530, in infer_shape
    out_type = infer_type(inputs, mod=mod)
  File "/workplace/software/tvm/tvm/python/tvm/relay/frontend/common.py", line 501, in infer_type
    new_mod = IRModule.from_expr(node)
  File "/workplace/software/tvm/tvm/python/tvm/ir/module.py", line 254, in from_expr
    return _ffi_api.Module_FromExpr(expr, funcs, defs)
  File "/workplace/software/tvm/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
  11: TVMFuncCall
  10: _ZN3tvm7runtime13Pac
  9: tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::RelayExpr const&, tvm::runtime::Map<tvm::GlobalVar, tvm::BaseFunc, void, void> const&, tvm::runtime::Map<tvm::GlobalTypeVar, tvm::TypeData, void, void> const&)>::AssignTypedLambda<tvm::IRModule (*)(tvm::RelayExpr const&, tvm::runtime::Map<tvm::GlobalVar, tvm::BaseFunc, void, void> const&, tvm::runtime::Map<tvm::GlobalTypeVar, tvm::TypeData, void, void> const&)>(tvm::IRModule (*)(tvm::RelayExpr const&, tvm::runtime::Map<tvm::GlobalVar, tvm::BaseFunc, void, void> const&, tvm::runtime::Map<tvm::GlobalTypeVar, tvm::TypeData, void, void> const&), std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}::operator()(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*) const
  8: tvm::IRModule::FromExpr(tvm::RelayExpr const&, tvm::runtime::Map<tvm::GlobalVar, tvm::BaseFunc, void, void> const&, tvm::runtime::Map<tvm::GlobalTypeVar, tvm::TypeData, void, void> const&)
  7: tvm::IRModule::FromExprInContext(tvm::RelayExpr const&, tvm::runtime::Map<tvm::GlobalVar, tvm::BaseFunc, void, void> const&, tvm::runtime::Map<tvm::GlobalTypeVar, tvm::TypeData, void, void> const&, std::unordered_set<tvm::runtime::String, std::hash<tvm::runtime::String>, std::equal_to<tvm::runtime::String>, std::allocator<tvm::runtime::String> >)
  6: tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<tvm::runtime::TypedPackedFunc<tvm::relay::Function (tvm::RelayExpr, tvm::IRModule)>::AssignTypedLambda<tvm::relay::$_5>(tvm::relay::$_5, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)
  5: tvm::relay::FreeVars(tvm::RelayExpr const&)
  4: tvm::relay::VarVisitor::Free(tvm::RelayExpr const&)
  3: tvm::relay::MixedModeVisitor::VisitExpr(tvm::RelayExpr const&)
  2: tvm::relay::MixedModeVisitor::VisitLeaf(tvm::RelayExpr const&)
  1: tvm::relay::ExprFunctor<void (tvm::RelayExpr const&)>::VisitExpr(tvm::RelayExpr const&)
  0: _ZN3tvm7runtime6detail
  File "/workplace/software/tvm/tvm/include/tvm/relay/expr_functor.h", line 92
TVMError: 
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------
  Check failed: (n.defined()) is false: Found null pointer node while traversing AST. The previous pass may have generated invalid data.

Steps to reproduce

  1. download model optional_has_element.onnx

  2. Execute the following command:

python -m tvm.driver.tvmc compile --target 'llvm' optional_has_element.onnx

I have checked the source code of the ONNX frontend, and the OptionalHasElement operator has been supported. I’m curious about why causes this crashed.

@vvchernov @tqchen Is it a bug in ONNXConverter?