-
Notifications
You must be signed in to change notification settings - Fork 48
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
0D scalars #390
Comments
@fdwr mlContext.computSync should run in the worker and I tried to delete the errant validation statement in the graph builder and run your scalar test, it passed. |
@miaobin: Great, thanks for verifying. |
In the current spec,
Once we support 0-D dimensions, should we make the |
I think so, |
Currently the spec says that if dimensions are missing, then it's treated as a scalar, and the shape for scalars is |
Sounds good to me. Thanks for the clarification. |
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjw@chromium.org> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Weizhong Xia <weizhong@google.com> Cr-Commit-Position: refs/heads/main@{#1225264}
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjw@chromium.org> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Weizhong Xia <weizhong@google.com> Cr-Commit-Position: refs/heads/main@{#1225264}
This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjw@chromium.org> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Weizhong Xia <weizhong@google.com> Cr-Commit-Position: refs/heads/main@{#1225264}
Automatic update from web-platform-tests WebNN: Support 0-D scalars This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjw@chromium.org> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Weizhong Xia <weizhong@google.com> Cr-Commit-Position: refs/heads/main@{#1225264} -- wpt-commits: 9a15f9f5814ac064c27ec9089acda4028b2518f8 wpt-pr: 43140
Automatic update from web-platform-tests WebNN: Support 0-D scalars This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjw@chromium.org> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Weizhong Xia <weizhong@google.com> Cr-Commit-Position: refs/heads/main@{#1225264} -- wpt-commits: 9a15f9f5814ac064c27ec9089acda4028b2518f8 wpt-pr: 43140
Automatic update from web-platform-tests WebNN: Support 0-D scalars This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjw@chromium.org> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Weizhong Xia <weizhong@google.com> Cr-Commit-Position: refs/heads/main@{#1225264} -- wpt-commits: 9a15f9f5814ac064c27ec9089acda4028b2518f8 wpt-pr: 43140
Automatic update from web-platform-tests WebNN: Support 0-D scalars This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjw@chromium.org> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Commit-Queue: ningxin hu <ningxin.hu@intel.com> Reviewed-by: Weizhong Xia <weizhong@google.com> Cr-Commit-Position: refs/heads/main@{#1225264} -- wpt-commits: 9a15f9f5814ac064c27ec9089acda4028b2518f8 wpt-pr: 43140
Automatic update from web-platform-tests WebNN: Support 0-D scalars This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjwchromium.org> Reviewed-by: Rafael Cintron <rafael.cintronmicrosoft.com> Commit-Queue: ningxin hu <ningxin.huintel.com> Reviewed-by: Weizhong Xia <weizhonggoogle.com> Cr-Commit-Position: refs/heads/main{#1225264} -- wpt-commits: 9a15f9f5814ac064c27ec9089acda4028b2518f8 wpt-pr: 43140 UltraBlame original commit: 7d5c3104db5385083454b56cf36201a8278bb1cc
Automatic update from web-platform-tests WebNN: Support 0-D scalars This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjwchromium.org> Reviewed-by: Rafael Cintron <rafael.cintronmicrosoft.com> Commit-Queue: ningxin hu <ningxin.huintel.com> Reviewed-by: Weizhong Xia <weizhonggoogle.com> Cr-Commit-Position: refs/heads/main{#1225264} -- wpt-commits: 9a15f9f5814ac064c27ec9089acda4028b2518f8 wpt-pr: 43140 UltraBlame original commit: 7d5c3104db5385083454b56cf36201a8278bb1cc
Automatic update from web-platform-tests WebNN: Support 0-D scalars This CL fixes the WebNN spec and implementation issue [1] and allows to present a 0-D scalar operand by empty dimensions. This CL also adds test cases for MLGraphBuilder, XNNPACK backend, WebNN service and DirectML backend for 0-D scalar operand. [1]: webmachinelearning/webnn#390 Bug: 1498803, 1273291 Change-Id: Ic30602d6a1cdbe38ca3d384ffb7d8fe053b0a5a7 Cq-Include-Trybots: luci.chromium.try:win11-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5029273 Reviewed-by: Jiewei Qian <qjwchromium.org> Reviewed-by: Rafael Cintron <rafael.cintronmicrosoft.com> Commit-Queue: ningxin hu <ningxin.huintel.com> Reviewed-by: Weizhong Xia <weizhonggoogle.com> Cr-Commit-Position: refs/heads/main{#1225264} -- wpt-commits: 9a15f9f5814ac064c27ec9089acda4028b2518f8 wpt-pr: 43140 UltraBlame original commit: 7d5c3104db5385083454b56cf36201a8278bb1cc
"dimensions" not currently being well defined for scalars came up in review of #555
So TL;DR: - let's dust #476 off and try to get it merged ASAP? How can I help? |
@inexorabletash: Sorry Josh - I'll dust it off tomorrow (hopefully before I see your virtual face again in the evening... 😅). I'll probably have Bikeshed questions! ⏳ |
Context
This arose during prototyping additional models and during Chromium code review and ORT review.
Overview
[1,2,3]
- 3D tensor shape[1,2]
- 2D tensor shape[1]
- 1D tensor shape[]
- 0D tensor shape (scalar)A 0D tensor shape vs a 1D tensor with a single element are semantically and functionally distinct. For simple operators (e.g. Add/Sin), treating a scalar as if it was a 1D array with a single element yields the same functional result, but for more complex operators where the rank matters (e.g. ReduceSum with all axes and keepDimensions = false, or Gather where the output rank is computed as input.rank + indices.rank - 1...), treating the two as synonymous is problematic and has been causing a multitude of problems with mapping certain ONNX models to WebNN.
References
Every known ML library represents 0D scalars via the shape
[]
(or()
):Numpy
TensorFlow
PyTorch
ONNX
SafeTensorss
The SafeTensors file format (commonly used with Stable Diffusion models for custom weights) explicitly allows 0D scalars and 0-size tensors.
XNNPack
Bin Miao says below that XNNPack works.
Implementation experience
In my Chromium fork, I just needed to change 2 lines, deleting 1 errant validation statement in the graph builder, and adding 1 in the DML backend (TensorDesc constructors sets a minimum rank of 1) for the rest of it to work. Then scalar tests passed:
Specification Update
The problematic statement in the spec is
If dimensions.length is 0, return false.
,https://www.w3.org/TR/webnn/#api-mloperand-create. Delete that line, and the rest should work.
The computation for the element count and byte length is even already correct (it would return 1 element for empty dimensions) https://www.w3.org/TR/webnn/#api-mloperanddescriptor:
Code locations to update
The text was updated successfully, but these errors were encountered: