Skip to content

[Fix][TOPI] Handle singleton align-corners resize axes - #20992

Open
DiadkoShmek wants to merge 1 commit into
apache:mainfrom
DiadkoShmek:DiadkoShmek/fix-resize-align-corners-singleton
Open

DiadkoShmek wants to merge 1 commit into
apache:mainfrom
DiadkoShmek:DiadkoShmek/fix-resize-align-corners-singleton

Conversation

@DiadkoShmek

Copy link
Copy Markdown

Fixes #20941.

TOPI's shared align_corners mapping divides by output_extent - 1. At a singleton extent, constant folding rejects the zero denominator for static shapes, and the symbolic kernel can produce NaN instead of sampling input coordinate zero.

Clamp the denominator to one. A singleton axis executes only at output coordinate zero, so the resulting input coordinate is zero. Extents greater than one keep the existing mapping.

On base 23a6dbe710dfcd445a090af1c49c8d7e8a57fb10, four static torch.export cases failed with division by zero, while both controls passed. The new symbolic 1D test emitted NaN instead of zero. All seven new regressions and all 31 existing resize/interpolate checks passed on the patch. An additional CPU run compiled one symbolic TOPI kernel per rank and checked nine 1D/3D output shapes against separable NumPy interpolation. Five singleton-containing shapes disagreed on the base. All nine matched exactly with the patch.

AI assistance (Codex) was used for the patch, tests, and verification.

Clamp the resize coordinate scale denominator to one so a singleton axis maps its only sample to input coordinate zero, for both static and symbolic output extents.

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] interpolate(mode="bilinear", align_corners=True) to an output size of 1 fails in tvm.compile: "Divide by zero"

1 participant