coffezhou opened a new issue, #18030:
URL: https://github.com/apache/tvm/issues/18030

   ### Expected behavior
   
   The onnx frontend should import the model correctly.
   
   ### Actual behavior
   
   For the following model, the onnx frontend cannot import it.
   
   
![Image](https://github.com/user-attachments/assets/46b3f015-c7d7-4951-9d52-4de3800ae470)
   
   ```c
   
   tvm_model = from_onnx(model, keep_params_in_input=True)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", 
line 3695, in from_onnx
       return g.from_onnx(graph, opset)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", 
line 3326, in from_onnx
       self._construct_nodes(graph)
     File 
"/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", 
line 3506, in _construct_nodes
       raise err
     File 
"/home/carla/Documents/tvm/python/tvm/relax/frontend/onnx/onnx_frontend.py", 
line 3503, in _construct_nodes
       op = self.bb.normalize(op)
            ^^^^^^^^^^^^^^^^^^^^^
     File "/home/carla/Documents/tvm/python/tvm/relax/block_builder.py", line 
667, in normalize
       return _ffi_api.BlockBuilderNormalize(self, expr)  # type: ignore
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "tvm/ffi/cython/./function.pxi", line 228, in 
tvm.ffi.core.Function.__call__
   tvm.error.InternalError: In Op(relax.less), the first input shape at dim 0 
is T.int64(3) and the second input shape at dim 3 is T.int64(5), which are not 
broadcastable.
   [17:27:21] /home/carla/Documents/tvm/src/relax/ir/block_builder.cc:64: 
Warning: BlockBuilder destroyed with remaining blocks!
   
   ```
   
   The Less operator supports multidirectional (i.e., Numpy-style) 
broadcasting. Hence, the inputs A and B should be broadcastable.
   I also using numpy to verify that A and B is broadcastable for the less 
operation, the results are as follows, which has the same shapes in the model:
   
![Image](https://github.com/user-attachments/assets/8f3de683-ebdd-48c7-89f8-bdf6838d72da)
   
   ### Environment
   
   OS: Ubuntu 20.04
   TVM: 0.21.dev0(eca92bd4f)
   
   ### 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, 
which indicates that the model is valid.
   ```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 test():
       onnx_model = onnx.load("11.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)
           
       print("ONNXRuntime:\n", ort_output)   
   
       tvm_model = from_onnx(onnx_model)
   
       
   if __name__ == "__main__":
       
       test()
   
   ```
   
   
[testcase.zip](https://github.com/user-attachments/files/20552044/testcase.zip)
   
   ### Triage
   
   * needs-triage
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to