[BugFix][TOPI] fix resize accuracy issue#16137
Closed
JR4er wants to merge 3 commits into
Closed
Conversation
e653a93 to
2ca5438
Compare
Member
|
Thanks for the fix. Could you please also add a topi test? |
Contributor
Author
a simple test for this case is added. |
tqchen
approved these changes
Apr 1, 2024
Member
|
@tvm-bot rerun |
Contributor
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/10871950809 Detailswith response |
Member
|
@tvm-bot rerun |
Contributor
|
Failed to re-run CI in https://github.com/apache/tvm/actions/runs/13210185773 Detailswith response |
tqchen
added a commit
to tqchen/tvm
that referenced
this pull request
Feb 26, 2026
`can_convert_multiply_to_intdiv` was enabled unconditionally for `nearest_neighbor` + `asymmetric` mode, even when `rounding_method` is not `floor`. This converted the mapped coordinate via integer division (equivalent to floor) regardless of the requested rounding, producing wrong results whenever the target size is an exact integer multiple of the source size. Fix: guard the `can_convert_multiply_to_intdiv` optimisation so it only activates when `rounding_method` is `"floor"` or `""` (which defaults to `"floor"` for asymmetric mode). Also update the Python reference implementation (`resize_python.py`) to accept and thread a `rounding_method` parameter through all public entry points (`get_index`, `resize3d_nearest`, `resize3d_ncdhw`, `resize1d_python`, `resize2d_python`, `resize3d_python`), so the reference matches the corrected TVM behaviour. Add `tests/python/te/test_topi_resize2d.py` with regression tests that exercise the buggy path (non-floor rounding + asymmetric + integer scale factor) as well as sanity checks for floor rounding and non-integer scale factors. Fixes: apache#16137
tqchen
added a commit
to tqchen/tvm
that referenced
this pull request
Feb 26, 2026
`can_convert_multiply_to_intdiv` was enabled unconditionally for `nearest_neighbor` + `asymmetric` mode, even when `rounding_method` is not `floor`. This converted the mapped coordinate via integer division (equivalent to floor) regardless of the requested rounding, producing wrong results whenever the target size is an exact integer multiple of the source size. Fix: guard the `can_convert_multiply_to_intdiv` optimisation so it only activates when `rounding_method` is `"floor"` or `""` (which defaults to `"floor"` for asymmetric mode). Also update the Python reference implementation (`resize_python.py`) to accept and thread a `rounding_method` parameter through all public entry points (`get_index`, `resize3d_nearest`, `resize3d_ncdhw`, `resize1d_python`, `resize2d_python`, `resize3d_python`), so the reference matches the corrected TVM behaviour. Add `tests/python/te/test_topi_resize2d.py` with regression tests that exercise the buggy path (non-floor rounding + asymmetric + integer scale factor) as well as sanity checks for floor rounding and non-integer scale factors. Fixes: apache#16137
tqchen
added a commit
to tqchen/tvm
that referenced
this pull request
Feb 27, 2026
`can_convert_multiply_to_intdiv` was enabled unconditionally for `nearest_neighbor` + `asymmetric` mode, even when `rounding_method` is not `floor`. This converted the mapped coordinate via integer division (equivalent to floor) regardless of the requested rounding, producing wrong results whenever the target size is an exact integer multiple of the source size. Fix: guard the `can_convert_multiply_to_intdiv` optimisation so it only activates when `rounding_method` is `"floor"` or `""` (which defaults to `"floor"` for asymmetric mode). Also update the Python reference implementation (`resize_python.py`) to accept and thread a `rounding_method` parameter through all public entry points (`get_index`, `resize3d_nearest`, `resize3d_ncdhw`, `resize1d_python`, `resize2d_python`, `resize3d_python`), so the reference matches the corrected TVM behaviour. Add `tests/python/te/test_topi_resize2d.py` with regression tests that exercise the buggy path (non-floor rounding + asymmetric + integer scale factor) as well as sanity checks for floor rounding and non-integer scale factors. Fixes: apache#16137
tqchen
added a commit
to tqchen/tvm
that referenced
this pull request
Feb 27, 2026
`can_convert_multiply_to_intdiv` was enabled unconditionally for `nearest_neighbor` + `asymmetric` mode, even when `rounding_method` is not `floor`. This converted the mapped coordinate via integer division (equivalent to floor) regardless of the requested rounding, producing wrong results whenever the target size is an exact integer multiple of the source size. Fix: guard the `can_convert_multiply_to_intdiv` optimisation so it only activates when `rounding_method` is `"floor"` or `""` (which defaults to `"floor"` for asymmetric mode). Also update the Python reference implementation (`resize_python.py`) to accept and thread a `rounding_method` parameter through all public entry points (`get_index`, `resize3d_nearest`, `resize3d_ncdhw`, `resize1d_python`, `resize2d_python`, `resize3d_python`), so the reference matches the corrected TVM behaviour. Add `tests/python/te/test_topi_resize2d.py` with regression tests that exercise the buggy path (non-floor rounding + asymmetric + integer scale factor) as well as sanity checks for floor rounding and non-integer scale factors. Fixes: apache#16137
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"resize" result can be wrong if method="nearest_neighbor" and coordinate_transformation_mode="asymmetric" and rounding_method != "floor" and target_height, target_width = n * image_height, m * image_width (n,m are integers).
#12567
in buggy implementation:
can_convert_multiply_to_intdivreturnsTrueifscaled_sizeis n timesorigin_size, which will result in thatget_closest_indexconverts the mapped coordinate byastype('int32')without checkingrounding_method.in this implementation:
check
can_convert_multiply_to_intdivonly if method="nearest_neighbor" and coordinate_transformation_mode="asymmetric" and rounding_method == "floor"cc @Hzfengsy