Hi All,
I am trying to update an IRModule with a new function, and I find out update_func from here: https://tvm.apache.org/docs/api/python/ir.html#tvm.ir.IRModule.update_func
I have written a simple test, and I am getting an error. So, the problem is either my understanding of udpate_func is wrong OR I am not using update_func properly. Any suggestions?
Here is my example
import tvm
import tvm.relay as relay
def module_update():
x0 = relay.var('x0', shape=(20, 1))
y0 = relay.var('y0', shape=(20, 1))
sub0 = relay.op.subtract(x0, y0)
f1 = relay.Function([], sub0)
print(f1)
mod = tvm.IRModule({"func1": f1})
print(mod)
x1 = relay.var('x1', shape=(20, 1))
y1 = relay.var('y1', shape=(20, 1))
add1 = relay.op.add(x1, y1)
f2 = relay.Function([], add1)
print(f2)
a = tvm.ir.GlobalVar('func2')
# update the module
mod.update_func(a, f2)
print(mod)
if __name__ == "__main__":
print("Testing Custom Sequential Pass")
s = module_update()
Here is the error
<class 'tvm.relay.function.Function'>
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\pydevd.py", line 1438, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm 2020.1.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/repos/tvm23/tvm/graph_opt/IRModule/IRModuleUpdate.py", line 35, in <module>
File "C:/repos/tvm23/tvm/graph_opt/IRModule/IRModuleUpdate.py", line 29, in module_update
File "C:\repos\tvm23\tvm\python\tvm\ir\module.py", line 135, in update_func
return _ffi_api.Module_UpdateFunction(self, var, func)
File "C:\repos\tvm23\tvm\python\tvm\_ffi\_ctypes\packed_func.py", line 237, in __call__
raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
File "C:\repos\tvm23\tvm\src\ir\module.cc", line 186
TVMError:
---------------------------------------------------------------
An internal invariant was violated during the execution of TVM.
Please read TVM's error reporting guidelines.
More details can be found here: https://discuss.tvm.ai/t/error-reporting/7793.
---------------------------------------------------------------
Check failed: fv.size() == 0 (2 vs. 0) : There are free variables: [Var(x1, ty=TensorType([20, 1], float32)), Var(y1, ty=TensorType([20, 1], float32))]