Skip to content

Commit

Permalink
[WebNN EP] Support ConvTranspose for TFLite backend (microsoft#21291)
Browse files Browse the repository at this point in the history
### Description
Chromium supports ConvTranspose for TFLite in
https://chromium-review.googlesource.com/c/chromium/src/+/5635194

With constraint that only default dilations and groups are supported.

---------

Co-authored-by: Dwayne Robinson <[email protected]>
  • Loading branch information
Honry and fdwr authored Jul 31, 2024
1 parent e7aa116 commit 1d4b161
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion js/web/docs/webnn-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ operators and the supported opset domain/versions in **WebNN EP** by ONNX Runtim
| 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) |
| ConvTranspose | ai.onnx(7-10, 11+) | convTranspose2d | || Only supports 3-D or 4-D input and 'W' (weight). |
| ConvTranspose | ai.onnx(7-10, 11+) | convTranspose2d | || Only supports 3-D or 4-D input and 'W' (weight). WebNN CPU backend only supports default dilations and group |
| Cos | ai.onnx(7+) | cos ||| |
| Div | ai.onnx(7-12, 13, 14+) | div ||| |
| Elu | ai.onnx(7+) | elu ||| WebNN CPU backend only supports 'alpha' value is 1.0 |
Expand Down
2 changes: 1 addition & 1 deletion onnxruntime/core/providers/webnn/builders/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static const InlinedHashMap<std::string, WebnnOpInfo> op_map = {
{"Concat", {"concat", true}},
{"Conv", {"conv2d", true}},
{"ConvInteger", {"conv2dInteger", false}},
{"ConvTranspose", {"convTranspose2d", false}},
{"ConvTranspose", {"convTranspose2d", true}},
{"Cos", {"cos", true}},
{"Div", {"div", true}},
{"DequantizeLinear", {"dequantizeLinear", false}},
Expand Down
16 changes: 16 additions & 0 deletions onnxruntime/core/providers/webnn/builders/impl/conv_op_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,22 @@ bool ConvOpBuilder::HasSupportedInputsImpl(const Node& node, const WebnnDeviceTy
return false;
}

// WebNN CPU backend (TFLite) only supports default dilations and group.
// https://source.chromium.org/chromium/chromium/src/+/main:services/webnn/tflite/graph_builder_tflite.cc;l=1040
if (device_type == WebnnDeviceType::CPU && op_type == "ConvTranspose") {
NodeAttrHelper helper(node);
const auto dilations = helper.Get("dilations", std::vector<int64_t>{1, 1});
const auto group = helper.Get("group", 1);
if (dilations[0] != 1 || (dilations.size() > 1 && dilations[1] != 1)) {
LOGS(logger, VERBOSE) << op_type << " for WebNN CPU backend only supports default dilation 1.";
return false;
}
if (group != 1) {
LOGS(logger, VERBOSE) << op_type << " for WebNN CPU backend only supports default group 1.";
return false;
}
}

return true;
}

Expand Down

0 comments on commit 1d4b161

Please sign in to comment.