Why autotune is used in the calling of relay.build() with opt_level 0

One stack trace of the calling to relay.build() is as below:
  0: tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<TVMFuncCreateFromCFunc::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#2}> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) [clone .cold]
  File "/home/xuyangyang/tvm2/python/tvm/_ffi/_ctypes/packed_func.py", line 81, in cfun
    rv = local_pyfunc(*pyargs)
  File "/home/xuyangyang/tvm2/python/tvm/relay/op/strategy/generic.py", line 56, in wrapper
    return topi_schedule(outs)
  File "/home/xuyangyang/tvm2/python/tvm/autotvm/task/topi_integration.py", line 242, in wrapper
    return topi_schedule(cfg, outs, *args, **kwargs)
  File "/home/xuyangyang/tvm2/python/tvm/topi/cuda/conv2d.py", line 46, in schedule_conv2d_nchw
    traverse_inline(s, outs[0].op, _callback)
  File "/home/xuyangyang/tvm2/python/tvm/topi/utils.py", line 81, in traverse_inline
    _traverse(final_op)
  File "/home/xuyangyang/tvm2/python/tvm/topi/utils.py", line 79, in _traverse
    callback(op)
  File "/home/xuyangyang/tvm2/python/tvm/topi/cuda/conv2d.py", line 44, in _callback
    schedule_direct_cuda(cfg, s, op.output(0))
  File "/home/xuyangyang/tvm2/python/tvm/topi/cuda/conv2d_direct.py", line 50, in schedule_direct_cuda
    cfg.fallback_with_reference_log(ref_log)
  File "/home/xuyangyang/tvm2/python/tvm/autotvm/task/space.py", line 1413, in fallback_with_reference_log
    factors = get_factors(int(np.prod(inp.config[knob_name].size)))
  File "/home/xuyangyang/tvm2/python/tvm/autotvm/task/space.py", line 170, in get_factors
    ([i, n // i] for i in range(1, int(math.sqrt(n)) + 1, step) if n % i == 0),
ValueError: math domain error

Why is the autotvm/task/space.py called?

Plus, I run the code on “Hygon Z100 GPU” which is similar to AMD MI100 GPU. The build of resnet18 onnx is successful but failed with this more complicated model: model.onnx - Google Drive

I guess that’s because some of the tunable operators’ functions are decorated with autotune decorator. For instance, in the definition of x86’s conv2d operator, you can spot something like: @autotvm.register_topi_compute("conv2d_NCHWc.x86").

And when the operator function is called during the lowering phase of relay.build(), the decorator will do its job and collect the corresponding operator as an autoTVM Task candidate, whether you’ll use autotune later or not.

You’ll go through this autotune task collection procedure anyways because of the existence of that decorator, though you may not do autotune afterward.

As for opt_level setting, it won’t affect the above process. You can refer to the list below to get a better idea of things will happen under different opt_levels:

Thank you. I understand it. By the way, why does this error happen in relay.build()?

The environment setup is in the first post and the code is: tvm_example.py · GitHub