Automatic update from web-platform-tests
Reland "webnn: rename roundingType to outputShapeRounding for pool2d ops"
This is a reland of commit e5811467122a07253805711cf7331c2de1741f1d.
The original CL was reverted because two newly-added baseline files
under platform/win11-arm64/virtual/webnn-service-on-cpu/... still
referenced the old "roundingType" test names, which no longer matched
the renamed WPT cases ("outputShapeRounding"). Those baselines are
updated in this reland.
Original change's description:
> webnn: rename roundingType to outputShapeRounding for pool2d ops
>
> This CL renames MLPool2dOptions::roundingType to
> MLPool2dOptions::outputShapeRounding in test files and implementations
> according to Spec change [1].
>
> [1] https://github.com/webmachinelearning/webnn/pull/770
>
> Bug: 498118207
> Change-Id: I815c7f7728071144835c0ada0747bc9de2999669
> Cq-Include-Trybots: luci.chromium.try:mac14.arm64-blink-rel, mac15.arm64-blink-rel, mac15-blink-rel, linux-blink-rel
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7717139
> Reviewed-by: Hu, Ningxin <ningxin.hu@intel.com>
> Reviewed-by: Reilly Grant <reillyg@chromium.org>
> Reviewed-by: Alex Gough <ajgo@chromium.org>
> Auto-Submit: Dai, Feng <feng.dai@intel.com>
> Commit-Queue: Dai, Feng <feng.dai@intel.com>
> Cr-Commit-Position: refs/heads/main@{#1618021}
Bug: 498118207
Change-Id: I4df2860081223af43493a0447ca5e69e104950df
Cq-Include-Trybots: luci.chromium.try:win11-blink-rel, win11-arm64-blink-rel, mac14.arm64-blink-rel, mac15.arm64-blink-rel, mac15-blink-rel, linux-blink-rel
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7882018
Reviewed-by: Joe Mason <joenotcharles@google.com>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Hu, Ningxin <ningxin.hu@intel.com>
Commit-Queue: Dai, Feng <feng.dai@intel.com>
Reviewed-by: Elias Klim <elklm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1639919}
--
wpt-commits: 58938037e8fd81f7a51b89985141c39ccf6922b1
wpt-pr: 60329
351 lines
9.8 KiB
JavaScript
351 lines
9.8 KiB
JavaScript
// META: title=validation tests for WebNN API pooling operation
|
|
// META: global=window
|
|
// META: variant=?cpu
|
|
// META: variant=?gpu
|
|
// META: variant=?npu
|
|
// META: script=../resources/utils_validation.js
|
|
|
|
'use strict';
|
|
|
|
const kPoolingOperators = ['averagePool2d', 'l2Pool2d', 'maxPool2d'];
|
|
|
|
kPoolingOperators.forEach((operatorName) => {
|
|
validateInputFromAnotherBuilder(
|
|
operatorName, {dataType: 'float32', shape: [2, 2, 2, 2]});
|
|
});
|
|
|
|
const label = 'pool_2d_xxx';
|
|
const tests = [
|
|
{
|
|
name: 'Test pool2d with default options.',
|
|
input: {dataType: 'float32', shape: [1, 3, 4, 4]},
|
|
output: {dataType: 'float32', shape: [1, 3, 1, 1]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with windowDimensions',
|
|
input: {dataType: 'float16', shape: [1, 3, 4, 4]},
|
|
options: {
|
|
windowDimensions: [3, 3],
|
|
},
|
|
output: {dataType: 'float16', shape: [1, 3, 2, 2]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with padding.',
|
|
input: {dataType: 'float32', shape: [1, 3, 5, 5]},
|
|
options: {
|
|
windowDimensions: [5, 5],
|
|
padding: [2, 2, 2, 2],
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 3, 5, 5]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with strides.',
|
|
input: {dataType: 'float16', shape: [1, 3, 5, 5]},
|
|
options: {
|
|
windowDimensions: [2, 2],
|
|
strides: [2, 2],
|
|
},
|
|
output: {dataType: 'float16', shape: [1, 3, 2, 2]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with strides and padding.',
|
|
input: {dataType: 'float32', shape: [1, 3, 5, 5]},
|
|
options: {
|
|
windowDimensions: [3, 3],
|
|
padding: [1, 1, 1, 1],
|
|
strides: [2, 2],
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 3, 3, 3]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with strides and asymmetric padding.',
|
|
input: {dataType: 'float32', shape: [1, 3, 7, 7]},
|
|
options: {
|
|
windowDimensions: [4, 4],
|
|
padding: [2, 1, 2, 1],
|
|
strides: [2, 2],
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 3, 4, 4]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with strides, padding and outputShapeRounding="floor".',
|
|
input: {dataType: 'float32', shape: [1, 3, 7, 7]},
|
|
options: {
|
|
windowDimensions: [4, 4],
|
|
padding: [1, 1, 1, 1],
|
|
strides: [2, 2],
|
|
outputShapeRounding: 'floor',
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 3, 3, 3]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with strides, padding and outputShapeRounding="ceil".',
|
|
input: {dataType: 'float16', shape: [1, 3, 7, 7]},
|
|
options: {
|
|
windowDimensions: [4, 4],
|
|
padding: [1, 1, 1, 1],
|
|
strides: [2, 2],
|
|
outputShapeRounding: 'ceil',
|
|
},
|
|
output: {dataType: 'float16', shape: [1, 3, 4, 4]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with explicit outputSizes ignored outputShapeRounding',
|
|
input: {dataType: 'float32', shape: [1, 3, 7, 7]},
|
|
options: {
|
|
windowDimensions: [4, 4],
|
|
padding: [1, 1, 1, 1],
|
|
strides: [2, 2],
|
|
outputShapeRounding: 'ceil',
|
|
outputSizes: [3, 3],
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 3, 3, 3]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with strides, padding and outputSizes=[3, 3].',
|
|
input: {dataType: 'float32', shape: [1, 3, 7, 7]},
|
|
options: {
|
|
windowDimensions: [4, 4],
|
|
padding: [1, 1, 1, 1],
|
|
strides: [2, 2],
|
|
outputSizes: [3, 3],
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 3, 3, 3]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with strides, padding and outputSizes=[4, 4].',
|
|
input: {dataType: 'float32', shape: [1, 3, 7, 7]},
|
|
options: {
|
|
windowDimensions: [4, 4],
|
|
padding: [1, 1, 1, 1],
|
|
strides: [2, 2],
|
|
outputSizes: [4, 4],
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 3, 4, 4]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with layout="nchw".',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [3, 3],
|
|
layout: 'nchw',
|
|
},
|
|
output: {dataType: 'float32', shape: [1, 2, 3, 3]}
|
|
},
|
|
{
|
|
name: 'Test pool2d with layout="nhwc".',
|
|
input: {dataType: 'float16', shape: [1, 5, 5, 2]},
|
|
options: {
|
|
windowDimensions: [3, 3],
|
|
layout: 'nhwc',
|
|
},
|
|
output: {dataType: 'float16', shape: [1, 3, 3, 2]}
|
|
},
|
|
{
|
|
name: 'Throw if the input is not a 4-D tensor.',
|
|
input: {dataType: 'float32', shape: [1, 5, 5]},
|
|
options: {label},
|
|
},
|
|
{
|
|
name: 'Throw if the output sizes is incorrect.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [2, 2],
|
|
padding: [2, 2, 2, 2],
|
|
strides: [2, 2],
|
|
outputSizes: [3, 3],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the length of output sizes is not 2.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [2, 2],
|
|
padding: [2, 2, 2, 2],
|
|
strides: [2, 2],
|
|
outputSizes: [1, 2, 4, 4],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if outputSizes[0] is not greater than 0.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [2, 2],
|
|
padding: [2, 2, 2, 2],
|
|
strides: [2, 2],
|
|
outputSizes: [0, 4],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if outputSizes[1] is not greater than 0.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [2, 2],
|
|
padding: [2, 2, 2, 2],
|
|
strides: [2, 2],
|
|
outputSizes: [4, 0],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the length of window dimensions is not 2.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [1, 1, 1, 1],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if any window dimension is lesser than 1.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [0, 2],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name:
|
|
'Throw if the input height is too small to fill the pool window height.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [8, 2],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name:
|
|
'Throw if the input width is too small to fill the pool window width.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [2, 8],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the calculated output height is equal to 0.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [6, 3],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the calculated output width is equal to 0.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
windowDimensions: [3, 6],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the length of padding is not 4.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
padding: [2, 2],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the length of strides is not 2.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
strides: [2],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if one stride value is smaller than 1.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
strides: [0, 2],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the length of dilations is not 2.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
dilations: [1, 1, 2],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if one dilation value is smaller than 1.',
|
|
input: {dataType: 'float32', shape: [1, 2, 5, 5]},
|
|
options: {
|
|
dilations: [1, 0],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the padding height value is too large',
|
|
input: {dataType: 'float32', shape: [1, 3, 5, 5]},
|
|
options: {
|
|
padding: [kMaxUnsignedLong, kMaxUnsignedLong, 0, 0],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the padding width value is too large',
|
|
input: {dataType: 'float32', shape: [1, 3, 5, 5]},
|
|
options: {
|
|
padding: [0, 0, kMaxUnsignedLong, kMaxUnsignedLong],
|
|
label: label,
|
|
},
|
|
},
|
|
{
|
|
name: 'Throw if the product of window dimensions is too large',
|
|
input: {dataType: 'float16', shape: [1, 1, 1, 1]},
|
|
options: {
|
|
windowDimensions: [1000092567, 1152814792],
|
|
padding: [500046283, 500046283, 576407395, 576407396],
|
|
strides: [1, 1],
|
|
layout: 'nhwc',
|
|
label: label,
|
|
},
|
|
},
|
|
];
|
|
|
|
tests.forEach(
|
|
test => promise_test(async t => {
|
|
const builder = new MLGraphBuilder(context);
|
|
const input = builder.input('input', test.input);
|
|
kPoolingOperators.forEach((operatorName) => {
|
|
if (test.output) {
|
|
const output = builder[operatorName](input, test.options);
|
|
assert_equals(output.dataType, test.output.dataType);
|
|
assert_array_equals(output.shape, test.output.shape);
|
|
} else {
|
|
const regrexp = new RegExp('\\[' + label + '\\]');
|
|
assert_throws_with_label(
|
|
() => builder[operatorName](input, test.options), regrexp);
|
|
}
|
|
});
|
|
}, test.name));
|
|
|
|
['int32', 'uint32', 'int8', 'uint8'].forEach(
|
|
dataType => promise_test(async t => {
|
|
const builder = new MLGraphBuilder(context);
|
|
const input = builder.input('input', {dataType, shape: [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 builder = new MLGraphBuilder(context);
|
|
const input =
|
|
builder.input('input', {dataType: 'int64', shape: [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 builder = new MLGraphBuilder(context);
|
|
const input =
|
|
builder.input('input', {dataType: 'uint8', shape: [1, 2, 4, 4]});
|
|
assert_throws_js(TypeError, () => builder.l2Pool2d(input));
|
|
}, '[l2Pool2d] Throw if the input data type is not floating point');
|