Skip to content

Commit

Permalink
[WebNN EP] Fix bug for PRelu on CPU backend. (#17543)
Browse files Browse the repository at this point in the history
### Description
WebNN CPU backend expects slope of PRelu to be a static value. For now,
we will not support it.


### Motivation and Context
Fallback this case to pass the CI.
  • Loading branch information
zesongw authored Sep 15, 2023
1 parent 4d931ed commit a5302fe
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class BinaryOpBuilder : public BaseOpBuilder {
private:
Status AddToModelBuilderImpl(ModelBuilder& model_builder, const Node& node,
const logging::Logger& logger) const override ORT_MUST_USE_RESULT;

// Operator support related.
bool IsOpSupportedImpl(const InitializedTensorSet& initializers, const Node& node,
const WebnnDeviceType device_type, const logging::Logger& logger) const override;
};

// Add operator related.
Expand Down Expand Up @@ -50,6 +54,24 @@ Status BinaryOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder, const
return Status::OK();
}

bool BinaryOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers,
const Node& node,
const WebnnDeviceType device_type,
const logging::Logger& logger) const {
const auto& input_defs = node.InputDefs();
const auto& op_type = node.OpType();

// XNNPACK prelu operator expects slope to be a static value.
// https://github.com/google/XNNPACK/issues/4692
// TODO: Remove this check after it is solved.
if (op_type == "PRelu" && !Contains(initializers, input_defs[1]->Name()) && device_type == WebnnDeviceType::CPU) {
LOGS(logger, VERBOSE) << "The second input (slope) for PRelu must be a constant initializer for WebNN CPU backend.";
return false;
}

return true;
}

void CreateBinaryOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations) {
if (op_registrations.op_builder_map.count(op_type) > 0)
return;
Expand Down

0 comments on commit a5302fe

Please sign in to comment.