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

   ### Expected behavior
   
   `tvm.relax.frontend.onnx.from_onnx()` should successfully import any valid 
ONNX model, including `Min` with two constant inputs. The imported Relax IR 
module should represent the correct elementwise minimum computation.
   
   ### Actual behavior
   
   `from_onnx()` crashes with a `TypeError` during the `Min` operator 
conversion:
   
   ```
   Error converting operator Min, with inputs: 
[metadata["relax.expr.Constant"][0]
   # Metadata omitted. Use show_meta=True in script() method to show it., 
metadata["relax.expr.Constant"][0]
   # Metadata omitted. Use show_meta=True in script() method to show it.]
   
   TypeError: only integer scalar arrays can be converted to a scalar index
   ```
   
   ### Environment
   
   - **OS**: Linux (x86_64, conda environment)
   - **GPU**: NVIDIA GeForce RTX 3080 Ti (12GB VRAM, CUDA 580.76.05)
   - **TVM version**: 0.25.0.post1
   - **Target**: `cuda` (GPU compilation)
   - **Python**: 3.12
   
   ### Steps to reproduce
   
   ```python
   from onnx import helper, TensorProto
   import onnxruntime as ort
   import numpy as np
   
   c1 = helper.make_tensor("c1_v", TensorProto.FLOAT, [2], [1.0, 2.0])
   c2 = helper.make_tensor("c2_v", TensorProto.FLOAT, [2], [3.0, 4.0])
   v_out = helper.make_tensor_value_info('v_out', TensorProto.FLOAT, [2])
   
   n1 = helper.make_node('Constant', inputs=[], outputs=['c1'], value=c1)
   n2 = helper.make_node('Constant', inputs=[], outputs=['c2'], value=c2)
   n3 = helper.make_node('Min', inputs=['c1', 'c2'], outputs=['v_out'])
   
   _graph = helper.make_graph([n1, n2, n3], 'min_const', [], [v_out])
   _model = helper.make_model(_graph, opset_imports=[helper.make_opsetid('', 
11)])
   
   np.random.seed(42)
   _sess = ort.InferenceSession(_model.SerializeToString(), 
providers=['CPUExecutionProvider'])
   _result = _sess.run(None, {})
   
   from tvm.relax.frontend.onnx import from_onnx
   mod = from_onnx(_model)
   ```
   
   ```txt
   Error converting operator Min, with inputs: 
[metadata["relax.expr.Constant"][0]
   # Metadata omitted. Use show_meta=True in script() method to show it., 
metadata["relax.expr.Constant"][0]
   # Metadata omitted. Use show_meta=True in script() method to show it.]
   Traceback (most recent call last):
     File 
"/root/autodl-tmp/data/maybeBug/onnx-tvm-cpu-scalar-index-001/reduced_minimal.py",
 line 15, in <module>
       mod = from_onnx(_model)
             ^^^^^^^^^^^^^^^^^
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/tvm/relax/frontend/onnx/onnx_frontend.py",
 line 5864, in from_onnx
       return g.from_onnx(graph, opset)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/tvm/relax/frontend/onnx/onnx_frontend.py",
 line 5393, in from_onnx
       self._construct_nodes(graph)
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/tvm/relax/frontend/onnx/onnx_frontend.py",
 line 5602, in _construct_nodes
       raise err
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/tvm/relax/frontend/onnx/onnx_frontend.py",
 line 5596, in _construct_nodes
       op = self._convert_operator(op_name, inputs, attr, self.opset)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/tvm/relax/frontend/onnx/onnx_frontend.py",
 line 5696, in _convert_operator
       sym = op_function(self.bb, inputs, attrs, [self._nodes, self._params])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/tvm/relax/frontend/onnx/onnx_frontend.py",
 line 2253, in _impl_v1
       output = cls.numpy_op(*np_inputs)  # pylint: disable=not-callable
                ^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/numpy/_core/fromnumeric.py",
 line 3299, in min
       return _wrapreduction(a, np.minimum, 'min', axis, None, out,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/root/miniconda3/envs/aifuzzer/lib/python3.12/site-packages/numpy/_core/fromnumeric.py",
 line 83, in _wrapreduction
       return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   TypeError: only integer scalar arrays can be converted to a scalar index
   [19:59:47] /project/src/relax/ir/block_builder.cc:66: Warning: BlockBuilder 
destroyed with remaining blocks!
   ```
   
   ### Triage
   
   * frontend:onnx
   * 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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to