[WebNN EP] TFLite backend only supports Elu with default alpha (#20862)

This commit is contained in:
Wanming Lin 2024-06-04 05:10:22 +08:00 committed by GitHub
parent ae8df4db8f
commit c128132dd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View file

@ -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 | ✗ | ✓ | |

View file

@ -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<int64_t> 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;
}