Skip to content
Merged
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
10 changes: 7 additions & 3 deletions onnxruntime/core/providers/webnn/builders/model_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ Status ModelBuilder::RegisterInitializers() {
for (const auto& pair : GetInitializerTensors()) {
const auto& tensor = *pair.second;
const auto& name = tensor.name();
// Optional tensors can be indicated by an empty name, just ignore it.
if (name.empty() || Contains(skipped_initializers_, name))
const auto& shape = tensor.dims();

// Ignore the following tensors:
// 1. Empty tensors: optional tensors can be indicated by an empty name.
// 2. Tensors in skipped_initializers_: These are tensors that are not used as WebNN Constants.
// Note: Scalar tensors are excluded because ONNX Runtime will optimize same scalar initializers into one.
if (name.empty() || (Contains(skipped_initializers_, name) && !shape.empty()))
continue;

const auto& shape = tensor.dims();
std::vector<int32_t> dims;
// When the shape is empty, it is scalar initializer that dims = {};
std::transform(shape.cbegin(), shape.cend(),
Expand Down
Loading