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


##########
python/tvm/tir/op.py:
##########
@@ -2116,6 +2116,8 @@ def exp(x):
         The result.
     """
     x = tir.convert(x)
+    if "int" in x.dtype:
+        x = tir.Cast("float32", x)

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Hardcoding the cast to `float32` can lead to overflow for large integer 
inputs (e.g., from an `int64` type). For example, `exp(100)` overflows 
`float32` but fits in `float64`.
   
   To prevent potential overflow and precision loss, and to better align with 
the behavior of libraries like NumPy and PyTorch which promote integers to 
`float64` for exponential functions, it would be safer to cast to `float64`.
   
   ```suggestion
           x = tir.Cast("float64", x)
   ```



##########
tests/python/relax/test_transform_legalize_ops_unary.py:
##########
@@ -85,6 +85,7 @@ def main(x: R.Tensor(("m", "n"), dtype)):
         ("cos", R.cos, topi.cos, "float32"),
         ("cosh", R.cosh, topi.cosh, "float32"),
         ("exp", R.exp, topi.exp, "float32"),
+        ("exp", R.exp, topi.exp, "int32"),

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   It's great that you've added a test case for `int32`. To ensure full 
coverage for integer types, especially concerning potential precision and 
overflow issues with larger integers, please also add a test case for `int64`. 
This is particularly important if the implementation is updated to cast to 
`float64` to handle a wider range of integer inputs.
   
   ```suggestion
           ("exp", R.exp, topi.exp, "int32"),
           ("exp", R.exp, topi.exp, "int64"),
   ```



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