Skip to content

[WebNN] Handle in-memory external data #25079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Honry
Copy link
Contributor

@Honry Honry commented Jun 16, 2025

Description

Some initializers are stored as in-memory external data, WebNN EP should support these initializers.

Motivation and Context

This PR:

  • Added HasExternalDataInMemory check for external data to avoid unexpected error.
  • Wrapped the UnpackInitializerData to make it compatible with external data.

Fixed #25078

Some initializers are stored as in-memory external data, WebNN
EP should support these initializers.

This PR:
- Added `HasExternalDataInMemory` check for external data to avoid
unexpected error.
- Wrapped the `UnpackInitializerData` to make it compatible with
external data.

Fixed microsoft#25078
@Honry
Copy link
Contributor Author

Honry commented Jun 16, 2025

@yuslepukhin, @fs-eire, @fdwr, PTAL, thanks!

@guschmue guschmue added the ep:WebNN WebNN execution provider label Jun 17, 2025
@guschmue guschmue requested a review from Copilot June 17, 2025 15:10
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates various WebNN operator builders to support in-memory external data for initializers. The changes add an in-memory external data check and update numerous calls to initializer unpacking and tensor reading functions to pass the graph viewer and logger for improved error reporting and compatibility.

  • Added a check for in-memory external data in constant registration.
  • Updated calls to UnpackInitializerData, ReadIntArrayFrom1DTensor, and ReadScalarTensorData to include graph viewer context.
  • Modified several operator builders (e.g., triangular, split, slice, resize, reshape, pad, lstm, gru, gqa, expand, cumsum) to support these changes.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
onnxruntime/core/providers/webnn/builders/model_builder.cc Added an in-memory external-data check and updated unpacking function call.
onnxruntime/core/providers/webnn/builders/impl/triangular_op_builder.cc Updated initializer unpacking to include additional parameters.
onnxruntime/core/providers/webnn/builders/impl/split_op_builder.cc Changed tensor reading for split input to pass the graph viewer.
onnxruntime/core/providers/webnn/builders/impl/slice_op_builder.cc Updated unpacking call signature for slice input tensors.
onnxruntime/core/providers/webnn/builders/impl/resize_op_builder.cc Modified scales and sizes unpacking calls to include graph viewer and logger context.
onnxruntime/core/providers/webnn/builders/impl/reshape_op_builder.cc Updated perm tensor unpacking call with the new function signature.
onnxruntime/core/providers/webnn/builders/impl/pad_op_builder.cc Updated pad and axis tensor reading to pass the graph viewer and adjusted error messages.
onnxruntime/core/providers/webnn/builders/impl/lstm_op_builder.cc Updated sequence lens reading to include graph viewer context.
onnxruntime/core/providers/webnn/builders/impl/gru_op_builder.cc Updated sequence lens reading for GRU with the graph viewer parameter.
onnxruntime/core/providers/webnn/builders/impl/gqa_op_builder.cc Modified scalar tensor reading to include graph viewer context.
onnxruntime/core/providers/webnn/builders/impl/expand_op_builder.cc Updated shape tensor reading by including the graph viewer.
onnxruntime/core/providers/webnn/builders/impl/cumsum_op_builder.cc Changed axis tensor unpacking to use the new interface with graph viewer.
onnxruntime/core/providers/webnn/builders/helper.h Introduced a new inline overload for UnpackInitializerData and updated helper functions.

fdwr
fdwr previously approved these changes Jun 17, 2025
Copy link
Contributor

@fdwr fdwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the typos fixed.

@fdwr
Copy link
Contributor

fdwr commented Jun 18, 2025

/azp run ONNX Runtime Web CI Pipeline,Windows GPU CI Pipeline,Linux Android Emulator QNN CI Pipeline,Windows GPU WebGPU CI Pipeline,Windows OpenVINO CI Pipeline

@fdwr
Copy link
Contributor

fdwr commented Jun 18, 2025

/azp run Linux CPU CI Pipeline,Linux CPU Minimal Build E2E CI Pipeline,Linux GPU CI Pipeline,Linux GPU TensorRT CI Pipeline,Linux OpenVINO CI Pipeline,Linux QNN CI Pipeline,MacOS CI Pipeline,Windows ARM64 QNN CI Pipeline,Windows CPU CI Pipeline

@fdwr
Copy link
Contributor

fdwr commented Jun 18, 2025

/azp run Windows GPU CUDA CI Pipeline,Windows GPU DML CI Pipeline,Windows GPU Doc Gen CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI

@fdwr
Copy link
Contributor

fdwr commented Jun 18, 2025

/azp run Windows GPU TensorRT CI Pipeline,onnxruntime-binary-size-checks-ci-pipeline,orttraining-linux-ci-pipeline,orttraining-linux-gpu-ci-pipeline,orttraining-ortmodule-distributed,Windows x64 QNN CI Pipeline,Big Models

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@fdwr
Copy link
Contributor

fdwr commented Jun 18, 2025

/azp run Test Linux CUDA x64 Release,Test Linux TensorRT x64 Release,web_Debug / build_onnxruntime_web,web_Release / build_onnxruntime_web

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

No pipelines are associated with this pull request.

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@Honry
Copy link
Contributor Author

Honry commented Jun 18, 2025

LGTM with the typos fixed.

Thanks, typos fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:WebNN WebNN execution provider
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WebNN EP] Fail to run some models with in-memory external data
3 participants