Skip to content

Commit

Permalink
[WebNN EP] Don't covert all inputs except the 0th input for Resize (m…
Browse files Browse the repository at this point in the history
…icrosoft#18687)

Currently all the inputs of Resize node will be converted to NHWC if the
preferred layout is NHWC, and the ORT will call `IsOpSupportedImpl`
twice, first time the inputs are NCHW, and the second time the inputs
have been converted to NHWC. This would make the validation for scales
input complicated and difficult to identify the height and width values.
  • Loading branch information
Honry authored Dec 8, 2023
1 parent 7ed48a2 commit e8f33b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ Status TransformLayoutForEP(Graph& graph, bool& modified, const IExecutionProvid
// Except for resize and convolution ops, all the other layout sensitive ops only require layout transformation
// for 0th input and output. For resize, add the other relevant inputs which need conversion. For Conv - layout
// transformer only converts layout for 0th input, weights should be handled by every EP.
if (node->OpType() == "Resize") {
// For resize in WebNN EP, we don't want to convert all the inputs except the 0th input.
if (node->OpType() == "Resize" && node->GetExecutionProviderType() != kWebNNExecutionProvider) {
// Older versions of resize have a bug where ROI and Scales cannot be made empty inputs. To handle this case,
// we need to jump a few extra hoops to make sure its inputs are correctly handled.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ Status ResizeOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
const bool isNhwc = model_builder.GetPreferredLayout() == DataLayout::NHWC;
if (input_defs.size() == 3) { // Use scales.
ORT_RETURN_IF_NOT(GetResizeScales(initializers, node, scales, logger), "Error getting resize scales");
if (isNhwc) {
scales_hw = {scales[1], scales[2]};
} else {
scales_hw = {scales[2], scales[3]};
}
scales_hw = {scales[2], scales[3]};
options.set("scales", emscripten::val::array(scales_hw));
} else { // We already checked number of inputs in IsOpSupportedImpl.
std::vector<int64_t> output_sizes;
Expand All @@ -136,11 +132,7 @@ Status ResizeOpBuilder::AddToModelBuilderImpl(ModelBuilder& model_builder,
std::transform(output_sizes.cbegin(), output_sizes.cend(),
std::back_inserter(sizes),
[](int64_t dim) -> int32_t { return SafeInt<int32_t>(dim); });
if (isNhwc) {
sizes_hw = {sizes[1], sizes[2]};
} else {
sizes_hw = {sizes[2], sizes[3]};
}
sizes_hw = {sizes[2], sizes[3]};
options.set("sizes", emscripten::val::array(sizes_hw));
}

Expand Down

0 comments on commit e8f33b5

Please sign in to comment.