【TIR】After auto tuning, what other optimizations based on tir will be done?

I am a newer to TVM, from my point, compute + schedule + auto tuning convert the relay IR to Tensor IR. this process includes many hardware special optimizations related with schedule primitives. After the auto tuning, Tensor IR was generated.

Q1: Besides the AutoTVM(include schedules), what are the optimizations based on TIR?These optimizations are the operations in /tir/transform files?
I did not find any related knowledge about optimizations based on tir in tvm paper

Q2: whether relay.build() execute the related call below?

If there are any mistakes, please correct me.

Thanks in advance!

I’m no expert with this, but if you take a look in build_module.py, you can see what TIR passes are run after the schedules have been lowered. I’ll paste them here for convenience:

tvm.tir.transform.InjectPrefetch(),
tvm.tir.transform.StorageFlatten(64, instrument_bound_checkers),
tvm.tir.transform.BF16Legalize(),
tvm.tir.transform.NarrowDataType(32),
tvm.tir.transform.Simplify(),
tvm.tir.transform.LoopPartition(),
tvm.tir.transform.VectorizeLoop(not disable_vectorize),
tvm.tir.transform.InjectVirtualThread(),
tvm.tir.transform.InjectDoubleBuffer(),
tvm.tir.transform.StorageRewrite(),
tvm.tir.transform.UnrollLoop(),
tvm.tir.transform.Simplify(),
tvm.tir.transform.RemoveNoOp(),
tvm.tir.transform.RewriteUnsafeSelect(),
tvm.tir.transform.HoistIfThenElse()

I’m only familiar with a few of these, but sometimes to get a better understanding I’ll just print the module between passes and see what changed.

What @mbaret pointed out is correct. In addition, your figure is not exactly correct. relay.build actually goes the same flow as AutoTVM/TE schedule. When calling relay.build, it lowers each operator to TE according to Relay op strategy. The op strategy will select a TE compute/schedule for each Relay op based on certain rules. For example, if you provide the tuning logs like:

with ApplyHistoryBest('tune.log'):
  relay.build(mod, target)

Then the op strategy will be based on the tuning results. On the other hand, it selects schedules based on the default priority order.