Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xnnpack execution provider Resize::IsOnnxNodeSupported causes crash for models where Resize layer scales tensor is an empty tensor #23886

Open
pl121lp opened this issue Mar 4, 2025 · 2 comments
Labels
ep:Xnnpack issues related to XNNPACK EP platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@pl121lp
Copy link

pl121lp commented Mar 4, 2025

Describe the issue

onnxruntime/core/providers/xnnpack/tensor/resize.cc:69 (const auto scales = scale_val.DataAsSpan();)
results in crash if scales tensor is an empty tensor.
This is the case from some onnx models where both scales and sizes tensor is provided. In this case scales is an empty tensor and size tensor has data. See attached netron visualization clip from the model.
Image

Applying a condition (e.g. "if(scale_val.size() > 1) {" ) to check size of scales resolves this issue. I suggest this fix is introduced.

To reproduce

I cannot not share proprietary model.

Urgency

No response

Platform

Android

OS Version

Any recent version

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1ffe793

ONNX Runtime API

C++

Architecture

ARM64

Execution Provider

Other / Unknown

Execution Provider Library Version

xnnpack

@github-actions github-actions bot added ep:Xnnpack issues related to XNNPACK EP platform:mobile issues related to ONNX Runtime mobile; typically submitted using template labels Mar 4, 2025
@skottmckay
Copy link
Contributor

Your model does not conform to the ONNX spec for Resize. You cannot provide both scales and sizes. Pass an empty string (which indicates a missing optional input) and not an empty tensor for scales.

https://github.com/onnx/onnx/blob/main/docs/Operators.md#inputs-1---4

scales (optional, non-differentiable) : tensor(float)
The scale array along each dimension. It takes value greater than 0. If it's less than 1, it's sampling down, otherwise, it's upsampling. The number of elements of 'scales' should be the same as the rank of input 'X' or the length of 'axes', if provided. One of 'scales' and 'sizes' MUST be specified and it is an error if both are specified. If 'sizes' is needed, the user can use an empty string as the name of 'scales' in this operator's input list.
sizes (optional, non-differentiable) : tensor(int64)
Target size of the output tensor. Its interpretation depends on the 'keep_aspect_ratio_policy' value.The number of elements of 'sizes' should be the same as the rank of input 'X', or the length of 'axes', if provided. Only one of 'scales' and 'sizes' can be specified.

@pl121lp
Copy link
Author

pl121lp commented Mar 5, 2025

Right, I concur that the model does not adhere to spec.
However, note that the model can run just just fine using the default CPUExecutionProvider.
This means that the default code path does have the ability to handle this case (even though IR is deviation from spec).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:Xnnpack issues related to XNNPACK EP platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

No branches or pull requests

2 participants