gemini-code-assist[bot] commented on code in PR #19566:
URL: https://github.com/apache/tvm/pull/19566#discussion_r3241008241


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -526,7 +538,38 @@ class Div(BinaryBase):
 
     @classmethod
     def _impl_v7(cls, bb, inputs, attr, params):
-        return cls.base_impl(bb, inputs, attr, params)
+        lhs_dtype = inputs[0].struct_info.dtype
+        rhs_dtype = inputs[1].struct_info.dtype
+
+        try:
+            lhs_code = DataType(lhs_dtype).type_code
+            rhs_code = DataType(rhs_dtype).type_code
+        except (ValueError, TypeError, TVMError):
+            return cls.base_impl(bb, inputs, attr, params)
+
+        lhs_is_integer = lhs_code == DataTypeCode.INT or lhs_code == 
DataTypeCode.UINT
+        rhs_is_integer = rhs_code == DataTypeCode.INT or rhs_code == 
DataTypeCode.UINT
+        if not (lhs_is_integer and rhs_is_integer):
+            return cls.base_impl(bb, inputs, attr, params)
+
+        rhs_has_zero = _const_integer_expr_has_zero(inputs[1])
+        if rhs_has_zero:
+            return ValueError("ONNX Div with integer inputs encountered 
divisor value 0.")

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The operator converter should `raise` the `ValueError` instead of returning 
it. Returning an exception object will cause the frontend to fail later with a 
cryptic error (e.g., when trying to access `struct_info` on the exception 
object) instead of providing a clear error message during the model import 
process.
   
   ```suggestion
               raise ValueError("ONNX Div with integer inputs encountered 
divisor value 0.")
   ```



-- 
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