You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "cchung100m (via GitHub)" <gi...@apache.org> on 2026/06/09 15:56:41 UTC

[PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

cchung100m opened a new pull request, #19698:
URL: https://github.com/apache/tvm/pull/19698

   Hi Committers,
   
   This PR fixes issues https://github.com/apache/tvm/issues/19570. Any suggestions would be appreciated if you are available.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-4912114231

   cc @tlopex  @guan404ming 


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5675144316

   Hi @tlopex 
   Thanks for catching this. You are right that disabling the fast path for every explicit scale was too aggressive. I've updated the fix so the integer-division path is only skipped when the explicit scale actually disagrees with the ratio implied by the sizes; when it agrees (as in your example), it's still used and gives the exact result.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19698:
URL: https://github.com/apache/tvm/pull/19698#discussion_r3382065667


##########
python/tvm/topi/image/resize.py:
##########
@@ -856,6 +881,8 @@ def compute_func(*indices):
             exclude_outside=bicubic_exclude,
             extrapolation_value=extrapolation_value,
             out_dtype=out_dtype,
+            scale_h = scale_h,
+            scale_w = scale_w,

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   According to PEP 8, there should be no spaces around the `=` sign when used to indicate a keyword argument.
   
   ```python
               scale_h=scale_h,\n            scale_w=scale_w,
   ```



##########
python/tvm/topi/image/resize.py:
##########
@@ -145,9 +145,13 @@ def get_inx(
     start_x=0,
     end_x=-1,
     use_int_div=False,
+    scale_x_override=None,
 ):
     """Infer input x from output x with various coordinate transformation methods"""
-    scale_x = te.div(image_width.astype("float"), target_width.astype("float"))
+    if scale_x_override is not None:
+        scale_x = sacle_x_override

Review Comment:
   ![critical](https://www.gstatic.com/codereviewagent/critical.svg)
   
   There is a typo in the variable name here. `sacle_x_override` should be `scale_x_override`. This will cause a `NameError` at runtime when `scale_x_override` is provided.
   
   ```suggestion
           scale_x = scale_x_override
   ```



##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -3230,14 +3230,18 @@ def _impl_v18(cls, bb, inputs, attr, params):
 
         use_dynamic_roi = roi_dynamic_vec is not None
 
-        # Convert scales to sizes if needed.
+        # Convert scales to sizes if needed, preserving the orginal spatial scales so
+        # the coordinate transformation uses the exact ONNX scale value rather than the
+        # lossy ratio derived from floor(input * scale) / input.
+        original_spatial_scales = None
         if scales is not None:
             if isinstance(scales, relax.Constant):
                 scales = scales.data.numpy()
             elif isinstance(scales, relax.expr.ShapeExpr):
                 scales = [int(val.value) for val in scales.values]
             else:
                 raise ValueError(f"Type {type(scales)} for scale is currently unsupported.")
+            original_spatial_scales = list(scales[2:])

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The variable `original_spatial_scales` is defined and populated here but is never used or passed to any of the resize operators (`topi.image.resize1d`, `relax.op.image.resize2d`, or `relax.op.image.resize3d`).\n\n- For `ndims == 3`, you should pass `scales=original_spatial_scales` to `bb.emit_te(topi.image.resize1d, ...)`.\n- For `ndims == 4` and `ndims == 5`, the Relax operators `relax.op.image.resize2d` and `relax.op.image.resize3d` do not accept a `scales` parameter. If `scales` is provided, you may need to fallback to emitting the TE operations directly via `bb.emit_te(topi.image.resize2d, ...)` and `bb.emit_te(topi.image.resize3d, ...)` to ensure the scales are propagated, or update the Relax operators to support scales.



-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5305892925

   Hi @tlopex 
   Thanks for the feedback. I've addressed the issue "use sizes or add a TOPI test without scales" by implementing three direct TOPI-level tests that call topi.image.resize2d directly. These tests:
   1. Verify the int-div optimization fires when scales=None and the size ratio is an integer
   2. Verify the optimization is correctly disabled when an explicit (non-integer) scale override is provided.
   3. Verify the optimization is behavior-preserving for integer scale overrides


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5629843542

   Sorry for the late reply. Could we preserve the integer-division path when the explicit scale matches the integer output/input ratio? Disabling it for all explicit scales introduces a numerical regression.
   
   For input shape `(1, 1, 1, 411)`, scales `[1, 1, 1, 41]`, and `nearest/asymmetric/floor`, output index `16810` should read input index `410`. The reciprocal multiplication produces approximately `409.99997`, so it reads index `409` instead.
   
   I reproduced this with the C backend: the base revision matches ONNX Runtime, while this PR fails. Please retain exact integer indexing for this case.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5059438304

   > [!CAUTION]
   > The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.
   


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19698:
URL: https://github.com/apache/tvm/pull/19698#discussion_r3397212963


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -3230,14 +3230,18 @@ def _impl_v18(cls, bb, inputs, attr, params):
 
         use_dynamic_roi = roi_dynamic_vec is not None
 
-        # Convert scales to sizes if needed.
+        # Convert scales to sizes if needed, preserving the orginal spatial scales so
+        # the coordinate transformation uses the exact ONNX scale value rather than the
+        # lossy ratio derived from floor(input * scale) / input.

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   There is a typo in the comment: 'orginal' should be 'original'.
   
   ```suggestion
           # Convert scales to sizes if needed, preserving the original spatial scales so
           # the coordinate transformation uses the exact ONNX scale value rather than the
           # lossy ratio derived from floor(input * scale) / input.
   ```



-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5071068334

   Hi @tlopex 
   
   Thank you for the detailed review. I have implemented regression tests as requested.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-4682259199

   /gemini review


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5316455174

   Failed to re-run CI in https://github.com/apache/tvm/actions/runs/32032583932
   
   <details>
   
   ```
   Traceback (most recent call last):
     File "/home/runner/work/tvm/tvm/ci/scripts/github/github_tvmbot.py", line 588, in comment_failure
       raise item
     File "/home/runner/work/tvm/tvm/ci/scripts/github/github_tvmbot.py", line 694, in run
       pr.rerun_jenkins_ci()
     File "/home/runner/work/tvm/tvm/ci/scripts/github/github_tvmbot.py", line 547, in rerun_jenkins_ci
       post(url, auth=("tvm-bot", TVM_BOT_JENKINS_TOKEN))
     File "/home/runner/work/tvm/tvm/ci/scripts/jenkins/git_utils.py", line 54, in post
       with request.urlopen(req, data) as response:
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/usr/lib/python3.12/urllib/request.py", line 215, in urlopen
       return opener.open(url, data, timeout)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File "/usr/lib/python3.12/urllib/request.py", line 521, in open
       response = meth(req, response)
                  ^^^^^^^^^^^^^^^^^^^
     File "/usr/lib/python3.12/urllib/request.py", line 630, in http_response
       response = self.parent.error(
                  ^^^^^^^^^^^^^^^^^^
     File "/usr/lib/python3.12/urllib/request.py", line 559, in error
       return self._call_chain(*args)
              ^^^^^^^^^^^^^^^^^^^^^^^
     File "/usr/lib/python3.12/urllib/request.py", line 492, in _call_chain
       result = func(*args)
                ^^^^^^^^^^^
     File "/usr/lib/python3.12/urllib/request.py", line 639, in http_error_default
       raise HTTPError(req.full_url, code, msg, hdrs, fp)
   urllib.error.HTTPError: HTTP Error 502: Bad Gateway
   
   ```
   
   with response
   
   ```
   <html>
   <head><title>502 Bad Gateway</title></head>
   <body>
   <center><h1>502 Bad Gateway</h1></center>
   </body>
   </html>
   
   ```
   
   </details>


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19698:
URL: https://github.com/apache/tvm/pull/19698#discussion_r3397212974


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -3295,6 +3315,21 @@ def _impl_v18(cls, bb, inputs, attr, params):
             )
         else:  # ndims == 5
             roi3d = _topi_resize3d_roi_from_onnx_ncdhw_spatial(roi_static)
+            if original_spatial_scales is not None:
+                return bb.emit_te(
+                    topi.image.resize3d,
+                    x,
+                    roi3d,
+                    sizes,
+                    "NCDHW",
+                    relax_mode,

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For consistency with the 1D and 2D resize implementations (which use `topi_mode`), we should pass `topi_mode` here instead of `relax_mode`.
   
   ```suggestion
                       topi_mode,
   ```



-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5183934392

   @cchung100m  Hey, the updated test does not exercise the integer-division optimization because providing `scales` makes `scale_h` and `scale_w` non-`None`, so the optimized path is skipped. Please use `sizes` or add a TOPI test without `scales`.


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [Relax][Frontend][ONNX] Fix Resize coordinate error with non-integer scales [tvm]

Posted by "cchung100m (via GitHub)" <gi...@apache.org>.
cchung100m commented on PR #19698:
URL: https://github.com/apache/tvm/pull/19698#issuecomment-5316367734

   @tvm-bot  rerun


-- 
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: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org