tvm icon indicating copy to clipboard operation
tvm copied to clipboard

[Bug] Inconsistent Transformation Results in TVM's DivToMul Optimization

Open Jupiterghy opened this issue 1 year ago • 0 comments

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.

Expected behavior

The modules after transformation should be structural equal.

Actual behavior

The two transformed modules (module and module_once) are not structurally equal.

Environment

  • Operating System: Ubuntu 18.04.5
  • TVM version: 0.15.dev0
  • ONNX: 1.15.0

Steps to reproduce

  1. Download the ONNX model
  2. Execute the script:
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)

Triage

  • needs-triage

Jupiterghy avatar Mar 29 '24 04:03 Jupiterghy