Impact of opset_version to onnx in TVM

I have two models, i.e., big and small.

  • 1 .Currently what I found is when exports the onnx model from the small model in pytorch, opset_version should be set to 11 (default is 9) because there is some operation the version 9 doesn’t support. This onnx model can’t be used to run inference and tune in TVM (got below issue).

torch.onnx.export(model, sample, ntpath.basename(model_path).rsplit('.', 1)[0]+'.onnx', opset_version=11)

  • 2.The big model is able to be exported to a onnx model with setting as 9. This onnx model can run inference and be tuned in TVM. But if set the opset_version to 11 then the onnx model exported from the big model will not be able to run inference in TVM (got below issue).

Seems the opset_version has some impacts on the onnx run&tuning in TVM. Is this true?

Error message:

tensor type `Tensor[(1), bool]` has 1 dimensions, while `bool` has 0 dimensions
The Relay type checker is unable to show the following types match.
In particular `Tensor[(1), bool]` does not match `bool`
tensor type `Tensor[(?, 1, ?, ?), float32]` has 4 dimensions, while `Tensor[(?, ?, ?), float32]` has 3 dimensions
The Relay type checker is unable to show the following types match.
In particular `Tensor[(?, 1, ?, ?), float32]` does not match `Tensor[(?, ?, ?), float32]`

After set the below environment, te backtrace looks below:

"run with TVM_BACKTRACE=1 environment variable to display a backtrace"

tensor type `Tensor[(1), bool]` has 1 dimensions, while `bool` has 0 dimensions
The Relay type checker is unable to show the following types match.
In particular `Tensor[(1), bool]` does not match `bool`
tensor type `Tensor[(?, 1, ?, ?), float32]` has 4 dimensions, while `Tensor[(?, ?, ?), float32]` has 3 dimensions
The Relay type checker is unable to show the following types match.
In particular `Tensor[(?, 1, ?, ?), float32]` does not match `Tensor[(?, ?, ?), float32]`
Traceback (most recent call last):
  File "run_onnx_tvm_camera.py", line 123, in <module>
    graph, lib, params = relay.build(mod,
  File "/home/workspacae/installation/TVM/tvm/python/tvm/relay/build_module.py", line 275, in build
    graph_json, mod, params = bld_mod.build(mod, target, target_host, params)
  File "/home/workspacae/installation/TVM/tvm/python/tvm/relay/build_module.py", line 138, in build
    self._build(mod, target, target_host)
  File "/home/workspacae/installation/TVM/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm.error.DiagnosticError: Traceback (most recent call last):
  [bt] (8) /home/workspacae/installation/TVM/tvm/build/libtvm.so(tvm::relay::backend::RelayBuildModule::Optimize(tvm::IRModule, tvm::Map<tvm::Integer, tvm::Target, void, void> const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tvm::runtime::NDArray, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, tvm::runtime::NDArray> > > const&)+0xe86) [0x7f9ba6d27826]
  [bt] (7) /home/workspacae/installation/TVM/tvm/build/libtvm.so(tvm::transform::Pass::operator()(tvm::IRModule) const+0x67) [0x7f9ba6258067]
  [bt] (6) /home/workspacae/installation/TVM/tvm/build/libtvm.so(tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const+0x32f) [0x7f9ba636524f]
  [bt] (5) /home/workspacae/installation/TVM/tvm/build/libtvm.so(tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const+0x27e) [0x7f9ba636519e]
  [bt] (4) /home/workspacae/installation/TVM/tvm/build/libtvm.so(tvm::transform::ModulePassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const+0x1d4) [0x7f9ba63683d4]
  [bt] (3) /home/workspacae/installation/TVM/tvm/build/libtvm.so(+0x120eeb2) [0x7f9ba6d04eb2]
  [bt] (2) /home/workspacae/installation/TVM/tvm/build/libtvm.so(+0x120de37) [0x7f9ba6d03e37]
  [bt] (1) /home/workspacae/installation/TVM/tvm/build/libtvm.so(tvm::DiagnosticContext::Render()+0x231) [0x7f9ba6319391]
  [bt] (0) /home/workspacae/installation/TVM/tvm/build/libtvm.so(+0x822f88) [0x7f9ba6318f88]
  File "/home/workspacae/installation/TVM/tvm/src/ir/diagnostic.cc", line 105
DiagnosticError: one or more error diagnostics were emitted, please check diagnostic render for output.