TypeError: Array is not registered via TVM_REGISTER_NODE_TYPE

I am working on adding a unit test for resize operator in relay to onnx conversion.

import tvm
from tvm import relay
from tvm.contrib.target.onnx import to_onnx

x = relay.var("x", shape=(1, 3, 480, 640), dtype="float32")
y = relay.image.resize(x, size=(240, 1280))

f = relay.Function([x], y)
mod = tvm.IRModule()
mod["main"] = f
onnx_model = to_onnx(mod, {}, "test_resize", path=None)

When I run the above code, I get the following error. I can send the full error log if its useful.

.
.
File "/home/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
raise get_last_ffi_error()
TypeError: Traceback (most recent call last):
[bt] (4) /home/tvm/build/libtvm.so(TVMFuncCall+0x65) [0x7fd2320f1695]
[bt] (3) /home/tvm/build/libtvm.so(std::_Function_handler<void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*), void (*)(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)>::_M_invoke(std::_Any_data const&, tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)+0x14) [0x7fd2314d50e4]
[bt] (2) /home/tvm/build/libtvm.so(tvm::NodeGetAttr(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)+0x31e) [0x7fd2314d302e]
[bt] (1) /home/tvm/build/libtvm.so(tvm::ReflectionVTable::GetAttr(tvm::runtime::Object*, tvm::runtime::String const&) const+0x3e0) [0x7fd2314d2840]
[bt] (0) /home/tvm/build/libtvm.so(+0xcc5552) [0x7fd2314d1552]

File "/home/tvm/include/tvm/node/reflection.h", line 390
TypeError: Array is not registered via TVM_REGISTER_NODE_TYPE

How do I register array? And which array - x?

Have you tried to recompile TVM?

Yes, I re-built the latest main. commit 1d7a9e9dff1983cd4b12104f93b32bfe4b4c4f7e

Here is the full error log:

Traceback (most recent call last):
  File "test_resize.py", line 12, in <module>
    onnx_model = to_onnx(mod, {}, "test_resize", path=None)
  File "/home/tvm/python/tvm/contrib/target/onnx.py", line 1049, in to_onnx
    onnx_model = converter.convert_to_onnx(func)
  File "/home/tvm/python/tvm/contrib/target/onnx.py", line 879, in convert_to_onnx
    self.visit(func)
  File "/home/tvm/python/tvm/contrib/target/onnx.py", line 887, in visit
    super().visit(expr)
  File "/home/tvm/python/tvm/relay/expr_functor.py", line 46, in visit
    res = self.visit_function(expr)
  File "/home/tvm/python/tvm/relay/expr_functor.py", line 156, in visit_function
    self.visit(f.body)
  File "/home/tvm/python/tvm/contrib/target/onnx.py", line 887, in visit
    super().visit(expr)
  File "/home/tvm/python/tvm/relay/expr_functor.py", line 48, in visit
    res = self.visit_call(expr)
  File "/home/tvm/python/tvm/contrib/target/onnx.py", line 949, in visit_call
    self._add_node(node_entry, node_index)
  File "/home/tvm/python/tvm/contrib/target/onnx.py", line 960, in _add_node
    return converter.convert(node_entry, self._mc, self._node_dict)
  File "/home/tvm/python/tvm/contrib/target/onnx.py", line 734, in convert
    out_size_array, numpy.asarray(input_shape).astype(numpy.int64)
  File "/usr/local/lib/python3.7/dist-packages/numpy/core/_asarray.py", line 85, in asarray
    return array(a, dtype, copy=False, order=order)
  File "/home/tvm/python/tvm/runtime/object.py", line 63, in __getattr__
    return _ffi_node_api.NodeGetAttr(self, name)
  File "/home/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
TypeError: Traceback (most recent call last):
  3: TVMFuncCall
  2: _ZNSt17_Function_handlerI
  1: tvm::NodeGetAttr(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)
  0: tvm::ReflectionVTable::GetAttr(tvm::runtime::Object*, tvm::runtime::String const&) const
  File "/home/tvm/include/tvm/node/reflection.h", line 390
TypeError: Array is not registered via TVM_REGISTER_NODE_TYPE

Also, I noticed that with the latest code, tvm.relay.image.resize is no longer supported. I had to change that to tvm.relay.image.resize2d. Is this expected?

  • For resize, I think so: [Relay][TOPI] Resize 1D by mbrookhart ¡ Pull Request #8346 ¡ apache/tvm ¡ GitHub

  • I cannot reproduce your error on my local. Instead, this is what I got:

    File "/home/ubuntu/cody-tvm/python/tvm/contrib/target/onnx.py", line 867, in _add_node
        "Currently the operator '{0}' is " "not supported.".format(node_entry["op"].name)
    NotImplementedError: Currently the operator 'image.resize2d' is not supported.
    

    So I still feel the error you got is due to the mismatch between TVM Python code and built C++ shared library. You can check whether they are referring to the same build directory.

    On the other hand, I have no idea why resize2d is not supported in ONNX converter. Maybe @mbrookhart knows more details.

Yes, sorry, I refactored the resize kernels to match conv1d/2d/3d, etc, we had resize (instead of resize2d), resize3d, and no resize1d before.

@schil The error you posted is definitely consistent with a mis-build of TVM, I would delete your build directory and re-run cmake.

python/tvm/contrib/target/onnx.py

I wasn’t aware of this file, it looks like it’s trying to export a relay graph to onnx? I’ve only worked on the other direction. It looks like this is something developed primarily by @maheshambule and @xyzhou, and recently (yesterday) extended by you @schil :smiley:

I’m not sure what the target flow for this pass it, but it doesn’t look like it supports all that many ops:

1 Like

@comaniac @mbrookhart Thanks for the ideas.

Re-building TVM cleaned it up. There was also an issue in my local relay to onnx conversion code for resize. “Currently the operator ‘image.resize2d’ is not supported” was because I forgot to post the conversion code. My bad.

All issues are resolved. Have filed a PR for resize op conversion to onnx.

Thanks for all your help!

1 Like