I'm trying to understand the relationship between relay.build() and 
tvm.build(). 

@vinx13, thanks for you reply. Does this mean a neural-network import from 
certain framework, say MXNET (e.g. [this 
tutorial](https://docs.tvm.ai/tutorials/frontend/from_mxnet.html)), can only 
use relay.build() to do full-model compilation? Is there a way to optimize 
further using tvm.build() or it is actually doing that under the hood? It is 
appreciated anyone can specify the code there. Thanks. 

```
shape_dict = {'data': x.shape}
mod, params = relay.frontend.from_mxnet(block, shape_dict)
## we want a probability so add a softmax operator
func = mod["main"]

func = relay.Function(func.params, relay.nn.softmax(func.body), None, 
func.type_params, func.attrs)
target = 'llvm'
with relay.build_config(opt_level=3):
    graph, lib, params = relay.build(func, target, params=params)

##########################
# Anything we can do here to further optimize individual operators/steps 
#   in the imported resnet using tvm.build()?
########################

...
from tvm.contrib import graph_runtime
ctx = tvm.gpu(0)
dtype = 'float32'
m = graph_runtime.create(graph, lib, ctx)
# set inputs
m.set_input('data', tvm.nd.array(x.astype(dtype)))
m.set_input(**params)
# execute
m.run()
# get outputs
tvm_output = m.get_output(0)
top1 = np.argmax(tvm_output.asnumpy()[0])
print('TVM prediction top-1:', top1, synset[top1])





---
[Visit 
Topic](https://discuss.tvm.ai/t/relationship-between-tvm-build-and-relay-build/4166/3)
 to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.tvm.ai/email/unsubscribe/2354962d49e135e12e681301f1262f782145c2414742d6467e1225dec9fda54e).

Reply via email to