Skip to content
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 EP] TFLite backend only supports limit ranges for Clip #20863

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/web/docs/webnn-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ operators and the supported opset domain/versions in **WebNN EP** by ONNX Runtim
| BatchNormalization | ai.onnx(7-8, 9-13, 14, 15+) | batchNormalization | ✗ | ✓ | Only supports 'training_mode' value is 0, one output |
| Cast | ai.onnx(7-8, 9-12, 13-18, 19-20, 21+) | cast | ✗ | ✓ | |
| Ceil | ai.onnx(7-12, 13+) | ceil | ✓ | ✓ | |
| Clip | ai.onnx(7-10, 11, 12, 13+) | clamp | ✓ | ✓ | |
| Clip | ai.onnx(7-10, 11, 12, 13+) | clamp | ✓ | ✓ | WebNN CPU backend only supports 3 specific ranges: [0.0, infinity], [-1.0, 1.0], [0.0, 6.0] (Chromium issue: https://issues.chromium.org/issues/326156496) |
| Concat | ai.onnx(7-10, 11-12, 13+) | concat | ✓ | ✓ | |
| Conv | ai.onnx(7-10, 11+) | conv2d | ✓ | ✓ | Only supports 3-D or 4-D input and 'W' (weight). WebNN CPU requires the 'W' (weight) input to be a constant |
| ConvTranspose | ai.onnx(7-10, 11+) | convTranspose2d | ✓ | ✗ | Only supports 3-D or 4-D input and 'W' (weight). |
Expand Down
26 changes: 23 additions & 3 deletions onnxruntime/core/providers/webnn/builders/impl/clip_op_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Operator support related.
private:
bool IsOpSupportedImpl(const InitializedTensorSet& initializers, const Node& node,
const WebnnDeviceType /* device_type */, const logging::Logger& logger) const override;
const WebnnDeviceType device_type, const logging::Logger& logger) const override;
bool HasSupportedInputsImpl(const Node& node, const WebnnDeviceType device_type,
const logging::Logger& logger) const override;
};
Expand Down Expand Up @@ -64,13 +64,33 @@

bool ClipOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers,
const Node& node,
const WebnnDeviceType /* device_type */,
const WebnnDeviceType device_type,
const logging::Logger& logger) const {
// TODO: Update IsOpSupportedImpl to pass GraphViewer instead of InitializedTensorSet so the implementations
// can ensure initializers are constant. See #19401 for details of how this update was made to the NNAPI EP.
// GetClipMinMax(graph_viewer, node, minValue, maxValue, logger)
float min, max;
return GetClipMinMax(initializers, node, min, max, logger);
if (GetClipMinMax(initializers, node, min, max, logger)) {
// WebNN CPU backend only supports 3 specific ranges: [0.0, infinity], [-1.0, 1.0], [0.0, 6.0].
// TODO: Remove this workaround once the associated issue is resolved in Chromium:

Check warning on line 75 in onnxruntime/core/providers/webnn/builders/impl/clip_op_builder.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2] Raw Output: onnxruntime/core/providers/webnn/builders/impl/clip_op_builder.cc:75: Missing username in TODO; it should look like "// TODO(my_username): Stuff." [readability/todo] [2]
// https://issues.chromium.org/issues/326156496.
if (device_type == WebnnDeviceType::CPU) {
if ((min == 0.0f && max == std::numeric_limits<float>::infinity()) ||
(min == -1.0f && max == 1.0f) ||
(min == 0.0f && max == 6.0f)) {
return true;
} else {
LOGS(logger, VERBOSE) << "Clip min and max values ("
<< min << ", "
<< max << ") are not supported for WebNN CPU backend";
return false;
}
}

return true;
} else {
return false;
};

Check warning on line 93 in onnxruntime/core/providers/webnn/builders/impl/clip_op_builder.cc

View workflow job for this annotation

GitHub Actions / Lint C++

[cpplint] reported by reviewdog 🐶 You don't need a ; after a } [readability/braces] [4] Raw Output: onnxruntime/core/providers/webnn/builders/impl/clip_op_builder.cc:93: You don't need a ; after a } [readability/braces] [4]
}

bool ClipOpBuilder::HasSupportedInputsImpl(const Node& node, const WebnnDeviceType device_type,
Expand Down
Loading