How does USE_RELAY_DEBUG work (with Relay/Relax)?

I’m a newcomer and followed this comment to try to dump the debugging infos. I’m sure I turned on USE_RELAY_DEBUG and exported environmental variable TVM_LOG_DEBUG. However, I tried a few examples such as this old one with Relay or this newer one with Relax. Neither dumps the IR. Do I have to make any further adjustment in order to do what I expected?

You can directly use print(mod) to dump the IRModule

However, I want to dump the IR module after each passes. Do I have to do it manually? It seems this post wants to achieve what I want.

see if tvm.instrument — tvm 0.20.dev0 documentation works

This worked for me:

from tvm.ir.instrument import PrintAfterAll, PrintBeforeAll 
… 
with tvm.transform.PassContext(opt_level=3, instruments=[PrintBeforeAll(), PrintAfterAll()]):
        mod = tvm.tir.transform.DefaultGPUSchedule()(mod)
        ex = relax.build(mod, target, exec_mode="compiled")

Set TVM_LOG_DEBUG env var, e.g., TVM_LOG_DEBUG=DEFAULT=2

1 Like

Thank you very much. It worked!