Skip to content

Bugfix: Allow 0-D output for gather() - #953

Merged
fdwr merged 1 commit into
webmachinelearning:mainfrom
huningxin:gather-allow-0d-output
Sep 4, 2026
Merged

Bugfix: Allow 0-D output for gather()#953
fdwr merged 1 commit into
webmachinelearning:mainfrom
huningxin:gather-allow-0d-output

Conversation

@huningxin

Copy link
Copy Markdown
Contributor

The indices operand already allows rank 0, and the output rank is rank(input) + rank(indices) - 1. So a rank-1 input gathered with scalar indices produces a rank-0 output.

The algorithm steps needed no change; they already produce an empty output shape for this case.

Fixes #946

The indices operand already allows rank 0, and the output rank is
rank(input) + rank(indices) - 1. So a rank-1 input gathered with scalar
indices legitimately produces a rank-0 output, e.g. input of shape [4]
with indices of shape [] and axis 0 yields output of shape [].

The output row of the tensor limits table set the minimum rank to 1,
which rejected that case. Relax it to allow rank 0, matching both the
indices row and gatherND()'s output row.

The algorithm steps needed no change; they already produce an empty
output shape for this case.

Fixes webmachinelearning#946
@huningxin
huningxin requested a review from fdwr September 4, 2026 22:46

@fdwr fdwr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@fdwr
fdwr merged commit f4a9b25 into webmachinelearning:main Sep 4, 2026
2 checks passed
github-actions Bot added a commit that referenced this pull request Sep 4, 2026
SHA: f4a9b25
Reason: push, by fdwr

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
beckysiegel pushed a commit to chromium/chromium that referenced this pull request Sep 9, 2026
This CL updates the minimum allowed rank of gather's output to 0 in
required_datatypes_ranks.json by executing the script
tools/generate-required-datatypes-ranks.py, per Spec change [1].

No new conformance tests are needed: the existing conformance tests
and validation tests already exercise the 0-D output path.

[1] Spec change: webmachinelearning/webnn#953

Change-Id: If127608d7e5cf80a402e0544169e9fa67237d66c
Bug: 557288874
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8361354
Auto-Submit: Dai, Feng <feng.dai@intel.com>
Reviewed-by: Hu, Ningxin <ningxin.hu@intel.com>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Hu, Ningxin <ningxin.hu@intel.com>
Cr-Commit-Position: refs/heads/main@{#1694279}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 9, 2026
This CL updates the minimum allowed rank of gather's output to 0 in
required_datatypes_ranks.json by executing the script
tools/generate-required-datatypes-ranks.py, per Spec change [1].

No new conformance tests are needed: the existing conformance tests
and validation tests already exercise the 0-D output path.

[1] Spec change: webmachinelearning/webnn#953

Change-Id: If127608d7e5cf80a402e0544169e9fa67237d66c
Bug: 557288874
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8361354
Auto-Submit: Dai, Feng <feng.dai@intel.com>
Reviewed-by: Hu, Ningxin <ningxin.hu@intel.com>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Hu, Ningxin <ningxin.hu@intel.com>
Cr-Commit-Position: refs/heads/main@{#1694279}
lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request Sep 11, 2026
…tor, a=testonly

Automatic update from web-platform-tests
webnn: allow 0-D output for gather operator

This CL updates the minimum allowed rank of gather's output to 0 in
required_datatypes_ranks.json by executing the script
tools/generate-required-datatypes-ranks.py, per Spec change [1].

No new conformance tests are needed: the existing conformance tests
and validation tests already exercise the 0-D output path.

[1] Spec change: webmachinelearning/webnn#953

Change-Id: If127608d7e5cf80a402e0544169e9fa67237d66c
Bug: 557288874
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8361354
Auto-Submit: Dai, Feng <feng.dai@intel.com>
Reviewed-by: Hu, Ningxin <ningxin.hu@intel.com>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Hu, Ningxin <ningxin.hu@intel.com>
Cr-Commit-Position: refs/heads/main@{#1694279}

--

wpt-commits: fadb01bc53cd4a9fac9352c977df1787425b856e
wpt-pr: 62541
mtavenrath pushed a commit to rustnn/rustnn that referenced this pull request Sep 13, 2026
Gather index normalization currently replaces dynamic dimensions with
their maximum extents. The model interface and dispatch also use those
maxima, preventing active-sized inputs from reaching CoreML correctly.

This preserves dynamic dimensions through `gather`, `gatherElements`,
and `gatherND` normalization, adds matching model shape ranges
(including integer proxy outputs), and binds the active input dimensions
with checked byte lengths. Dispatch now rejects oversized results
instead of silently truncating them.

Scalar gathers also bypassed normalization: gathering index `-1` from
`[10, 20, 30]` returned `10` instead of `30`. Normalize constant and
runtime scalar indices while preserving WebNN rank-zero results and
CoreML's `[1]` feature boundary, consistent with
[webmachinelearning/webnn#953](webmachinelearning/webnn#953).

Related to [#222](#222). Dynamic
behavior remains behind `dynamic-inputs`; this complements the proposed
host-side shape evaluation in
[#225](#225). Dynamic gathered-axis
bounds, runtime reshape/slice lowering, and empty KV-cache behavior
remain separate work.

Validation on the M4:

- Formatting and strict Clippy passed; 356 default, 364 CoreML, and 376
CoreML/dynamic Rust tests passed.
- Locally compiled CoreML models returned exact values for all three
gather variants over active lengths `1 -> 4 -> 2 -> 1`, including
negative/out-of-range indices; constant and runtime scalar cases passed.
Converter tests cover mixed dimensions, axis removal, and integer proxy
metadata.
- CoreML WPT: 2,461 passed, 40 skipped, and the same 20 negative-index
scatter failures as clean `main` (`04fc5f4`), using [WPT
`04cd4a8`](web-platform-tests/wpt@04cd4a8).
The previously skipped scalar out-of-range positive gather case now
passes; no expectations or snapshot changes.

No newer CoreML operations or APIs are introduced. Physical iOS
18.x/watchOS 11.x validation has not been rerun for this patch.
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.

gather should allow 0D output

2 participants