I am trying ti run quantize in tvm, however, I got following errors: Expected type relay.Expr but get relay.Module
my code :
import numpy as np
import tvm
import tvm.autotvm as autotvm
import tvm.relay as relay
import tvm.relay.testing
import tvm.autotvm
from tvm.contrib import graph_runtime
from common import get_network
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--log_file', type=str, default='logs/history_best_1080.log')
args = parser.parse_args()
ctx = tvm.gpu(0)
target = tvm.target.cuda()
def bench(name, batch):
sym, data_shape = get_network(name, batch)
data_shape = data_shape[0][1]
sym, _ = relay.frontend.from_mxnet(sym, {'data': data_shape})
sym, params = tvm.relay.testing.create_workload(sym)
with relay.quantize.qconfig(skip_k_conv=0, round_for_shift=True):
sym = relay.quantize.quantize(sym, params)
with relay.build_module.build_config(opt_level=3):
graph, lib, params = relay.build(sym, 'cuda', 'llvm', params=params)
m = graph_runtime.create(graph, lib, ctx)
x = np.random.uniform(size=data_shape)
data_tvm = tvm.nd.array(x.astype('float32'))
m.set_input("data", data_tvm)
m.set_input(**{k:tvm.nd.array(v, ctx) for k, v in params.items()})
m.run()
e = m.module.time_evaluator("run", ctx, number=2000, repeat=3)
t = e(data_tvm).results
t = np.array(t) * 1000
print('{} (batch={}): {} ms'.format(name, batch, t.mean()))
def main():
with tvm.target.cuda():
with autotvm.apply_history_best(args.log_file):
for batch in [1, 16]:
for name in ['vgg-19', 'resnet-50', 'resnext-50', 'inception_v3', 'drn-c-26', 'dcn-resnet-101']:
bench(name, batch)
if __name__ == '__main__':
main()
error information
File "run_tvm.py", line 53, in <module>
main()
File "run_tvm.py", line 49, in main
bench(name, batch)
File "run_tvm.py", line 24, in bench
sym, params = tvm.relay.testing.create_workload(sym)
File "/mnt/ebs0/lst/tvm/tvm/python/tvm/relay/testing/init.py", line 153, in create_workload
mod = relay.Module.from_expr(net)
File "/mnt/ebs0/lst/tvm/tvm/python/tvm/relay/module.py", line 183, in from_expr
return _module.Module_FromExpr(expr)
File "tvm/_ffi/_cython/./function.pxi", line 310, in tvm._ffi._cy3.core.FunctionBase.__call__
File "tvm/_ffi/_cython/./function.pxi", line 245, in tvm._ffi._cy3.core.FuncCall
File "tvm/_ffi/_cython/./function.pxi", line 234, in tvm._ffi._cy3.core.FuncCall3
File "tvm/_ffi/_cython/./base.pxi", line 170, in tvm._ffi._cy3.core.CALL
tvm._ffi.base.TVMError: Traceback (most recent call last):
[bt] (3) /mnt/ebs0/lst/tvm/tvm/build/libtvm.so(TVMFuncCall+0x46) [0x2b5cf662c556]
[bt] (2) /mnt/ebs0/lst/tvm/tvm/build/libtvm.so(+0xd98e03) [0x2b5cf634ce03]
[bt] (1) /mnt/ebs0/lst/tvm/tvm/build/libtvm.so(tvm::relay::Expr tvm::runtime::TVMArgValue::AsNodeRef<tvm::relay::Expr>()const+0x254) [0x2b5cf62a2e74]
[bt] (0) /mnt/ebs0/lst/tvm/tvm/build/libtvm.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x22) [0x2b5cf5fbf0b2]
File "/mnt/ebs0/lst/tvm/tvm/include/tvm/packed_func_ext.h", line 141
TVMError: Check failed: NodeTypeChecker<TNodeRef>: :Check(sptr.get()): Expected type relay.Expr but get relay.Module