Hello,
I have encountered an issue while using the relay.transform.DivToMul()
optimization in TVM. I don’t know why there exists an inconsistency. I think the two methods should yield the same result while actually not. I’d appreciate any help
I am using the following code snippet to optimize a module:
import onnx
import tvm
from tvm import relay
def apply_optimizations(module, opt, num_iterations=1):
for _ in range(num_iterations):
module = opt(module)
return module
if __name__ == "__main__":
onnx_file = "model.onnx"
onnx_model = onnx.load(onnx_file)
shape_dict = {'v25_0': [1, 1, 1], 'v4_0': [12, 2, 45, 1, 1], 'v19_0': [12, 1, 45, 1, 1], 'v15_0': [12, 1, 45, 1, 1], 'v14_0': [12, 52, 45, 1, 1]}
mod, params = relay.frontend.from_onnx(onnx_model, shape_dict, freeze_params=True)
opt = relay.transform.DivToMul()
module = opt(mod)
module_once = apply_optimizations(mod, opt, num_iterations=1)
assert tvm.ir.structural_equal(module, module_once)
I have tried to identify the inconsistency using the following code snippet, but I still don’t know the reason.
path = tvm.ir.base.get_first_structural_mismatch(module, module_once)
print(path)
# (<root>.functions[I.GlobalVar("main")].body.fields[2].args[1].data, <root>.functions[I.GlobalVar("main")].body.fields[2].args[1].data)
print(str(module) == str(module_once))
# The output is True