Files
sousa-gecko/testing/web-platform/tests/webnn/validation_tests/reshape.https.any.js
T
Ningxin Hu c2c6c6c97c Bug 1989415 [wpt PR 54932] - Reland "WebNN: Support rankRange for op output tensors in opSupportLimits", a=testonly
Automatic update from web-platform-tests
Reland "WebNN: Support rankRange for op output tensors in opSupportLimits"

This is a reland of commit 6591b48a057a42cc1a621b2e7b74aa35157c2bd5

This reland fixes WPT failures for CoreML by keeping the error message
consistent and adding the WPT rebaseline results.

Because blink-side can validate the rank range of operation output,
graph input and output, this reland removes the async error handling
for reshape output, graph input and output in CoreML backend.

Original change's description:
> WebNN: Support rankRange for op output tensors in opSupportLimits
>
> This CL prototypes WebNN spec change [1] that supports tensor rank
> range for graph input, constant, output and each operation's output.
>
> This CL adds new shape rank validation according to allowed output
> tensor rank of expand and reshape operations.
>
> The sequence output of gru and cell operations has different rank,
> this CL extends context properties to support them.
>
> For logical ops, the output rank ranges are set to each op's input
> rank ranges, while the output data types are set to unified logical
> output data type of context properties.
>
> [1]: https://github.com/webmachinelearning/webnn/pull/857
>
> Bug: 442209350
> Change-Id: Ie5ca5c794cebb4586bcccaaa8d237be1dffea458
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6903617
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Reviewed-by: Alex Gough <ajgo@chromium.org>
> Commit-Queue: ningxin hu <ningxin.hu@intel.com>
> Cr-Commit-Position: refs/heads/main@{#1516982}

Bug: 442209350, 445793611
Change-Id: Id666c89b8860abe06bac9a1e912057887c3fe03f
Cq-Include-Trybots: luci.chromium.try​:win11-blink-rel, mac14.arm64-blink-rel, mac14-blink-rel, mac15.arm64-blink-rel, mac15-blink-rel, linux-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6963704
Reviewed-by: Alex Gough <ajgo@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: ningxin hu <ningxin.hu@intel.com>
Cr-Commit-Position: refs/heads/main@{#1517665}

--

wpt-commits: 611eeeaf5144cc732b63b68a716bc1d1cbd96cbf
wpt-pr: 54932
2025-09-24 11:05:21 +00:00

101 lines
3.3 KiB
JavaScript

// META: title=validation tests for WebNN API reshape operation
// META: global=window
// META: variant=?cpu
// META: variant=?gpu
// META: variant=?npu
// META: script=../resources/utils_validation.js
'use strict';
multi_builder_test(async (t, builder, otherBuilder) => {
const inputFromOtherBuilder =
otherBuilder.input('input', {dataType: 'float32', shape: [1, 2, 3]});
const newShape = [3, 2, 1];
assert_throws_js(
TypeError, () => builder.reshape(inputFromOtherBuilder, newShape));
}, '[reshape] throw if input is from another builder');
const tests = [
{
name: '[reshape] Test with new shape=[3, 8].',
input: {dataType: 'float32', shape: [2, 3, 4]},
newShape: [3, 8],
output: {dataType: 'float32', shape: [3, 8]}
},
{
name: '[reshape] Test with new shape=[24], src shape=[2, 3, 4].',
input: {dataType: 'float32', shape: [2, 3, 4]},
newShape: [24],
output: {dataType: 'float32', shape: [24]}
},
{
name: '[reshape] Test with new shape=[1], src shape=[1].',
input: {dataType: 'float32', shape: [1]},
newShape: [1],
output: {dataType: 'float32', shape: [1]}
},
{
name: '[reshape] Test reshaping a 1-D 1-element tensor to scalar.',
input: {dataType: 'float32', shape: [1]},
newShape: [],
output: {dataType: 'float32', shape: []}
},
{
name: '[reshape] Test reshaping a scalar to 1-D 1-element tensor.',
input: {dataType: 'float32', shape: []},
newShape: [1],
output: {dataType: 'float32', shape: [1]}
},
{
name: '[reshape] Throw if one value of new shape is 0.',
input: {dataType: 'float32', shape: [2, 4]},
newShape: [2, 4, 0],
},
{
name:
'[reshape] Throw if the number of elements implied by new shape is not equal to the number of elements in the input tensor when new shape=[].',
input: {dataType: 'float32', shape: [2, 3, 4]},
newShape: [],
},
{
name:
'[reshape] Throw if the number of elements implied by new shape is not equal to the number of elements in the input tensor.',
input: {dataType: 'float32', shape: [2, 3, 4]},
newShape: [3, 9],
},
];
tests.forEach(
test => promise_test(async t => {
const builder = new MLGraphBuilder(context);
const input = builder.input('input', test.input);
if (test.output) {
const output = builder.reshape(input, test.newShape);
assert_equals(output.dataType, test.output.dataType);
assert_array_equals(output.shape, test.output.shape);
} else {
const label = 'reshape_xxx';
const options = {label};
const regrexp = new RegExp('\\[' + label + '\\]');
assert_throws_with_label(
() => builder.reshape(input, test.newShape, options), regrexp);
}
}, test.name));
promise_test(async t => {
const builder = new MLGraphBuilder(context);
const input = builder.input('input', {dataType: 'float32', shape: [2]});
const newShape =
new Array(context.opSupportLimits().expand.output.rankRange.max + 1)
.fill(1);
newShape[0] = 2;
const label = 'reshape_xxx';
const options = {label};
const regrexp = new RegExp('\\[' + label + '\\]');
assert_throws_with_label(
() => builder.reshape(input, newShape, options), regrexp);
}, '[expand] throw if new shape rank exceeds limit');