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


##########
python/tvm/relax/transform/legalize_ops/image.py:
##########
@@ -66,6 +66,7 @@ def _image_affine_grid(bb: BlockBuilder, call: Call) -> Expr:
         topi.image.affine_grid,
         call.args[0],
         target_shape=target_shape,
+        align_corners=bool(call.attrs.align_corners),

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `bool()` conversion is redundant here because `call.attrs.align_corners` 
is already a boolean value (as defined in `AffineGridAttrs`). We can simplify 
this to directly use `call.attrs.align_corners`.
   
   ```suggestion
           align_corners=call.attrs.align_corners,
   ```



##########
python/tvm/topi/image/grid_sample.py:
##########
@@ -47,13 +51,22 @@ def affine_grid(data, target_shape):
     )
 
     dtype = data.dtype
-    y_step = tirx.const((2.0 - 1e-7) / (target_shape[0] - 1), dtype=dtype)
-    x_step = tirx.const((2.0 - 1e-7) / (target_shape[1] - 1), dtype=dtype)
-    start = tirx.const(-1.0, dtype=dtype)
+    height, width = target_shape[0], target_shape[1]
+    if align_corners:

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   When `align_corners` is `False`, the target shape dimensions are allowed to 
be `1` because the pixel center mapping formula `(2 * i + 1) / size - 1` does 
not result in a division by zero (unlike the `align_corners=True` formula which 
divides by `size - 1`). However, the assertion on line 49 (`assert 
target_shape[0] > 1 and target_shape[1] > 1`) unconditionally restricts both 
dimensions to be greater than 1. Consider relaxing that assertion to only apply 
when `align_corners` is `True`.



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