Skip to content

Commit 86b3b89

Browse files
authored
[WebNN EP] Check if the tensor shape has 0 dimension (#22573)
WebNN doesn't support empty tensor.
1 parent 7a8fa12 commit 86b3b89

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

onnxruntime/core/providers/webnn/builders/helper.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ bool IsTensorShapeSupported(const NodeArg& node_arg, const std::string& parent_n
8989
<< "use sessionOptions.FreeDimensionOverrides to set a fixed shape: " << node_arg_name;
9090
return false;
9191
}
92+
if (dim.dim_value() == 0) {
93+
LOGS(logger, VERBOSE) << "The shape of [" << node_arg_name << "] has 0 dimension which is not supported by WebNN";
94+
return false;
95+
}
9296
}
9397

9498
return true;

onnxruntime/core/providers/webnn/builders/impl/expand_op_builder.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ bool ExpandOpBuilder::IsOpSupportedImpl(const InitializedTensorSet& initializers
8888
LOGS(logger, VERBOSE) << "Cannot get shape.";
8989
return false;
9090
}
91+
if (std::any_of(new_shape.begin(), new_shape.end(), [](int64_t dimension) { return dimension == 0; })) {
92+
LOGS(logger, VERBOSE) << "WebNN expand does not support new shape with 0 dimension.";
93+
return false;
94+
}
9195

9296
std::vector<int64_t> input_shape;
9397
if (!GetShape(*input_defs[0], input_shape, logger)) {

0 commit comments

Comments
 (0)