From 536c5951f70d77c0be08552be6bd5bbc2a082e5c Mon Sep 17 00:00:00 2001 From: Phillis Tang Date: Fri, 23 Aug 2024 13:24:10 -0700 Subject: [PATCH] webnn: support all axes for resample2d Allow arbitrary axes as long as they are valid dimensions for resample2d instead of restricting them to point to spacial dimensions. Apply transposes for input & output when the axes is not supported by the backend. See spec pr: https://github.com/webmachinelearning/webnn/pull/752 Change-Id: I5112abf1f43328d901000a4cff8468bd9bfe2dfb Cq-Include-Trybots: luci.chromium.try:win11-blink-rel,mac14.arm64-blink-rel,mac14-blink-rel, linux-blink-rel Bug: 329658123, 334914468 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5798093 Commit-Queue: Phillis Tang Reviewed-by: ningxin hu Reviewed-by: Alex Gough Cr-Commit-Position: refs/heads/main@{#1346174} --- .../conformance_tests/resample2d.https.any.js | 112 ++++++++++++++++++ .../validation_tests/resample2d.https.any.js | 19 +-- 2 files changed, 122 insertions(+), 9 deletions(-) diff --git a/webnn/conformance_tests/resample2d.https.any.js b/webnn/conformance_tests/resample2d.https.any.js index bedd348fe58961..65faca22abdddb 100644 --- a/webnn/conformance_tests/resample2d.https.any.js +++ b/webnn/conformance_tests/resample2d.https.any.js @@ -278,6 +278,44 @@ const resample2dTests = [ } } }, + { + 'name': + 'resample2d(upsample) float32 4D tensor explicit options.axes=[3, 2]', + 'graph': { + 'inputs': { + 'resample2dInput': { + 'data': [ + 59.92947006225586, 41.98918914794922, 66.39534759521484, + 90.7006607055664, 86.95105743408203, 79.10005187988281 + ], + 'descriptor': {'dimensions': [1, 1, 2, 3], 'dataType': 'float32'} + } + }, + 'operators': [{ + 'name': 'resample2d', + 'arguments': [ + {'input': 'resample2dInput'}, + {'options': {'sizes': [6, 4], 'axes': [3, 2]}} + ], + 'outputs': 'resample2dOutput' + }], + 'expectedOutputs': { + 'resample2dOutput': { + 'data': [ + 59.92947006225586, 59.92947006225586, 41.98918914794922, + 41.98918914794922, 66.39534759521484, 66.39534759521484, + 59.92947006225586, 59.92947006225586, 41.98918914794922, + 41.98918914794922, 66.39534759521484, 66.39534759521484, + 90.7006607055664, 90.7006607055664, 86.95105743408203, + 86.95105743408203, 79.10005187988281, 79.10005187988281, + 90.7006607055664, 90.7006607055664, 86.95105743408203, + 86.95105743408203, 79.10005187988281, 79.10005187988281 + ], + 'descriptor': {'dimensions': [1, 1, 4, 6], 'dataType': 'float32'} + } + } + } + }, { 'name': 'resample2d(upsample) float32 4D tensor explicit options.mode=\'nearest-neighbor\'', @@ -429,6 +467,80 @@ const resample2dTests = [ } } } + }, + { + 'name': 'resample2d(upsample) float32 4D tensor options.axes=[0, 1]', + 'graph': { + 'inputs': { + 'resample2dInput': { + 'data': [ + 59.92947006225586, 90.7006607055664, 41.98918914794922, + 86.95105743408203, 66.39534759521484, 79.10005187988281 + ], + 'descriptor': {'dimensions': [3, 2, 1, 1], 'dataType': 'float32'} + } + }, + 'operators': [{ + 'name': 'resample2d', + 'arguments': [ + {'input': 'resample2dInput'}, + {'options': {'sizes': [6, 4], 'axes': [0, 1]}} + ], + 'outputs': 'resample2dOutput' + }], + 'expectedOutputs': { + 'resample2dOutput': { + 'data': [ + 59.92947006225586, 59.92947006225586, 90.7006607055664, + 90.7006607055664, 59.92947006225586, 59.92947006225586, + 90.7006607055664, 90.7006607055664, 41.98918914794922, + 41.98918914794922, 86.95105743408203, 86.95105743408203, + 41.98918914794922, 41.98918914794922, 86.95105743408203, + 86.95105743408203, 66.39534759521484, 66.39534759521484, + 79.10005187988281, 79.10005187988281, 66.39534759521484, + 66.39534759521484, 79.10005187988281, 79.10005187988281 + ], + 'descriptor': {'dimensions': [6, 4, 1, 1], 'dataType': 'float32'} + } + } + } + }, + { + 'name': 'resample2d(upsample) float32 4D tensor options.axes=[1, 0]', + 'graph': { + 'inputs': { + 'resample2dInput': { + 'data': [ + 59.92947006225586, 90.7006607055664, 41.98918914794922, + 86.95105743408203, 66.39534759521484, 79.10005187988281 + ], + 'descriptor': {'dimensions': [3, 2, 1, 1], 'dataType': 'float32'} + } + }, + 'operators': [{ + 'name': 'resample2d', + 'arguments': [ + {'input': 'resample2dInput'}, + {'options': {'sizes': [4, 6], 'axes': [1, 0]}} + ], + 'outputs': 'resample2dOutput' + }], + 'expectedOutputs': { + 'resample2dOutput': { + 'data': [ + 59.92947006225586, 59.92947006225586, 90.7006607055664, + 90.7006607055664, 59.92947006225586, 59.92947006225586, + 90.7006607055664, 90.7006607055664, 41.98918914794922, + 41.98918914794922, 86.95105743408203, 86.95105743408203, + 41.98918914794922, 41.98918914794922, 86.95105743408203, + 86.95105743408203, 66.39534759521484, 66.39534759521484, + 79.10005187988281, 79.10005187988281, 66.39534759521484, + 66.39534759521484, 79.10005187988281, 79.10005187988281 + ], + 'descriptor': {'dimensions': [6, 4, 1, 1], 'dataType': 'float32'} + } + } + } } ]; diff --git a/webnn/validation_tests/resample2d.https.any.js b/webnn/validation_tests/resample2d.https.any.js index a07a9b4ca58335..dd9916aefe099c 100644 --- a/webnn/validation_tests/resample2d.https.any.js +++ b/webnn/validation_tests/resample2d.https.any.js @@ -55,6 +55,16 @@ const tests = [ options: {scales: [2.0, 2.0], sizes: [3, 6]}, output: {dataType: 'float32', dimensions: [1, 1, 3, 6]}, }, + { + name: + '[resample2d] Test building resample2d with non consecutive axes=[0,2]', + input: {dataType: 'float32', dimensions: [1, 1, 2, 4]}, + options: { + axes: [0, 2], + label: label, + }, + output: {dataType: 'float32', dimensions: [1, 1, 2, 4]}, + }, { name: '[resample2d] Throw if the dataType of input is not float32 or float16', @@ -177,15 +187,6 @@ const tests = [ label: label, }, }, - { - // The valid values in the axes sequence are [0, 1], [1, 2] or [2, 3] - name: '[resample2d] Throw if the values of axes are inconsecutive', - input: {dataType: 'float32', dimensions: [1, 1, 2, 4]}, - options: { - axes: [0, 2], - label: label, - }, - }, { name: '[resample2d] Throw if the values of axes are same', input: {dataType: 'float32', dimensions: [1, 1, 2, 4]},