How to get source from Module[GraphRuntime]?

Hello all, first time poster here.

I have been building networks using the Relay interface, and am curious about what the generated code for these systems is.

The “Get Started with Tensor Expression” tutorial shows that you can get the generated source code from a module using the get_source() method..

However, when I use this approach with a neural network module, such as the one defined in the Relay QuickStart tutorial, I get the following error:

module.module.get_source()

TVMError: Traceback (most recent call last):
  [bt] (3) /home/wheest/tools/tvm/build/libtvm.so(TVMFuncCall+0x4a) [0x7f9e57a9884a]
  [bt] (2) /home/wheest/tools/tvm/build/libtvm.so(+0x94bd34) [0x7f9e57a9ed34]
  [bt] (1) /home/wheest/tools/tvm/build/libtvm.so(tvm::runtime::ModuleNode::GetSource(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0xa7) [0x7f9e57a9e2e7]
  [bt] (0) /home/wheest/tools/tvm/build/libtvm.so(+0x10b382) [0x7f9e5725e382]
  File "/home/wheest/tools/tvm/src/runtime/module.cc", line 97
TVMError: Module[GraphRuntime] does not support GetSource

Is there a way that I can inspect the generated source for modules of this type? I haven’t found anything here, in the GitHub issues, or in the docs yet.

Thanks,
Wheest

How and on what target/context did you compile your module?

Here’s an example to inspect the generated code

import tvm
from tvm import relay
from tvm.relay import testing

# input from relevant `relay.frontend`
# but for now, let's consider resnet 18 with random weights
net, params = relay.testing.resnet.get_workload(
    num_layers=18, batch_size=1, image_shape=(3, 224, 224))

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

print(lib.get_souce())

Thank you, this approach works.

I was trying to access the source of the module returned by:

module = graph_runtime.create(self.graph, self.lib, ctx)

Rather than the lib object returned by relay.build_module.build(self.graph, self.lib, ctx).

graph_runtime.create returns a GraphModule (used for runtime) which you cannot get generated source from. Get source after the compilation step instead.