Skip to content

[Relax][ONNX] Support align_corners in AffineGrid op#19864

Merged
cbalint13 merged 1 commit into
mainfrom
fix/onnx-affinegrid-align-corners
Jun 22, 2026
Merged

[Relax][ONNX] Support align_corners in AffineGrid op#19864
cbalint13 merged 1 commit into
mainfrom
fix/onnx-affinegrid-align-corners

Conversation

@guan404ming

@guan404ming guan404ming commented Jun 22, 2026

Copy link
Copy Markdown
Member

Related Issue

closes #19690

Why

ONNX AffineGrid carries an align_corners attribute, but the Relax op ignored it and always produced the align_corners=1 grid.

How

  • Add align_corners field to AffineGridAttrs (mirrors GridSampleAttrs).
  • Thread the flag through the op, legalize pass, and TOPI compute.
  • Pass the ONNX attribute through in the frontend instead of dropping it.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for the align_corners attribute in the Relax affine_grid operator, allowing both corner-aligned and pixel-center-aligned coordinate mappings. This enables full support for ONNX's default align_corners=0 behavior. The feedback suggests removing a redundant bool() conversion in the legalization pass and relaxing an assertion in the TOPI implementation that restricts target dimensions to be greater than 1, which is only necessary when align_corners is enabled.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/tvm/relax/transform/legalize_ops/image.py Outdated
Comment thread python/tvm/topi/image/grid_sample.py
@guan404ming
guan404ming force-pushed the fix/onnx-affinegrid-align-corners branch from 5cb3fe1 to c342721 Compare June 22, 2026 07:09
@guan404ming
guan404ming requested review from cbalint13 and tlopex June 22, 2026 09:08

@cbalint13 cbalint13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks @guan404ming !

@cbalint13
cbalint13 merged commit 4650887 into main Jun 22, 2026
12 checks passed
@guan404ming

Copy link
Copy Markdown
Member Author

Thanks @cbalint13!

@guan404ming
guan404ming deleted the fix/onnx-affinegrid-align-corners branch June 22, 2026 09:59
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][ONNX] AffineGrid with align_corners=0 (the ONNX default!) is unsupported

2 participants