Skip to content

Commit c9c3a0c

Browse files
huningxinchromium-wpt-export-bot
authored andcommitted
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]: webmachinelearning/webnn#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}
1 parent 40fc257 commit c9c3a0c

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

webnn/validation_tests/expand.https.any.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ multi_builder_test(async (t, builder, otherBuilder) => {
1717
}, '[expand] throw if input is from another builder');
1818

1919
const label = 'xxx_expand';
20-
const regrexp = new RegExp('\\[' + label + '\\]');
20+
const regexp = new RegExp('\\[' + label + '\\]');
2121
const tests = [
2222
{
2323
name: '[expand] Test with 0-D scalar to 3-D tensor.',
@@ -77,7 +77,7 @@ tests.forEach(
7777
const options = {...test.options};
7878
if (options.label) {
7979
assert_throws_with_label(
80-
() => builder.expand(input, test.newShape, options), regrexp);
80+
() => builder.expand(input, test.newShape, options), regexp);
8181
} else {
8282
assert_throws_js(
8383
TypeError, () => builder.expand(input, test.newShape, options));
@@ -113,5 +113,19 @@ promise_test(async t => {
113113

114114
const options = {label};
115115
assert_throws_with_label(
116-
() => builder.expand(input, newShape, options), regrexp);
116+
() => builder.expand(input, newShape, options), regexp);
117117
}, '[expand] throw if the output tensor byte length exceeds limit');
118+
119+
promise_test(async t => {
120+
const builder = new MLGraphBuilder(context);
121+
122+
const input = builder.input('input', {dataType: 'float32', shape: [2]});
123+
const newShape =
124+
new Array(context.opSupportLimits().expand.output.rankRange.max + 1)
125+
.fill(1);
126+
newShape[newShape.length - 1] = 2;
127+
128+
const options = {label};
129+
assert_throws_with_label(
130+
() => builder.expand(input, newShape, options), regexp);
131+
}, '[expand] throw if new shape rank exceeds limit');

webnn/validation_tests/reshape.https.any.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,19 @@ tests.forEach(
8282
() => builder.reshape(input, test.newShape, options), regrexp);
8383
}
8484
}, test.name));
85+
86+
promise_test(async t => {
87+
const builder = new MLGraphBuilder(context);
88+
89+
const input = builder.input('input', {dataType: 'float32', shape: [2]});
90+
const newShape =
91+
new Array(context.opSupportLimits().expand.output.rankRange.max + 1)
92+
.fill(1);
93+
newShape[0] = 2;
94+
95+
const label = 'reshape_xxx';
96+
const options = {label};
97+
const regrexp = new RegExp('\\[' + label + '\\]');
98+
assert_throws_with_label(
99+
() => builder.reshape(input, newShape, options), regrexp);
100+
}, '[expand] throw if new shape rank exceeds limit');

0 commit comments

Comments
 (0)