Skip to content

Set exclude_outside=1 on Resize for antialiased upsample#2916

Open
ssam18 wants to merge 2 commits into
microsoft:mainfrom
ssam18:fix/issue-pytorch-183546-aa-exclude-outside
Open

Set exclude_outside=1 on Resize for antialiased upsample#2916
ssam18 wants to merge 2 commits into
microsoft:mainfrom
ssam18:fix/issue-pytorch-183546-aa-exclude-outside

Conversation

@ssam18
Copy link
Copy Markdown

@ssam18 ssam18 commented May 13, 2026

F.interpolate with antialias=True did not match PyTorch eager after ONNX export. The cause is that ONNX Resize defaults exclude_outside=0 while PyTorch's eager kernels drop out of bounds samples and renormalize the filter weights to sum to one. This change threads exclude_outside=1 through _aten_upsample_output_size and _aten_upsample_scales and sets it for the bilinear and bicubic AA paths. The shape only test guard for the two AA upsample ops is removed so the existing numerical comparison runs again.

Fixes pytorch/pytorch#183546.

ONNX Resize defaults exclude_outside=0 while PyTorch's antialiased upsample kernels drop out of bounds samples from the filter window and renormalize the remaining weights so they sum to one. Without exclude_outside=1 the exported model produces values that differ from eager near the boundary. This also drops the shape only test guard for the AA upsample ops so the existing numerical comparison runs again.

Fixes pytorch/pytorch#183546.
@ssam18
Copy link
Copy Markdown
Author

ssam18 commented May 13, 2026

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Collaborator

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@justinchuby justinchuby added the module: torchlib Related to the torch/aten function lib in development label May 18, 2026
@justinchuby justinchuby enabled auto-merge (squash) May 18, 2026 17:06
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.61%. Comparing base (029441f) to head (cba8e85).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2916   +/-   ##
=======================================
  Coverage   72.61%   72.61%           
=======================================
  Files         259      259           
  Lines       31597    31597           
  Branches     2973     2973           
=======================================
  Hits        22945    22945           
  Misses       7643     7643           
  Partials     1009     1009           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

The exclude_outside=1 change fixes the align_corners=False / no-scales path. Two cases still diverge: align_corners=True (the AA scale formula differs between PyTorch and ONNX Resize) and align_corners=False with explicit scales_h/scales_w (PyTorch ignores the scales, ONNX honors them same pre-existing mismatch already xfailed on the non-AA variants). Add matching .xfail matchers on both _upsample_bilinear2d_aa and _upsample_bicubic2d_aa so CI is green while the remaining gaps stay tracked.
auto-merge was automatically disabled May 18, 2026 18:30

Head branch was pushed to by a user without write access

Comment thread tests/function_libs/torch_lib/ops_test_data.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: torchlib Related to the torch/aten function lib in development

Projects

Development

Successfully merging this pull request may close these issues.

ONNX export of F.interpolate(..., antialias=True) does not preserve PyTorch eager semantics

2 participants