Skip to content

[Fix][TOPI] Handle empty half-pixel resize outputs - #21102

Open
Nanmur wants to merge 1 commit into
apache:mainfrom
Nanmur:codex/fix-resize-empty-output
Open

Nanmur wants to merge 1 commit into
apache:mainfrom
Nanmur:codex/fix-resize-empty-output

Conversation

@Nanmur

@Nanmur Nanmur commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #20876.

Problem

get_inx constructs image_width / target_width before any output coordinates are evaluated. A statically empty output axis therefore raises divide-by-zero while constructing the TE body, even though its iteration domain has no elements to sample. This prevents valid empty half-pixel Resize results from being lowered.

Change

When equal_const_int(target_width, 0) proves that the output axis is empty, use a zero placeholder scale instead of constructing the division. Nonzero and general symbolic extents retain the original expression. Output shape, output dtype, and the existing operator validation paths are unchanged.

This targets empty half-pixel output construction. It does not implement sampling from an empty input into a nonempty output or change the separate unit-extent tf_crop_and_resize branch.

Regression tests

  • ONNX Resize-11 with positive scales and zero input height, width, or both; nearest/linear interpolation and float16/float32.
  • Equivalent nonempty constant-one controls with exact output shape, dtype, and value checks.
  • Direct TOPI 1D/2D/3D execution through Relax call_te, including NCW, NCHW, NHWC, and NCDHW; default and explicit output dtype.
  • Structural checks that ordinary positive and general symbolic half-pixel coordinate expressions remain unchanged.

Local validation

  • Unmodified main TOPI resize module: 20 failed, 14 passed, with the 20 empty-output cases reproducing divide-by-zero.
  • Patched module: 34 passed (32 LLVM/VM execution tests plus 2 coordinate-expression structural checks).
  • Ruff 0.12.3 check/format and git diff --check passed.

The main TOPI resize Python module was loaded verbatim into an existing local TVM 0.26.dev0 LLVM runtime, with compatibility aliases kept outside the PR. This is not a full current-main rebuild or full-suite result; upstream CI is required.

For a current-main build:

python -m pytest tests/python/relax/test_frontend_onnx_resize_empty.py -q

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Relax][TOPI] Empty half_pixel Resize constructs a zero-divisor coordinate before generating an empty result

1 participant