Skip to content
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

Investigate whether raw data or external data should be used #52

Open
mingmingtasd opened this issue Jan 3, 2025 · 6 comments
Open
Labels
question Further information is requested

Comments

@mingmingtasd
Copy link
Collaborator

Some initializers must be uploaded to raw data, for example:

  1. Reshape op needs parameter shape as raw data to do shape inference.
  2. Reduce op needs parameter axes as raw data.
  3. Expand op needs parameter shape as raw data.
  4. Slice op needs starts, ends and steps as raw data.

While for some other ops, initializers have not to be raw data:
min/max value of clamp can be either raw data or external data

Are there other ops requiring initializer as raw data?
Currently we upload all webnn constants into external data (for potential zero-copy) but what if some ops like Reshape can't take external data as initializers?

@huningxin @shiyi9801 @lisa0314 @miaobin

@shiyi9801
Copy link
Owner

/cc @Honry

@huningxin
Copy link
Collaborator

huningxin commented Jan 3, 2025

@miaobin mentioned that the raw data is required by shape inference code.

#47 (comment)

@huningxin
Copy link
Collaborator

While for some other ops, initializers have not to be raw data: min/max value of clamp can be either raw data or external data

WebNN clamp min/max values are just scalars. Raw data (copying) vs. external data (non-copying) seems not to be much different.

@huningxin
Copy link
Collaborator

huningxin commented Jan 4, 2025

The guideline recommends using raw data when

  • the value is less than 128 bytes (because there's about 60 bytes or so of overhead to use the external memory structure for pre-allocated memory), the scalar should be in this category
  • the value is used for shape inference

We may need to add a helper to calculate the size of an initializer and use raw data if its size is less than 128 bytes.

See more discussions at microsoft/onnxruntime#23223 (comment)

@huningxin
Copy link
Collaborator

@mingmingtasd , your instanceNormalization PR mentions

// ONNX requires scale and bias inputs. And they must be uploaded as raw data,
// otherwise there will be runtime error.

https://github.com/shiyi9801/chromium/blame/ort_backend/services/webnn/ort/graph_builder_ort.cc#L666

I understand scale and bias won't be used for shape inference. What's the runtime error if using pre-allocated data?

@mingmingtasd
Copy link
Collaborator Author

I understand scale and bias won't be used for shape inference. What's the runtime error if using pre-allocated data

Sorry, after verifying, the scale and bias of instance norm can be external data, I added wrong annotation here. I will fix ~

We may need to add a helper to calculate the size of an initializer and use raw data if its size is less than 128 bytes.

I will do this.

@huningxin huningxin added the question Further information is requested label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants