gemini-code-assist[bot] commented on code in PR #19674:
URL: https://github.com/apache/tvm/pull/19674#discussion_r3357196463
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -4531,7 +4531,12 @@ class Sign(OnnxOpConverter):
@classmethod
def _impl_v9(cls, bb, inputs, attr, params):
- return relax.op.sign(inputs[0])
+ x = inputs[0]
+ x_dtype = getattr(getattr(x, "struct_info", None), "dtype", None) or
getattr(x, "dtype", None)
+ y = relax.op.sign(x)
+ if x_dtype is not None and _relax_dtype_is_floating_point(x_dtype):
+ return relax.op.where(relax.op.isnan(x), x, y)
+ return y
Review Comment:

The extraction of `x_dtype` using nested `getattr` and `or getattr(x,
"dtype", None)` is overly complex and contains dead code, as `relax.Expr` does
not have a direct `dtype` attribute. We can simplify this by directly checking
if `x.struct_info` is an instance of `relax.TensorStructInfo` and extracting
its `dtype`, which is the standard and idiomatic way in TVM Relax.
```suggestion
x = inputs[0]
x_dtype = x.struct_info.dtype if isinstance(x.struct_info,
relax.TensorStructInfo) else None
y = relax.op.sign(x)
if x_dtype is not None and _relax_dtype_is_floating_point(x_dtype):
return relax.op.where(relax.op.isnan(x), x, y)
return y
```
--
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]