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


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2632,6 +2632,91 @@ def _impl_v1(cls, bb, inputs, attr, params):
         return inputs[0]
 
 
+def _onnx_resize_spatial_roi_vector(roi_full: relax.Expr, rank: int) -> 
relax.Expr:
+    """Map ONNX ROI [starts..., ends...] to TOPI spatial ROI (drop N/C 
axes)."""
+    return relax.op.concat(
+        [
+            relax.op.strided_slice(roi_full, axes=[0], begin=[2], end=[rank]),
+            relax.op.strided_slice(roi_full, axes=[0], begin=[rank + 2], 
end=[2 * rank]),
+        ],
+        axis=0,
+    )
+
+
+def _emit_resize_topi_dynamic_roi(
+    bb: relax.BlockBuilder,
+    data: relax.Expr,
+    roi_spatial_vec: relax.Expr,
+    sizes_spatial: list,
+    rank: int,
+    topi_mode: str,
+    coord_mode: str,
+    rounding_method: str,
+    cubic_coeff_a: float,
+    exclude_outside: int,
+    extrapolation_value: float,
+) -> relax.Expr:
+    """Lower Resize with runtime ROI via TOPI, which supports Expr ROI."""
+    if rank == 3:
+
+        def resize1d_dyn(d, r, s0):
+            return topi.image.resize1d(
+                d,
+                (r[0], r[1]),
+                [s0],
+                "NCW",
+                topi_mode,
+                coord_mode,
+                rounding_method,
+                cubic_coeff_a,
+                exclude_outside,
+                extrapolation_value,
+            )
+
+        return bb.emit_te(resize1d_dyn, data, roi_spatial_vec, 
sizes_spatial[0])
+
+    if rank == 4:
+
+        def resize2d_dyn(d, r, s0, s1):
+            return topi.image.resize2d(
+                d,
+                (r[0], r[1], r[2], r[3]),
+                (s0, s1),
+                layout="NCHW",
+                method=topi_mode,
+                coordinate_transformation_mode=coord_mode,
+                rounding_method=rounding_method,
+                bicubic_alpha=cubic_coeff_a,
+                bicubic_exclude=exclude_outside,
+                extrapolation_value=extrapolation_value,
+            )
+
+        return bb.emit_te(resize2d_dyn, data, roi_spatial_vec, 
sizes_spatial[0], sizes_spatial[1])
+
+    def resize3d_dyn(d, r, s0, s1, s2):
+        return topi.image.resize3d(
+            d,
+            (r[0], r[1], r[2], r[3], r[4], r[5]),

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The ROI indices for 3D resize are incorrectly mapped. TOPI's `resize3d` 
implementation (in `topi/image/resize.py`) expects the ROI vector in the order 
`[start_w, start_h, start_d, end_w, end_h, end_d]`. However, 
`_onnx_resize_spatial_roi_vector` produces `[d1, h1, w1, d2, h2, w2]` for rank 
5. You need to reorder the indices when passing them to `topi.image.resize3d`.
   
   ```suggestion
               (r[2], r[1], r[0], r[5], r[4], r[3]),
   ```



##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2706,11 +2794,26 @@ def _impl_v18(cls, bb, inputs, attr, params):
             else:
                 assert f"Type {type(sizes)} for size is currently unsupported."

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   This assertion is invalid because a non-empty string literal is always 
truthy in Python, meaning the assertion will never trigger even if the code 
path is reached. It should be changed to `raise ValueError` or `assert False`.
   
   ```suggestion
                   raise ValueError(f"Type {type(sizes)} for size is currently 
unsupported.")
   ```



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