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

[WebNN] Improve data type check of slice op #22988

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

shiyi9801
Copy link
Contributor

A follow-up of [WebNN] Support negative steps for slice. Slice op is emulated by reverse+slice when steps < 0 so SliceOpBuilder::HasSupportedInputsImpl() should also check the supported data types of reverse.

@shiyi9801
Copy link
Contributor Author

@Honry PTAL, thanks!

Copy link
Contributor

@Honry Honry left a comment

Choose a reason for hiding this comment

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

Thanks @shiyi9801, data type check is not rigorous in WebNN EP, especially for those ONNX ops that need to be supported by decomposed WebNN ops. This is a good starting.👍

if (!ReadIntArrayFrom1DTensor(*initializers.at(input_defs[4]->Name()), steps, logger))
return false;
if (std::any_of(steps.begin(), steps.end(), [](int64_t step) { return step < 0; })) {
if (!IsDataTypeSupportedByWebNNOp(op_type, "reverse", input_type, wnn_limits, "input", "data", logger)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can simplify this by using a parameter webnn_op_type, set it to reverse or slice according to the step value.

Then only call IsDataTypeSupportedByWebNNOp once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

slice always needs to be checked (except for a few cases like steps=1, start=0, end=input_dim) so we still have to call IsDataTypeSupportedByWebNNOp() twice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry, I missed this.

onnxruntime/core/providers/webnn/builders/helper.cc Outdated Show resolved Hide resolved
Co-authored-by: Wanming Lin <[email protected]>
Copy link
Contributor

@Honry Honry left a comment

Choose a reason for hiding this comment

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

👍

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.

2 participants