Hi,
I converted my first model to TVM. However I have some issues and questions.
-
I still don’t get the target and target_host event looking at the docs I don’t get the full meaning.
https://docs.tvm.ai/api/python/build.html -
My model has dynamic inputs however I had to make the fixed because the TVM was complaining. How can I make dynamic graphs in TVM?
tf.placeholder(tf.float32, [None, None, 3], name=‘input’)
- After given a fixed input I was able to convert it using graph.as_graph_def(add_shapes=True) (I had to add the shapes) however I have some warnings
cannot evaluate set type Cast
cannot find config for target llvm, workload=(‘conv2d’
Further investigation has driven to me that I have to specifically fine tune it on my own. Is that right?
The model runs in 35secs which is 3.6x slower than tensorflow
here is my code:
import nnvm
import nnvm.compiler
import nnvm.testing.tf
import tvm
x0 = img
target = 'llvm -mcpu=core-avx2'
target_host = 'llvm'
layout = None
ctx = tvm.cpu(0)
## nnvm graph
graph_def = nnvm.testing.tf.ProcessGraphDefParam( graph.as_graph_def(add_shapes=True) )
sym, params = nnvm.frontend.from_tensorflow(graph_def, layout=layout)
shape_dict = {'input': x0.shape}
dtype_dict = {'input': 'float32'}
graph, lib, params = nnvm.compiler.build(sym, shape=shape_dict, target=target, target_host=target_host, dtype=dtype_dict, params=params)
from tvm.contrib import graph_runtime
m = graph_runtime.create(graph, lib, ctx)
ts = time.time()
m.set_input('input', tvm.nd.array( x0.astype('float32') ) )
m.set_input(**params)
m.run()
tvm_output = m.get_output(0).asnumpy()
print('tvm predict took:' + str(time.time() - ts) )
imsave('test_tvm.jpg', tvm_output)