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

Shall we update the spec to add constraints on the axes and the input rank for the reduction operator? #681

Closed
mei1127 opened this issue May 8, 2024 · 5 comments · Fixed by #683

Comments

@mei1127
Copy link

mei1127 commented May 8, 2024

(This was raised by @a-sully in Chromium CL-5496412 review.)

For WebNN's reduction operator:
Austion proposed to update the spec to add constraints on the axes and the input rank.

The Chromium code which validates reductions also fails if
the input rank is zero
values in axes are duplicated
Shall we update the spec and add WPTs accordingly?

/cc @a-sully

@mei1127 mei1127 changed the title Shall we update the spec to specify the input rank can't be zero for reduce operator? Shall we update the spec to specify the input rank and the axes for reduce operator? May 8, 2024
@mei1127 mei1127 changed the title Shall we update the spec to specify the input rank and the axes for reduce operator? Shall we update the spec to add constraints on the axes of the input rank and reduction operators? May 8, 2024
@mei1127 mei1127 changed the title Shall we update the spec to add constraints on the axes of the input rank and reduction operators? Shall we update the spec to add constraints on the axes and the input rank for the reduction operator? May 8, 2024
inexorabletash added a commit to inexorabletash/webnn that referenced this issue May 9, 2024
Suggested behavior matches the Chromium prototype implementation.

Fixes webmachinelearning#681
@inexorabletash inexorabletash self-assigned this May 9, 2024
@inexorabletash
Copy link
Contributor

Makes sense to me - I put up a PR

@fdwr
Copy link
Collaborator

fdwr commented May 10, 2024

also fails if the input rank is zero

(repeating here too)
Nop reductions are valid (where axes are empty), and scalars are just another instance of a nop:

x = tensorflow.constant([3,3,3], dtype=tensorflow.float32)
y = tensorflow.reduce_sum(x, axis=[])

# value: tf.Tensor([3. 3. 3.], shape=(3,), dtype=float32)
# shape: (3,)

x = tensorflow.constant([], dtype=tensorflow.float32)
y = tensorflow.reduce_sum(x, axis=[])

# value: tf.Tensor([], shape=(0,), dtype=float32)
# shape: (0,)

What's not valid is a scalar reduction with non-empty axes, because that would index axes beyond the rank, but the existing check that each axis < inputRank already validates that condition, and so checking input rank is redundant and unnecessarily exclusionary. So, we should remove that line in Chromium.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 10, 2024
crrev.com/c/5496321 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
@inexorabletash
Copy link
Contributor

Groovy. I have a Chromium CL (with WPT changes) up to remove the rank check crrev.com/c/5529350 but I'm a bit rusty so it may not land for a bit.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 10, 2024
crrev.com/c/5496321 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 11, 2024
crrev.com/c/5496321 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
@fdwr
Copy link
Collaborator

fdwr commented May 11, 2024

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt

Oh interesting. So making the change in Chromium land actually pushes it back into web-platform-tests/wpt.

@inexorabletash
Copy link
Contributor

Yeah, we have two-way sync set up with WPT. Mozilla and Apple have something similar. It's not perfect and requires some babysitting, but it's super great when it works.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 13, 2024
crrev.com/c/5496321 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 13, 2024
crrev.com/c/5496321 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 13, 2024
crrev.com/c/5496321 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 13, 2024
crrev.com/c/5496321 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 13, 2024
crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 14, 2024
crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 14, 2024
crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 14, 2024
crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
aarongable pushed a commit to chromium/chromium that referenced this issue May 15, 2024
crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5529350
Reviewed-by: Phillis Tang <phillis@chromium.org>
Reviewed-by: ningxin hu <ningxin.hu@intel.com>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1301369}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 15, 2024
crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5529350
Reviewed-by: Phillis Tang <phillis@chromium.org>
Reviewed-by: ningxin hu <ningxin.hu@intel.com>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1301369}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 15, 2024
crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5529350
Reviewed-by: Phillis Tang <phillis@chromium.org>
Reviewed-by: ningxin hu <ningxin.hu@intel.com>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1301369}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue May 23, 2024
…testonly

Automatic update from web-platform-tests
WebNN: Allow 0-D (scalar) reductions

crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try​:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5529350
Reviewed-by: Phillis Tang <phillis@chromium.org>
Reviewed-by: ningxin hu <ningxin.hu@intel.com>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1301369}

--

wpt-commits: 22a06eb294cd23846add1c8ca8e234bc9d7260c6
wpt-pr: 46209
jamienicol pushed a commit to jamienicol/gecko that referenced this issue May 24, 2024
…testonly

Automatic update from web-platform-tests
WebNN: Allow 0-D (scalar) reductions

crrev.com/c/5448942 added a restriction on the reduction ops
(including argMin/argMax) that the rank of the input tensor must be
greater than zero.

In webmachinelearning/webnn#681, @fdwr
points out that 0-D (scalar) reductions are fine, it's just a no-op.
Per that discussion, this removes a restriction. There are already
WPT cases for argMin/argMax (although they fail for other reasons);
cases are added for the plethora of reduction ops (which also fail
for other reasons).

Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f
Cq-Include-Trybots: luci.chromium.try​:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5529350
Reviewed-by: Phillis Tang <phillis@chromium.org>
Reviewed-by: ningxin hu <ningxin.hu@intel.com>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1301369}

--

wpt-commits: 22a06eb294cd23846add1c8ca8e234bc9d7260c6
wpt-pr: 46209
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants