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] Support SkipSimplifiedLayerNormalization op #23151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Honry
Copy link
Contributor

@Honry Honry commented Dec 19, 2024

The algorithm of SkipSimplifiedLayerNormalization is quite similar to the SimplifiedLayerNormalization, only different is SkipSimplifiedLayerNormalization provides an additional output used for calculating the sum of the input, skip and bias (if it exits).

BTW, fix a bug in SimplifiedLayerNormalization, adding bias if it exits.

@Honry
Copy link
Contributor Author

Honry commented Dec 19, 2024

@fdwr, @guschmue, PTAL, thanks!

The algorithm of SkipSimplifiedLayerNormalization is quite
similar to the SimplifiedLayerNormalization, only different
is SkipSimplifiedLayerNormalization provides an additional
output used for caculating the sum of the input, skip and
bias (if it exits).

BTW, fix a bug in SimplifiedLayerNormalization, adding bias
if it exits.
@Honry Honry force-pushed the skip-simplified-layernorm branch from e6780a0 to c8d9efc Compare December 19, 2024 12:48
@guschmue guschmue added the ep:WebNN WebNN execution provider label Dec 19, 2024
@guschmue
Copy link
Contributor

/azp run ONNX Runtime Web CI Pipeline,Windows GPU CI Pipeline,Linux Android Emulator QNN CI Pipeline

@guschmue
Copy link
Contributor

/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

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@guschmue
Copy link
Contributor

/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

@guschmue
Copy link
Contributor

/azp run Windows GPU CUDA CI Pipeline,Windows GPU DML CI Pipeline,Windows GPU Doc Gen CI Pipeline

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Copy link

Azure Pipelines successfully started running 9 pipeline(s).

Copy link
Contributor

@fdwr fdwr left a comment

Choose a reason for hiding this comment

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

👍


const size_t bias_input_index = op_type == "SkipSimplifiedLayerNormalization" ? 3 : 2;
emscripten::val bias = emscripten::val::undefined();
if (input_defs.size() > bias_input_index && input_defs[bias_input_index]->Exists()) {
Copy link
Contributor

@fdwr fdwr Dec 19, 2024

Choose a reason for hiding this comment

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

(minor recommendation) 🤔 I see this so often that it could boost concise readability and decrease potential typos to add a helper.

Suggested change
if (input_defs.size() > bias_input_index && input_defs[bias_input_index]->Exists()) {
if (TensorExists(input_defs, bias_input_index)) {
-      if (op_type == "SkipSimplifiedLayerNormalization" && output_defs.size() > 3 && output_defs[3]->Exists()) {
+      if (op_type == "SkipSimplifiedLayerNormalization" && TensorExists(output_defs, 3)) {
bool TensorExists(gsl::span<const NodeArg*> defs, size_t tensor_index) noexcept {
  return tensor_index < defs.size() && defs[tensor_index]->Exists()) {
}

return false;
if (op_type == "SkipSimplifiedLayerNormalization") {
for (size_t i = 1; i < output_defs.size(); i++) {
if (output_defs[i]->Exists() && i < 3) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it also be an error if there are more than 3 outputs? Currently it loops through all outputs, including ones beyond 3, but it doesn't give an error for them.

  if (op_type == "SkipSimplifiedLayerNormalization") {
    if (output_defs.size() > 3) {
        LOGS(logger, VERBOSE) << "WebNN's SkipSimplifiedLayerNormalization does not support " << output_defs.size() << " outputs, only 1.";
    }
    for (size_t i = 1, count = std::min(output_defs.size(), 3); i < count; i++) {

@fdwr
Copy link
Contributor

fdwr commented Dec 19, 2024

ONNX Runtime Web CI Pipeline ...
npm error code E409
npm error 409 Conflict - GET https://registry.npmjs.org/shiki/-/shiki-0.14.7.tgz
source

Possible infrastructure issue. Restarting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:WebNN WebNN execution provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants