Skip to content

Commit

Permalink
[WebNN EP] Only support opset >= 7 (microsoft#16730)
Browse files Browse the repository at this point in the history
Set WebNN EP minimum supported opset to 7 as ONNX Runtime currently only
guarantees support for models stamped with opset 7 or above.
  • Loading branch information
Honry authored Jul 19, 2023
1 parent 7dcb805 commit dcb0f2c
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class ActivationOpBuilder : public BaseOpBuilder {
private:
Status AddToModelBuilderImpl(ModelBuilder& model_builder, const Node& node,
const logging::Logger& logger) const override ORT_MUST_USE_RESULT;

// Operator support related.
private:
int GetMinSupportedOpSet(const Node& node) const override;
};

// Add operator related.
Expand Down Expand Up @@ -70,13 +66,6 @@ Status ActivationOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
return Status::OK();
}

// Operator support related.

int ActivationOpBuilder::GetMinSupportedOpSet(const Node& /* node */) const {
// Any operators < opset 6 used the deprecated "consumed_inputs attribute" which is unsupported.
return 6;
}

void CreateActivationOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations) {
if (op_registrations.op_builder_map.find(op_type) != op_registrations.op_builder_map.cend())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class BaseOpBuilder : public IOpBuilder {
virtual bool HasSupportedInputsImpl(const Node& node, const WebnnDeviceType device_type,
const logging::Logger& logger) const;

virtual int GetMinSupportedOpSet(const Node& /* node */) const { return 1; }
// ONNX Runtime only *guarantees* support for models stamped
// with opset version 7 or above for opset domain 'ai.onnx'.
virtual int GetMinSupportedOpSet(const Node& /* node */) const { return 7; }
virtual int GetMaxSupportedOpSet(const Node& /* node */) const { return 19; }

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ 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.
private:
int GetMinSupportedOpSet(const Node& node) const override;
};

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

// Operator support related.

int BinaryOpBuilder::GetMinSupportedOpSet(const Node& /* node */) const {
// Add/Sub/Mul/Div/Pow opset 6- has broadcast attributes we do not support now.
return 7;
}

void CreateBinaryOpBuilder(const std::string& op_type, OpBuilderRegistrations& op_registrations) {
if (op_registrations.op_builder_map.find(op_type) != op_registrations.op_builder_map.cend())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class CastOpBuilder : public BaseOpBuilder {
private:
bool IsOpSupportedImpl(const InitializedTensorSet& /* initializers */, const Node& node,
const WebnnDeviceType device_type, const logging::Logger& logger) const override;

int GetMinSupportedOpSet(const Node& node) const override;
};

// Add operator related.
Expand Down Expand Up @@ -76,11 +74,6 @@ Status CastOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,

// Operator support related.

int CastOpBuilder::GetMinSupportedOpSet(const Node& /* node */) const {
// Since opset 6, Cast uses attribute "to" as int type.
return 6;
}

bool CastOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& /* initializers */,
const Node& node,
const WebnnDeviceType device_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class ReshapeOpBuilder : public BaseOpBuilder {
private:
bool IsOpSupportedImpl(const InitializedTensorSet& initializers, const Node& node,
const WebnnDeviceType /* device_type */, const logging::Logger& logger) const override;

// Reshape opset 4- uses attributes for new shape which we do not support for now.
int GetMinSupportedOpSet(const Node& /* node */) const override { return 5; }
};

// Add operator related.
Expand Down

0 comments on commit dcb0f2c

Please sign in to comment.