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


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -3834,8 +3834,7 @@ def _impl_v17(cls, bb, inputs, attr, params):
         gamma_shape = get_const_tuple(scale.struct_info.shape)
 
         if bias is None:
-            seq_len = data.struct_info.shape[1].value
-            bias = relax.const([0.0] * seq_len, dtype="float32")
+            bias = relax.const(_np.zeros(gamma_shape, 
dtype=scale.struct_info.dtype))

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Using `_np.zeros(gamma_shape, dtype=scale.struct_info.dtype)` will raise a 
`TypeError: data type 'bfloat16' not understood` in standard NumPy environments 
when the dtype is `"bfloat16"`, as NumPy does not natively support `bfloat16` 
without external libraries like `ml_dtypes`.
   
   To prevent this, we should construct the NumPy array with a standard type 
like `"float32"` and pass the target dtype to `relax.const`, which natively 
supports `"bfloat16"` and handles the conversion correctly. This also aligns 
with the pattern mentioned in the PR description.
   
   ```suggestion
               bias = relax.const(_np.zeros(gamma_shape, dtype="float32"), 
dtype=scale.struct_info.dtype)
   ```



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