Skip to content

Commit

Permalink
check 0 dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyi9801 committed Oct 24, 2024
1 parent 08cc261 commit ede50eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions onnxruntime/core/providers/webnn/builders/helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ bool IsInputSupported(const NodeArg& input, const std::string& parent_name, cons
<< input_name;
return false;
}
if (dim.dim_value() == 0) {
LOGS(logger, VERBOSE) << "The shape of [" << node_arg_name << "] has 0 dimension which is not supported";
return false;
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ bool ExpandOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers
LOGS(logger, VERBOSE) << "Cannot get shape.";
return false;
}
if (std::any_of(new_shape.begin(), new_shape.end(), [](int64_t dimension) { return dimension == 0; })) {
LOGS(logger, VERBOSE) << "Expand does not support new shape with 0 dimension.";
return false;
}

std::vector<int64_t> input_shape;
if (!GetShape(*input_defs[0], input_shape, logger)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool ReshapeOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializer

const int64_t* raw_new_shape = reinterpret_cast<const int64_t*>(unpacked_tensor.data());
const auto& perm_dims = perm_tensor.dims();
if (perm_dims.empty() || perm_dims[0] == 0) {
if (perm_dims.empty()) {
LOGS(logger, VERBOSE) << "New shape of reshape cannot be empty";
return false;
}
Expand Down

0 comments on commit ede50eb

Please sign in to comment.