As far as I know, there are two types of dynamic shape.
-
The final output shape can be infered once the input shape is supplied. For example, resnet , once the input shape is fixed, the output shape is fixed.
-
The final output shape is related to the input tensor value. For example, I want to get all elements that is less than 0.5, and use these elements to do some calculation. Does Relay VM support this kind of dynamic shape ?
I wrote an example of the 2nd type, and Relay VM doesn’t work. I wonder to what extent dynamic shape is supported in Relay VM.
TVMError: Check failed: fshape_func.count(op) > 0 (0 vs. 0) : Internal error, cannot find ShapeFunc for gather_nd
import numpy as np
from tvm.runtime.vm import VirtualMachine
import tvm
from tvm import te
from tvm.runtime import profiler_vm
from tvm import relay
import tensorflow as tf
data = np.random.rand(10, 1).astype('float32')
def create_tf_graph_def():
graph = tf.Graph()
with graph.as_default():
a = tf.placeholder(tf.float32, shape=(None, 1))
b = tf.less(a, 0.5)
x = tf.where(b, name='x')
y = tf.gather_nd(a, x, name='y')
with tf.Session() as sess:
result = sess.run(y, feed_dict = {a:data})
return graph.as_graph_def()
def test_basic():
graph_def = create_tf_graph_def()
output_names = ['y']
mod, params = relay.frontend.from_tensorflow(graph_def, outputs = output_names)
target = 'llvm'
ctx = tvm.cpu()
exe = relay.vm.compile(mod, target, params=params)
vm = VirtualMachine(exe, tvm.cpu())
res = vm.invoke("main", data)
print(res)
if __name__ == "__main__":
test_basic()