How to dump IRs for each pass when building a model

Can we dump the intermediate files to explore the optimization process when building a model using

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):

This will dump all intermediate IRs in a current directory.


@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 =, 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?

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+).

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.

Hello, where is this tvm.build_config come from ? I am using tvm 0.8 dev but this does not exist

Hi @huangteng , tvm.build_config had been replaced with PassContext. Check these PRs.

  1. [REFACTOR][RELAY] Replace build_config with PassContext (#5698) · apache/tvm@c55ed37 (

  2. [REFACTOR][TIR][API-Change] Migrate BuildConfig to PassContext. (#5668) · apache/tvm@b264026 (

1 Like