[Relay]Is it possible to use tvm Tensor object as input to relay operator?


#1

The example code is like this:

import tvm.relay.op.nn.nn
a = tvm.placeholder((1,3,16,16), name='a')
b = tvm.relay.op.nn.nn.relu(a)

I get the following error:

Traceback (most recent call last):
File “”, line 1, in
File “/home/pengxihan/tvm/python/tvm/relay/op/nn/nn.py”, line 524, in relu
return _make.relu(data)
File “/home/pengxihan/tvm/python/tvm/_ffi/_ctypes/function.py”, line 209, in call
raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
[bt] (3) /home/pengxihan/tvm/build/libtvm.so(TVMFuncCall+0x61) [0x7f5740320c41]
[bt] (2) /home/pengxihan/tvm/build/libtvm.so(+0xcce496) [0x7f573ffc4496]
[bt] (1) /home/pengxihan/tvm/build/libtvm.so(+0xb8b304) [0x7f573fe81304]
[bt] (0) /home/pengxihan/tvm/build/libtvm.so(+0x842eb2) [0x7f573fb38eb2]
File “/home/pengxihan/tvm/include/tvm/packed_func_ext.h”, line 141
TVMError: Check failed: NodeTypeChecker: :Check(sptr.get()): Expected type relay.Expr but get Tensor

It seems that relay operator only accept relay.Expr as its input, but I want to give a tvm Tensor as its input and then I want to use tvm.create_schdule function.


#2

Instead of using tvm.placeholder, you can use relay.var

x = tvm.relay.Var("x", tvm.relay.TensorType([1,3,16,16]))

#3

Maybe I did not make my description clear. What I want to do is to use relay operator that is written to implement my customized operator which can only be developed by tvm primitives, just like tvm.placeholder, tvm.compute, etc.


#4

Someone can correct me if I’m wrong, but Relay is at a higher level than TVM primitives. Relay operators are abstract, and call back to an implementation in TOPI. This TOPI implementation uses TVM primitives.

So, you can create your own Relay operator and have it call back to your TOPI implementation.