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

NNotepad: Pass buffers rather than views when building constants #303

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

inexorabletash
Copy link
Member

When building constants, either a raw ArrayBuffer can be passed or a view type like Float32Array. In the latter case the data type and view type must match; e.g. if dataType is "int8", a Uint8Array must be passed.

Chromium is in the process of rolling out native Float16Array support, but currently the WebNN prototype implementation[1] requires passing a Uint16Array if the data type is "float16". NNotepad utilizes this workaround if native Float16Array is not present. But if it is present, it passes a native Float16Array and Chromium throws.

Until things settle, have NNotepad's constant() builder just pass the underlying buffer rather than view, which bypasses this check. This change can be reverted at some point in the future, but is harmless to continue using this workaround.

1: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/ml/webnn/ml_graph_utils.cc;l=92

When building constants, either a raw ArrayBuffer can be passed or a
view type like Float32Array. In the latter case the data type and view
type must match; e.g. if dataType is "int8", a Uint8Array must be
passed.

Chromium is in the process of rolling out native Float16Array support,
but currently the WebNN prototype implementation[1] requires passing a
Uint16Array if the data type is "float16". NNotepad utilizes this
workaround if native Float16Array is not present. But if it *is*
present, it passes a native Float16Array and Chromium throws.

Until things settle, have NNotepad's constant() builder just pass the
underlying buffer rather than view, which bypasses this check. This
change can be reverted at some point in the future, but is harmless to
continue using this workaround.

1: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/ml/webnn/ml_graph_utils.cc;l=92
@inexorabletash inexorabletash requested a review from Honry February 13, 2025 23:10
@inexorabletash
Copy link
Member Author

@Honry - can you please take a look?

@inexorabletash
Copy link
Member Author

FYI I was testing with out/Default/chrome --enable-features=WebMachineLearningNeuralNetwork --enable-experimental-web-platform-features --js-flags="--js-float16array" https://webmachinelearning.github.io/webnn-samples/nnotepad

Copy link
Collaborator

@Honry Honry left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@Honry Honry merged commit a1c3c11 into webmachinelearning:master Feb 14, 2025
3 checks passed
@inexorabletash inexorabletash deleted the nnotepad-f16compat branch February 14, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants