From c128132dd8aaabd9d132015f90be823b36bb0fec Mon Sep 17 00:00:00 2001 From: Wanming Lin Date: Tue, 4 Jun 2024 05:10:22 +0800 Subject: [PATCH] [WebNN EP] TFLite backend only supports Elu with default alpha (#20862) --- js/web/docs/webnn-operators.md | 2 +- .../webnn/builders/impl/activation_op_builder.cc | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/js/web/docs/webnn-operators.md b/js/web/docs/webnn-operators.md index bcabb6896f..7ec3eda8ce 100644 --- a/js/web/docs/webnn-operators.md +++ b/js/web/docs/webnn-operators.md @@ -25,7 +25,7 @@ operators and the supported opset domain/versions in **WebNN EP** by ONNX Runtim | ConvTranspose | ai.onnx(7-10, 11+) | convTranspose2d | ✓ | ✗ | Only supports 3-D or 4-D input and 'W' (weight). | | Cos | ai.onnx(7+) | cos | ✗ | ✓ | | | Div | ai.onnx(7-12, 13, 14+) | div | ✓ | ✓ | | -| Elu | ai.onnx(7+) | elu | ✓ | ✓ | | +| Elu | ai.onnx(7+) | elu | ✓ | ✓ | WebNN CPU backend only supports 'alpha' value is 1.0 | | Equal | ai.onnx(7-10, 11-12, 13-18, 19+) | equal | ✗ | ✓ | | | Erf | ai.onnx(7-9, 10-12, 13+) | erf | ✗ | ✓ | | | Exp | ai.onnx(7-12, 13+) | exp | ✗ | ✓ | | diff --git a/onnxruntime/core/providers/webnn/builders/impl/activation_op_builder.cc b/onnxruntime/core/providers/webnn/builders/impl/activation_op_builder.cc index 163c9b0fb9..af0f0133b4 100644 --- a/onnxruntime/core/providers/webnn/builders/impl/activation_op_builder.cc +++ b/onnxruntime/core/providers/webnn/builders/impl/activation_op_builder.cc @@ -20,7 +20,7 @@ class ActivationOpBuilder : public BaseOpBuilder { // Operator support related. bool IsOpSupportedImpl(const InitializedTensorSet& initializers, const Node& node, - WebnnDeviceType /* device_type */, const logging::Logger& logger) const override; + WebnnDeviceType device_type, const logging::Logger& logger) const override; bool HasSupportedInputsImpl(const Node& node, const WebnnDeviceType device_type, const logging::Logger& logger) const override; }; @@ -72,14 +72,24 @@ Status ActivationOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, // Operator support related. bool ActivationOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& /* initializers */, const Node& node, - WebnnDeviceType /* device_type */, + WebnnDeviceType device_type, const logging::Logger& logger) const { const auto& input_defs = node.InputDefs(); + const auto& op_type = node.OpType(); std::vector input_shape; if (!GetShape(*input_defs[0], input_shape, logger)) return false; + if (op_type == "Elu" && device_type == WebnnDeviceType::CPU) { + NodeAttrHelper helper(node); + float alpha = helper.Get("alpha", 1.0f); + if (alpha != 1.0f) { + LOGS(logger, VERBOSE) << "WebNN CPU backend only supports Elu's alpha == 1.0"; + return false; + } + } + return true; }