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


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -1814,13 +1817,42 @@ def _impl_v1(cls, bb, inputs, attr, params):
             padding=attr.get("pads", 0),
             output_padding=output_padding,
             dilation=dilations,
-            groups=attr.get("group", 1),
+            groups=groups,
             data_layout=data_layout,
             kernel_layout=kernel_layout,
         )
 
         if inputs[2] is not None:
-            bias = relax.op.reshape(inputs[2], [1, -1] + [1] * (ndim - 2))
+            bias_shape = inputs[2].struct_info.shape
+            if hasattr(inputs[2].struct_info, "ndim"):
+                bias_ndim = inputs[2].struct_info.ndim
+            else:
+                bias_ndim = len(bias_shape)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Using `hasattr(inputs[2].struct_info, "ndim")` to check for the presence of 
`ndim` is safe, but if `inputs[2].struct_info` does not have `ndim` and 
`bias_shape` is `None` (which can happen if the shape is completely 
dynamic/unknown), calling `len(bias_shape)` will raise a `TypeError`. We should 
add a fallback or check to ensure `bias_shape` is not `None` before calling 
`len()` on it.
   
   ```suggestion
               if hasattr(inputs[2].struct_info, "ndim") and 
inputs[2].struct_info.ndim is not None:
                   bias_ndim = inputs[2].struct_info.ndim
               elif bias_shape is not None:
                   bias_ndim = len(bias_shape)
               else:
                   bias_ndim = -1
   ```



##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -1814,13 +1817,42 @@ def _impl_v1(cls, bb, inputs, attr, params):
             padding=attr.get("pads", 0),
             output_padding=output_padding,
             dilation=dilations,
-            groups=attr.get("group", 1),
+            groups=groups,
             data_layout=data_layout,
             kernel_layout=kernel_layout,
         )
 
         if inputs[2] is not None:
-            bias = relax.op.reshape(inputs[2], [1, -1] + [1] * (ndim - 2))
+            bias_shape = inputs[2].struct_info.shape
+            if hasattr(inputs[2].struct_info, "ndim"):
+                bias_ndim = inputs[2].struct_info.ndim
+            else:
+                bias_ndim = len(bias_shape)
+            if bias_ndim != 1:
+                raise ValueError(f"ConvTranspose bias must be a 1D tensor, but 
got ndim={bias_ndim}")
+
+            def _as_static_int(dim):
+                try:
+                    return int(dim)
+                except (TypeError, ValueError, TVMError):
+                    return None

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `_as_static_int` helper catches `TVMError`, but in some environments or 
FFI boundaries, TVM might raise a standard `RuntimeError` or other custom 
exceptions. To make this helper more robust and prevent unexpected compilation 
failures, we should also catch `RuntimeError`.
   
   ```suggestion
               def _as_static_int(dim):
                   try:
                       return int(dim)
                   except (TypeError, ValueError, RuntimeError, TVMError):
                       return None
   ```



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