[onnx] Accept keep_aspect_ratio_policy=stretch in Resize parser#4875
[onnx] Accept keep_aspect_ratio_policy=stretch in Resize parser#4875itikhono wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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_resizeto early-return whenkeep_aspect_ratio_policyis absent or equals"stretch", while still rejecting unsupported policies when thesizesinput 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. |
|
@causten could you review the PR please? |
TedThemistokleous
left a comment
There was a problem hiding this comment.
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.
|
|
||
| // '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") |
There was a problem hiding this comment.
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.
| 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") |
| if(attr.at("keep_aspect_ratio_policy").s() == "stretch") | ||
| return; | ||
|
|
||
| // TODO: Add support for 'not_larger' and 'not_smaller' policies. |
There was a problem hiding this comment.
Make this an internal issue for us to track if this is a new TODO
|
@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) |
CharlieL7
left a comment
There was a problem hiding this comment.
LGTM. The TODO is rephrasing an old one we had. Not sure if it has been made into a github issue.
Motivation
Parsing ONNX models exported at opset 18 failed with:
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 containnn.Upsample/Resizenodes, 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_policynow returns early for"stretch"; unsupported policies ("not_larger","not_smaller") with asizesinput 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