-
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] Support SkipSimplifiedLayerNormalization op #23151
base: main
Are you sure you want to change the base?
Conversation
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.
e6780a0
to
c8d9efc
Compare
/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 |
Azure Pipelines successfully started running 2 pipeline(s). |
/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 |
/azp run Windows GPU CUDA CI Pipeline,Windows GPU DML CI Pipeline,Windows GPU Doc Gen CI Pipeline |
Azure Pipelines successfully started running 4 pipeline(s). |
Azure Pipelines successfully started running 3 pipeline(s). |
Azure Pipelines successfully started running 9 pipeline(s). |
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.
👍
|
||
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()) { |
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.
(minor recommendation) 🤔 I see this so often that it could boost concise readability and decrease potential typos to add a helper.
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()) {
}
onnxruntime/core/providers/webnn/builders/impl/normalization_op_builder.cc
Show resolved
Hide resolved
onnxruntime/core/providers/webnn/builders/impl/normalization_op_builder.cc
Show resolved
Hide resolved
return false; | ||
if (op_type == "SkipSimplifiedLayerNormalization") { | ||
for (size_t i = 1; i < output_defs.size(); i++) { | ||
if (output_defs[i]->Exists() && i < 3) { |
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.
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++) {
Possible infrastructure issue. Restarting. |
The algorithm of
SkipSimplifiedLayerNormalization
is quite similar to theSimplifiedLayerNormalization
, only different isSkipSimplifiedLayerNormalization
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.