Failure of registration of global function in TVM python API

Recently I started to investigate tuning of kernels in TIR format by meta-scheduler. I prepared python script for it with minimal imports from TVM. As results It failed due to tvm.topi.x86.utils.target_has_vnni was not registered but used on native side of TVM. You can see my fix and details in PR. Nevertheless it looks like more general problem of TVM. There are many global functions distributed in TVM code and nobody follows when they are registered and used. Possibly the issue with microTVM in CI tests was related to the same thing.

I would discuss here how can my particlar problem be workarounded correctly and in the best way, and how global functions can be organized in TVM code to the better control and using of them.

cc @apeskov

the reason that this particular method is not registered is that it’s not imported by default, so the python interpreter doesn’t even have the chance to run registration. If we get those methods imported beforehand, the problem would be gone :slight_smile:

I fully agree that we can do so. But 1. I do not think that it should be done on client script level, client should know about high-level API, but not about low-level details. 2. It means that TVM by its-self should registrate needed funcs for correct execution of high-level operations. This point was stopped by problem of TVM design and hierarchy of imports. 3. Other solution is to have separated module (and submodules) with stack of global funcs. Thus they can be imported without additional dependencies. The latter looks like more controlable process, but it needs heroic efforts to find all registered func in TVM and transfer them to new location saving all dependencies.

1 Like

I fully agree with all your points, and i do think we need to think carefully about the dependency between submodules :slight_smile:

In our particular case, if we need the particular methods from tvm/topi to tvm/target, then it should be fine given MetaSchedule/TIR are designed to depend on tvm.target.