apache / apache/tvm

[Bug] [FRONTEND][ONNX] The onnx frontend incorrectly recognized two arguments for BitwiseNot operator that only has one arguement

Open Beginner friendly
#17,991 1 comment 0 reactions 0 assignees View on GitHub
needs-triage type: bug
Dominant language
Python
Stars
13.7k
Forks
4k
Avg merge
2d 1h
Merged PRs (30d)
112

Description

### Expected behavior

The onnx frontend should import the model correctly.

### Actual behavior

When importing the onnx model, tvm crashes as follows:
```c
Error converting operator BitwiseNot, with inputs: [R.astype(lv, dtype="int32")]
Traceback (most recent call last):
File "/home/carla/Documents/test/test.py", line 36, in
main()
File "/home/carla/Documents/test/test.py", line 30, in main
tvm_model = from_onnx(onnx_model, keep_params_in_input=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 3696, in from_onnx
return g.from_onnx(graph, opset)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 3327, in from_onnx
self._construct_nodes(graph)
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 3507, in _construct_nodes
raise err
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 3502, in _construct_nodes
op = self._convert_operator(op_name, inputs, attr, self.opset)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 3602, in _convert_operator
sym = op_function(self.bb, inputs, attrs, [self._nodes, self._params])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 575, in _impl_v18
return cls.base_impl(bb, inputs, attr, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 531, in base_impl
return super().base_impl(bb, inputs, attr, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", line 348, in base_impl
return cls.relax_op(inputs[0], inputs[1]) # pylint: disable=not-callable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: bitwise_not() takes 1 positional argument but 2 were given
[16:11:28] /home/carla/Documents/tvm/src/relax/ir/block_builder.cc:64: Warning: BlockBuilder destroyed with remaining blocks!

```

### Environment

OS: Ubuntu 20.04
TVM: 0.21.dev0 (3db71bb3a)

### Steps to reproduce

This bug can be reproduced by the following code with the model in the attachment. As shown in the code, the model can be executed by onnxruntime.
```python
import sys

import numpy as np
import onnx
import onnxruntime

import tvm
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx

import pickle


def main():
onnx_model = onnx.load("a569.onnx")

with open("inputs.pkl", "rb") as fp:
inputs = pickle.load(fp)

try:
ort_session = onnxruntime.InferenceSession(
onnx_model.SerializeToString(), providers=["CPUExecutionProvider"]
)
ort_output = ort_session.run([], inputs)
except Exception as e:
print(e)
sys.exit(1)

# Convert the onnx model into relax through the onnx importer.
tvm_model = from_onnx(onnx_model, keep_params_in_input=True)

if __name__ == "__main__":
main()
```

[testcase.zip](https://github.com/user-attachments/files/20279963/testcase.zip)

### Triage

* needs-triage

cc @KJlaccHoeUM9l

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in python/tvm/relax/frontend/onnx/onnx_frontend.py at the BitwiseNot implementation and the base_impl call shown in the traceback. Reproduce with the attached testcase.zip and the provided from_onnx script; done means the ONNX model imports without the TypeError or block-builder warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.