How to dump IRs for each pass when building a model


#1

Can we dump the intermediate files to explore the optimization process when building a model using nnvm.compiler.build()?


How to dump Relay IR when compiling model
#2

You are in luck. There is a mechanism that does exactly what you want.

When building TVM function, enable dump_ir_pass option, like this:

  with tvm.build_config(dump_ir_pass=True):
          tvm.build(...)

This will dump all intermediate IRs in a current directory.


#3

@masahi Thanks very much

I add the tvm.build_config statement in my code like this:

with nnvm.compiler.build_config(opt_level=2):
    with tvm.build_config(dump_pass_ir=True):
        graph, lib, params = nnvm.compiler.build(sym, target, shape_dict, params=params)

and it dump out almost 2000 files, does those files contain the graph level optimization process in NNVM?

Do you have a good learning road map to understand those files?


#4

This flag only dumps passes in tvm, but there are only 40+ passes in tvm, so you may have like 50+ layers in your model you are building. each of them run thru all passes of tvm, so you have 40*50 files.
if you wanna know what’s happening in each pass, you may choose one layer dump files(40+).


#5

Is that still true today, that there are only 40ish passes in TVM and that dump_pass_ir=True only dumps passes in TVM? I added that flag to TVM’s Relay quick start tutorial, which uses resnet-18 and it outputs around 3600 files, which is way more than 40*18.