Skip to content

Commit

Permalink
[Tutorial][Executor] Fix executors in tutorials
Browse files Browse the repository at this point in the history
Co-authored-by: Junru Shao <[email protected]>
  • Loading branch information
junrushao committed Aug 8, 2021
1 parent dbfbebe commit 09d444b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tutorials/dev/bring_your_own_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ def get_cat_image():
######################################################################
# It's easy to execute MobileNet with native TVM:

ex = tvm.relay.create_executor("graph", mod=module)
ex = tvm.relay.create_executor("graph", mod=module, params=params)
input = get_cat_image()
result = ex.evaluate()(input, **params).numpy()
result = ex.evaluate()(input).numpy()
# print first 10 elements
print(result.flatten()[:10])

Expand Down
4 changes: 2 additions & 2 deletions tutorials/frontend/from_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@
target = "cuda"
dev = tvm.cuda(0)
with tvm.transform.PassContext(opt_level=3):
executor = relay.build_module.create_executor("graph", mod, dev, target)
executor = relay.build_module.create_executor("graph", mod, dev, target, params).evaluate()

######################################################################
# Execute on TVM
# ---------------
dtype = "float32"
tvm_out = executor.evaluate()(tvm.nd.array(data.astype(dtype)), **params)
tvm_out = executor(tvm.nd.array(data.astype(dtype)))
top1_tvm = np.argmax(tvm_out.numpy()[0])

#####################################################################
Expand Down
6 changes: 4 additions & 2 deletions tutorials/frontend/from_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@
mod, params = relay.frontend.from_onnx(onnx_model, shape_dict)

with tvm.transform.PassContext(opt_level=1):
intrp = relay.build_module.create_executor("graph", mod, tvm.cpu(0), target)
executor = relay.build_module.create_executor(
"graph", mod, tvm.cpu(0), target, params
).evaluate()

######################################################################
# Execute on TVM
# ---------------------------------------------
dtype = "float32"
tvm_output = intrp.evaluate()(tvm.nd.array(x.astype(dtype)), **params).numpy()
tvm_output = executor(tvm.nd.array(x.astype(dtype))).numpy()

######################################################################
# Display results
Expand Down

0 comments on commit 09d444b

Please sign in to comment.