2

In the TVM library, when the _relay.build_module.build()_ is used, what is the output result both after relay.build and tvm.build

And what is the difference and need for two parameters as output - graph and library - which are later used to run the graph or create a graph runtime ?

For example in this code :

opt_level = 3
target = tvm.target.cuda()
with relay.build_config(opt_level=opt_level):
    graph, lib, params = relay.build_module.build(
        net, target, params=params)

What are the outputs graph, lib ? Can we use just one of them to generate a graph runtime or do we always have to use both of them like below :

# create random input
ctx = tvm.gpu()
data = np.random.uniform(-1, 1, size=data_shape).astype("float32")
# create module
module = graph_runtime.create(graph, lib, ctx)
# set input and parameters
module.set_input("data", data)
module.set_input(**params)
# run
module.run()
# get output
out = module.get_output(0, tvm.nd.empty(out_shape)).asnumpy()
Ryan Schaefer
  • 3,047
  • 1
  • 26
  • 46

1 Answers1

1

To generate a graph runtime you always need both graph and lib.

  • graph: the execution graph in json format
  • lib: the TVM module library of compiled functions specifically for this graph on the target hardware.

In other words, graph tells the compiler how the layers are arranged; lib specifies the function each layer implements.

Source: https://docs.tvm.ai/tutorials/relay_quick_start.html#sphx-glr-tutorials-relay-quick-start-py

giovannib
  • 36
  • 2