Skip to content

[onnx] Accept keep_aspect_ratio_policy=stretch in Resize parser#4875

Open
itikhono wants to merge 2 commits into
ROCm:developfrom
itikhono:develop
Open

[onnx] Accept keep_aspect_ratio_policy=stretch in Resize parser#4875
itikhono wants to merge 2 commits into
ROCm:developfrom
itikhono:develop

Conversation

@itikhono
Copy link
Copy Markdown

Motivation

Parsing ONNX models exported at opset 18 failed with:

PARSE_RESIZE: keep_aspect_ratio_policy is not supported!

ONNX Runtime injects the schema default keep_aspect_ratio_policy="stretch" into every Resize-18 node during graph verification before the subgraph reaches MIGraphX. Ultralytics YOLO models (torch >= 2.4) export at opset 18 and contain nn.Upsample / Resize nodes, so inference via the ORT MIGraphX EP broke on all such models.

Technical Details

"stretch" is the Resize-18 default and is semantically identical to the pre-18 per-axis resizing already implemented. It is a no-op.set_aspect_ratio_policy now returns early for "stretch"; unsupported policies ("not_larger", "not_smaller") with a sizes input still throw.

Two test changes:

  • resize_aspect_ratio_err_test: policy corrected to "not_larger" (the actual unsupported case).
  • resize_aspect_ratio_stretch_test: new positive test that "stretch" + sizes parses successfully and produces the expected IR. Fails without the fix, passes with it.

Changelog Category

  • Resolved Issues

Copilot AI review requested due to automatic review settings May 12, 2026 12:34
@itikhono itikhono requested a review from causten as a code owner May 12, 2026 12:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the ONNX Resize parser to accept keep_aspect_ratio_policy="stretch" (the opset-18 default) as a no-op so opset-18 models verified by ONNX Runtime can be parsed successfully in MIGraphX.

Changes:

  • Updated parse_resize to early-return when keep_aspect_ratio_policy is absent or equals "stretch", while still rejecting unsupported policies when the sizes input is used.
  • Adjusted the existing negative test generator to use an actually-unsupported policy ("not_larger").
  • Added a new positive test case covering "stretch" + sizes.

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/onnx/parse_resize.cpp Treats keep_aspect_ratio_policy="stretch" as a no-op while preserving the existing error behavior for unsupported policies with sizes.
test/onnx/gen_onnx.py Updates the negative Resize aspect-ratio test and adds a new ONNX generator for the "stretch" acceptance case.
test/onnx/parse/resize_aspect_ratio_stretch_test.cpp Adds a parse test asserting that "stretch" + sizes produces the expected MIGraphX IR.

Comment thread src/onnx/parse_resize.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated no new comments.

@itikhono
Copy link
Copy Markdown
Author

@causten could you review the PR please?
the Copilot review passed

Copy link
Copy Markdown
Collaborator

@TedThemistokleous TedThemistokleous 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 for your changes. two small comments.

Appreciate the work on stuff between opsets. If there's more overhead / issues we can discuss how to easily as the attributes aren't like input and may be cumbersome to deal with.

I already have an opset_version flag in this parser and we can leverage that to manage between old/new opsets for the additional attributes that like to move around between Onnx versions.

Comment thread src/onnx/parse_resize.cpp

// 'stretch' is the opset-18 default and matches the existing per-axis
// semantics, so accept it as a no-op.
if(attr.at("keep_aspect_ratio_policy").s() == "stretch")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can have these as one if here and remove the above not check. Less code paths for the check and using and will guarantee if first check fails the second wont need to get checked.

Suggested change
if(attr.at("keep_aspect_ratio_policy").s() == "stretch")
if(not contains(attr, "keep_aspect_ratio_policy") and attr.at("keep_aspect_ratio_policy").s() == "stretch")

Comment thread src/onnx/parse_resize.cpp
if(attr.at("keep_aspect_ratio_policy").s() == "stretch")
return;

// TODO: Add support for 'not_larger' and 'not_smaller' policies.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Make this an internal issue for us to track if this is a new TODO

@TedThemistokleous
Copy link
Copy Markdown
Collaborator

TedThemistokleous commented May 12, 2026

@itikhono is there an AIMIGRAPHX or some sort of other tag this is referring to? We can link the ticket by issue name via replacing [onnx] with the ticket identifier (No internal links please)

Copy link
Copy Markdown
Collaborator

@CharlieL7 CharlieL7 left a comment

Choose a reason for hiding this comment

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

LGTM. The TODO is rephrasing an old one we had. Not sure if it has been made into a github issue.

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.

5 participants