Skip to content

Commit

Permalink
Bug 1894159 [wpt PR 45974] - webnn: Enforce data type constraints for…
Browse files Browse the repository at this point in the history
… averagePool2d and l2Pool2d, a=testonly

Automatic update from web-platform-tests
webnn: Enforce data type constraints for averagePool2d and l2Pool2d

As specified in webmachinelearning/webnn#646

Bug: 328567884
Change-Id: If0ea256805b5cfebdf15e0727fbc91acab918bbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5500424
Reviewed-by: Austin Sullivan <[email protected]>
Auto-Submit: Shiyi Zou <[email protected]>
Commit-Queue: Shiyi Zou <[email protected]>
Reviewed-by: ningxin hu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1297393}

--

wpt-commits: 8420f5224b6c558c67a32052f1148eca46245003
wpt-pr: 45974
  • Loading branch information
shiyi9801 authored and moz-wptsync-bot committed May 14, 2024
1 parent cd51617 commit 72c9469
Showing 1 changed file with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ kPoolingOperators.forEach((operatorName) => {
operatorName, {dataType: 'float32', dimensions: [2, 2, 2, 2]});
});


const tests = [
{
name: 'Test pool2d with default options.',
Expand All @@ -20,11 +19,11 @@ const tests = [
},
{
name: 'Test pool2d with windowDimensions',
input: {dataType: 'float32', dimensions: [1, 3, 4, 4]},
input: {dataType: 'float16', dimensions: [1, 3, 4, 4]},
options: {
windowDimensions: [3, 3],
},
output: {dataType: 'float32', dimensions: [1, 3, 2, 2]}
output: {dataType: 'float16', dimensions: [1, 3, 2, 2]}
},
{
name: 'Test pool2d with padding.',
Expand All @@ -37,12 +36,12 @@ const tests = [
},
{
name: 'Test pool2d with strides.',
input: {dataType: 'float32', dimensions: [1, 3, 5, 5]},
input: {dataType: 'float16', dimensions: [1, 3, 5, 5]},
options: {
windowDimensions: [2, 2],
strides: [2, 2],
},
output: {dataType: 'float32', dimensions: [1, 3, 2, 2]}
output: {dataType: 'float16', dimensions: [1, 3, 2, 2]}
},
{
name: 'Test pool2d with strides and padding.',
Expand Down Expand Up @@ -77,14 +76,14 @@ const tests = [
},
{
name: 'Test pool2d with strides, padding and roundingType="ceil".',
input: {dataType: 'float32', dimensions: [1, 3, 7, 7]},
input: {dataType: 'float16', dimensions: [1, 3, 7, 7]},
options: {
windowDimensions: [4, 4],
padding: [1, 1, 1, 1],
strides: [2, 2],
roundingType: 'ceil',
},
output: {dataType: 'float32', dimensions: [1, 3, 4, 4]}
output: {dataType: 'float16', dimensions: [1, 3, 4, 4]}
},
{
name: 'Test pool2d with explicit outputSizes ignored roundingType',
Expand Down Expand Up @@ -131,12 +130,12 @@ const tests = [
},
{
name: 'Test pool2d with layout="nhwc".',
input: {dataType: 'float32', dimensions: [1, 5, 5, 2]},
input: {dataType: 'float16', dimensions: [1, 5, 5, 2]},
options: {
windowDimensions: [3, 3],
layout: 'nhwc',
},
output: {dataType: 'float32', dimensions: [1, 3, 3, 2]}
output: {dataType: 'float16', dimensions: [1, 3, 3, 2]}
},
{
name: 'Throw if the input is not a 4-D tensor.',
Expand Down Expand Up @@ -273,3 +272,24 @@ tests.forEach(
}
});
}, test.name));

['int32', 'uint32', 'int8', 'uint8'].forEach(
dataType => promise_test(async t => {
const input = builder.input(
'input', {dataType: dataType, dimensions: [1, 3, 4, 4]});
const output = builder.maxPool2d(input);
assert_equals(output.dataType(), dataType);
assert_array_equals(output.shape(), [1, 3, 1, 1]);
}, `[maxPool2d] Test maxPool2d with data type ${dataType}`));

promise_test(async t => {
const input =
builder.input('input', {dataType: 'int64', dimensions: [1, 2, 3, 3]});
assert_throws_js(TypeError, () => builder.averagePool2d(input));
}, '[averagePool2d] Throw if the input data type is not floating point');

promise_test(async t => {
const input =
builder.input('input', {dataType: 'uint8', dimensions: [1, 2, 4, 4]});
assert_throws_js(TypeError, () => builder.l2Pool2d(input));
}, '[l2Pool2d] Throw if the input data type is not floating point');

0 comments on commit 72c9469

Please sign in to comment.