From 118087863d57eb145951889e856064215b1df2ae Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Fri, 10 May 2024 16:14:36 -0700 Subject: [PATCH] WebNN: Allow 0-D (scalar) reductions crrev.com/c/5496321 added a restriction on the reduction ops (including argMin/argMax) that the rank of the input tensor must be greater than zero. In https://github.com/webmachinelearning/webnn/issues/681, @fdwr points out that 0-D (scalar) reductions are fine, it's just a no-op. Per that discussion, this removes a restriction. There are already WPT cases for argMin/argMax (although they fail for other reasons); cases are added for the plethora of reduction ops (which also fail for other reasons). Change-Id: Ib10a9b0bb3062f9d2b6001d9a4963b14e751d14f Cq-Include-Trybots: luci.chromium.try:mac14-blink-rel,mac14.arm64-blink-rel,win11-blink-rel --- webnn/resources/test_data/reduce_l1.json | 18 ++++++++++++++++++ webnn/resources/test_data/reduce_l2.json | 18 ++++++++++++++++++ webnn/resources/test_data/reduce_log_sum.json | 18 ++++++++++++++++++ .../test_data/reduce_log_sum_exp.json | 18 ++++++++++++++++++ webnn/resources/test_data/reduce_max.json | 18 ++++++++++++++++++ webnn/resources/test_data/reduce_mean.json | 18 ++++++++++++++++++ webnn/resources/test_data/reduce_min.json | 18 ++++++++++++++++++ webnn/resources/test_data/reduce_product.json | 18 ++++++++++++++++++ webnn/resources/test_data/reduce_sum.json | 18 ++++++++++++++++++ .../resources/test_data/reduce_sum_square.json | 18 ++++++++++++++++++ 10 files changed, 180 insertions(+) diff --git a/webnn/resources/test_data/reduce_l1.json b/webnn/resources/test_data/reduce_l1.json index c3f2b618e9b0eb9..ffea2baf617ea7f 100644 --- a/webnn/resources/test_data/reduce_l1.json +++ b/webnn/resources/test_data/reduce_l1.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceL1 float32 0D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 5.508826448139126 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 5.508826448139126, + "type": "float32" + } + }, { "name": "reduceL1 float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/webnn/resources/test_data/reduce_l2.json b/webnn/resources/test_data/reduce_l2.json index d83eea9dfb93e87..33a2d70cf2644fe 100644 --- a/webnn/resources/test_data/reduce_l2.json +++ b/webnn/resources/test_data/reduce_l2.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceL2 float32 0D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 4.860227954324237 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 4.860227954324237, + "type": "float32" + } + }, { "name": "reduceL2 float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/webnn/resources/test_data/reduce_log_sum.json b/webnn/resources/test_data/reduce_log_sum.json index 061e12ad5165239..1abb6932f4535e9 100644 --- a/webnn/resources/test_data/reduce_log_sum.json +++ b/webnn/resources/test_data/reduce_log_sum.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceLogSum float32 0D constant tensor all non-negative default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 64.54826901463852 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 64.54826901463852, + "type": "float32" + } + }, { "name": "reduceLogSum float32 1D constant tensor all non-negative default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/webnn/resources/test_data/reduce_log_sum_exp.json b/webnn/resources/test_data/reduce_log_sum_exp.json index 3577d6aa9ee521a..aa820b1e11fd510 100644 --- a/webnn/resources/test_data/reduce_log_sum_exp.json +++ b/webnn/resources/test_data/reduce_log_sum_exp.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceLogSumExp float32 0D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} + "inputs": { + "input": { + "shape": [], + "data": [ + 0.7974132976078829 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 0.7974132976078829, + "type": "float32" + } + }, { "name": "reduceLogSumExp float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": { diff --git a/webnn/resources/test_data/reduce_max.json b/webnn/resources/test_data/reduce_max.json index 11ed0ed91914740..715c4d034d89449 100644 --- a/webnn/resources/test_data/reduce_max.json +++ b/webnn/resources/test_data/reduce_max.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceMax float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 32.166585683408215 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 32.166585683408215, + "type": "float32" + } + }, { "name": "reduceMax float32 1D constant tensor default options", "inputs": { diff --git a/webnn/resources/test_data/reduce_mean.json b/webnn/resources/test_data/reduce_mean.json index 8c26d0a5623e5cd..b04738b647d5f40 100644 --- a/webnn/resources/test_data/reduce_mean.json +++ b/webnn/resources/test_data/reduce_mean.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceMean float32 0D constant tensor all positive default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 95.84498772347054 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 95.84498772347054, + "type": "float32" + } + }, { "name": "reduceMean float32 1D constant tensor all positive default options", "inputs": { diff --git a/webnn/resources/test_data/reduce_min.json b/webnn/resources/test_data/reduce_min.json index 6c26df5db16d92a..1d07978599f6f13 100644 --- a/webnn/resources/test_data/reduce_min.json +++ b/webnn/resources/test_data/reduce_min.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceMin float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + -58.76195671214997 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": -58.76195671214997, + "type": "float32" + } + }, { "name": "reduceMin float32 1D constant tensor default options", "inputs": { diff --git a/webnn/resources/test_data/reduce_product.json b/webnn/resources/test_data/reduce_product.json index d58af30ec1af619..97007d191daaab3 100644 --- a/webnn/resources/test_data/reduce_product.json +++ b/webnn/resources/test_data/reduce_product.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceProduct float32 0D constant tensor default options", + "inputs": { + "input": { + "shape": [], + "data": [ + -68.75911760233478 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": -68.75911760233478, + "type": "float32" + } + }, { "name": "reduceProduct float32 1D constant tensor default options", "inputs": { diff --git a/webnn/resources/test_data/reduce_sum.json b/webnn/resources/test_data/reduce_sum.json index 7027d38b6769937..88db9973c598a94 100644 --- a/webnn/resources/test_data/reduce_sum.json +++ b/webnn/resources/test_data/reduce_sum.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceSum float32 0D constant tensor all positive default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 69.6038605453285 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 69.6038605453285, + "type": "float32" + } + }, { "name": "reduceSum float32 1D constant tensor all positive default options", "inputs": { diff --git a/webnn/resources/test_data/reduce_sum_square.json b/webnn/resources/test_data/reduce_sum_square.json index bd2ebb341a7c04b..6661c47133f4587 100644 --- a/webnn/resources/test_data/reduce_sum_square.json +++ b/webnn/resources/test_data/reduce_sum_square.json @@ -1,5 +1,23 @@ { "tests": [ + { + "name": "reduceSumSquare float32 0D constant tensor all positive default options", + "inputs": { + "input": { + "shape": [], + "data": [ + 52.5615351837915 + ], + "type": "float32", + "constant": true + } + }, + "expected": { + "name": "output", + "data": 52.5615351837915, + "type": "float32" + } + }, { "name": "reduceSumSquare float32 1D constant tensor all positive default options", // default options: {axes: null, keepDimensions: false} "inputs": {