[dump] any option can dump the relay and tir IR for each pass ?

  • It there any option in tvm similar to -print-after-all in the llvm, which can dump the llvm IR for each pass ?

When I look for the solution in deepseek, it give a example to use dump_pass_ir=1,

from tvm import relay
from tvm.relay import transform

# Build your Relay module (mod) and pass sequence
seq = transform.Sequential([...])

with tvm.transform.PassContext(opt_level=3, dump_pass_ir=1):  # Dump AFTER every pass
    mod_optimized = seq(mod)
  • So I try it base on tvm 0.18, but get a unexpected error ?
(tvm0.18_py310_zyd) root@j00595921debug2-cc95c9977-q752v:/home/zyd# python vector_matmul_add5.5.py
Traceback (most recent call last):
  File "/home/zhongyunde/vector_matmul_add5.5.py", line 41, in <module>
    with tvm.transform.PassContext(opt_level=3, dump_pass_ir=3):
TypeError: PassContext.__init__() got an unexpected keyword argument 'dump_pass_ir'
  • I also try the config in tvm 0.18, but it doesn’t generate any dump files.
export TVM_DUMP_IR=1
export TVM_DUMP_IR_DIR=./ir_dumps
python vector_matmul_add5.5.py
  • so now I define a dump class ,which need modify test case is not convenience to me. At the same time, I find it only dump the IR before tir.Filter pass ?
class MyPassInstrument(tvm.instrument.PassInstrument):
    def enter_pass_ctx(self):
        print("进入 PassContext")

    def exit_pass_ctx(self):
        print("退出 PassContext")

    def should_run(self, mod, info):
        print(f"检查是否运行 pass: {info.name}")
        return True  # 返回 True 表示始终运行该 pass

    def run_before_pass(self, mod, pass_info):
        if pass_info.name != "tir.RenormalizeSplitPattern":
            print(f"\n---- 在 {pass_info.name} 之前 ----")
            print("当前 IR 模块(InferType 之前):")
            # 打印出当前的 IR 模块内容
            print(mod)

    def run_after_pass(self, mod, pass_info):
        if pass_info.name != "tir.RenormalizeSplitPattern":
            print(f"\n---- 在 {pass_info.name} 之后 ----")
            print("当前 IR 模块(InferType 之后):")
            # 打印出当前的 IR 模块内容
            print(mod)

target = "llvm -mcpu=skylake-avx512"
with tvm.transform.PassContext(opt_level=3, instruments=[MyPassInstrument()]):
    func = tvm.build(s, [a, b, c, result], target, name="vector_mul_add")