-
Notifications
You must be signed in to change notification settings - Fork 788
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
Initial WebNN Support #890
Conversation
Thanks for the PR! Since our goal is to align with the python library as closely as possible, we may need to separate out Here are some proposals for the API: const classifier = await pipeline('image-classification', 'xenova/resnet-50', {
dtype: 'fp32',
device: 'gpu', // or 'npu'
provider: 'webnn',
}); const classifier = await pipeline('image-classification', 'xenova/resnet-50', {
dtype: 'fp32',
device: 'webnn-gpu', // e.g., or 'webnn-npu'
}); What do you think? |
Thank you @xenova for starting the review. Yes, the current
To simplify the API and maintain consistency with other devices, I think the second proposal is superior as it doesn't require an additional provider key. BTW, WebNN needs e.g. |
Yes this should be handled by specifying these values in the model's config.json under something like |
I couldn't test this yet, just wondering: if we pick WebNN as provider, do we have a different set of supported ops again based on the browsers WebNN implementation? I see three scenarios:
|
Thanks @xenova for the device detection and selection improvement between ff1853c Initial WebNN Support and 5b2cac2 Improve WebNN selection, now WebNN can be run successfully by using code below:
@kungfooman Thanks for the great question! Currently WebNN is still adding support for new ops and new data types. We are keep updating the Implementation Status of WebNN Operations based on the WebNN Spec and the browser implementation. Our team is also implementing and maintaining the WebNN EP of ONNX Runtime Web, if the op not supported in browsers WebNN implementation, there is a fallback mechanism that fallback these WebNN not supported ops to CPU EP (Wasm) of ONNX Runtime Web. WebNN is also adding WebGPU interops capabilities, interacting with WebGPU to support custom ops or cases that may not be supported by WebNN. Usually the more WebNN ops supported, the fewer subgraphs are split. The less partitions the better performance for WebNN. WebNN will enable users to leverage multiple AI accelerators, including CPUs, GPUs, and NPUs, opening up new possibilities such as power-efficient AI inferencing on NPUs. |
This is the initial PR to support WebNN API.
User Code
WebNN Installation Guide
WebNN is being rapidly implemented in browsers. Before it formally ships, WebNN requires a compatible browser to run, and Windows* 11 v21H2 (DML 1.6.0) or higher.
about://flags
, and then press Enter. An Experiments page openswebnn
.Enables WebNN API
appearsEnabled
Known Issue
From Transformers.js perspective, it's better to improve the following float16 check code (current via WebGPU and WebGPU shader-f16) since fp16 support is not GPU device only.
@Honry @huningxin @xenova PTAL.