-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[WebNN] Allow ops to handle ignoring an empty tensor as input #22972
Conversation
@fdwr, @guschmue, PTAL, thanks! cc/ @shiyi9801 |
That's illegal for ONNX models, and the model file should be fixed (along with whatever degenerate tool produced it), as
The documentation for Resize also says:
I also worry about applying this because an absent/missing tensor is conceptually distinct from a present but empty tensor, and this check makes the two cases indistinguishable, which matters because a missing tensor might have a default value that shouldn't be confused for an explicitly empty tensor. Does the CPU EP apply this hack? If so, that adds some weight to the decision, but if not, I'd really rather the model file be corrected. |
/azp run ONNX Runtime Web CI Pipeline,Windows GPU CI Pipeline,Linux Android Emulator QNN CI Pipeline |
/azp run Linux CPU CI Pipeline,Linux CPU Minimal Build E2E CI Pipeline,Linux GPU CI Pipeline,Linux GPU TensorRT CI Pipeline,Linux OpenVINO CI Pipeline,Linux QNN CI Pipeline,MacOS CI Pipeline,Windows ARM64 QNN CI Pipeline,Windows CPU CI Pipeline |
/azp run Windows GPU CUDA CI Pipeline,Windows GPU DML CI Pipeline,Windows GPU Doc Gen CI Pipeline |
/azp run Windows GPU TensorRT CI Pipeline,onnxruntime-binary-size-checks-ci-pipeline,orttraining-linux-ci-pipeline,orttraining-linux-gpu-ci-pipeline,orttraining-ortmodule-distributed,Windows x64 QNN CI Pipeline,Big Models |
Azure Pipelines successfully started running 2 pipeline(s). |
Azure Pipelines successfully started running 3 pipeline(s). |
Azure Pipelines successfully started running 4 pipeline(s). |
Azure Pipelines successfully started running 9 pipeline(s). |
onnxruntime/core/providers/webnn/builders/impl/base_op_builder.cc
Outdated
Show resolved
Hide resolved
I think so, I've encountered several such illegal models :(, but they can pass model initialization in ORT.
Assume that all initializers should either have shape information or have an empty tensor. That's the main reason why we skip checking the shape information for initializers here. Besides, we have additional validation for initializers in each op impl, if some op doesn't allow empty initializer, we do just fallback.
CPU EP firstly tries to get constant input, if it is empty tensor, it will use an internal default one. [1] https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/cpu/tensor/upsamplebase.h#L233 |
😥 Do you know the
or
|
e.g. model: https://github.com/onnx/models/blob/main/validated/vision/object_detection_segmentation/ssd-mobilenetv1/model/ssd_mobilenet_v1_13-qdq.onnx,
|
So then the CPU EP executes this model fine? Sigh.
:( Oh no, it's inside a model from the official ONNX repo. I commented here: onnx/models#587
There's still a semantic distinction between an empty tensor and a missing tensor. Being present but size 0 is different than missing completely (in which case we should use the default value from the spec). Can we limit this hack to just Resize rather than globally in the base class? |
Yes we can, but my question is, do we really need to check the shape for constant input? I believe ONNX doesn't allow an initializer with dynamic shape, nor 0 dimension. |
This comment was marked as outdated.
This comment was marked as outdated.
That surprises me, your example shows a non-initializer input with 0 dimension, but I just change it to an initializer input with 0 dimension, it just works.
All right, I will do this, thank you for your patient! |
ONNX initializers should have shape information, skip the shape check if the input is an initializer.
7667026
to
58b598f
Compare
@fdwr, I just update the PR to provide a flag for each op, allow it to handle ignoring an empty tensor as input. PTAL again, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
/azp run ONNX Runtime Web CI Pipeline,Windows GPU CI Pipeline,Linux Android Emulator QNN CI Pipeline |
/azp run Linux CPU CI Pipeline,Linux CPU Minimal Build E2E CI Pipeline,Linux GPU CI Pipeline,Linux GPU TensorRT CI Pipeline,Linux OpenVINO CI Pipeline,Linux QNN CI Pipeline,MacOS CI Pipeline,Windows ARM64 QNN CI Pipeline,Windows CPU CI Pipeline |
/azp run Windows GPU CUDA CI Pipeline,Windows GPU DML CI Pipeline,Windows GPU Doc Gen CI Pipeline |
/azp run Windows GPU TensorRT CI Pipeline,onnxruntime-binary-size-checks-ci-pipeline,orttraining-linux-ci-pipeline,orttraining-linux-gpu-ci-pipeline,orttraining-ortmodule-distributed,Windows x64 QNN CI Pipeline,Big Models |
Azure Pipelines successfully started running 2 pipeline(s). |
Azure Pipelines successfully started running 3 pipeline(s). |
Azure Pipelines successfully started running 4 pipeline(s). |
Azure Pipelines successfully started running 9 pipeline(s). |
/azp run Python format, orttraining-linux-ci-pipeline |
Azure Pipelines could not run because the pipeline triggers exclude this branch/path. |
…oft#22972) ### Description Some ops should allow empty tensor as input, e.g. roi, scales inputs in Resize ### Motivation and Context It avoid some unexpected fallback for optional input with empty tensor. e.g. roi and scales are both optional inputs in Resize, in some models they have non-empty name but with empty initializer presented as `[0]`, WebNN currently will fallback all nodes with 0 dimension, which is not expected. ![image](https://github.com/user-attachments/assets/599ba351-b5f6-49ac-8a1f-69fb28dbaf9b)
…oft#22972) ### Description Some ops should allow empty tensor as input, e.g. roi, scales inputs in Resize ### Motivation and Context It avoid some unexpected fallback for optional input with empty tensor. e.g. roi and scales are both optional inputs in Resize, in some models they have non-empty name but with empty initializer presented as `[0]`, WebNN currently will fallback all nodes with 0 dimension, which is not expected. ![image](https://github.com/user-attachments/assets/599ba351-b5f6-49ac-8a1f-69fb28dbaf9b)
…oft#22972) ### Description Some ops should allow empty tensor as input, e.g. roi, scales inputs in Resize ### Motivation and Context It avoid some unexpected fallback for optional input with empty tensor. e.g. roi and scales are both optional inputs in Resize, in some models they have non-empty name but with empty initializer presented as `[0]`, WebNN currently will fallback all nodes with 0 dimension, which is not expected. ![image](https://github.com/user-attachments/assets/599ba351-b5f6-49ac-8a1f-69fb28dbaf9b)
Description
Some ops should allow empty tensor as input, e.g. roi, scales inputs in Resize
Motivation and Context
It avoid some unexpected fallback for optional input with empty tensor.
e.g. roi and scales are both optional inputs in Resize, in some models they have non-empty name but with empty initializer presented as
[0]
, WebNN currently will fallback all nodes with 0 dimension, which is not expected.