From 78b0d0e3074df64a193ab7062b1dec4355be512a Mon Sep 17 00:00:00 2001 From: Phillis Tang Date: Tue, 10 Dec 2024 17:03:26 +0000 Subject: [PATCH] Bug 1935775 [wpt PR 49575] - webnn: implement lstm in coreml, a=testonly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic update from web-platform-tests webnn: implement lstm in coreml lstm requires weights and bias to be constants and they have different shapes compared to webnn spec. So the weight serialization needs to be changed to be done lazily. For all weights and biases, if it's bidirectional, they are splitted to two weights(with extra transposes and reshapes). Additionally bias and recurrent_bias are combined to a single bias param. Change-Id: I5881ff4a0618e5a9584d39099faa6ac30f4570e7 Bug: 360052663 Cq-Include-Trybots: luci.chromium.try​:mac14.arm64-blink-rel,mac15-blink-rel,mac15.arm64-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6071582 Reviewed-by: Austin Sullivan Commit-Queue: Phillis Tang Cr-Commit-Position: refs/heads/main@{#1393164} -- wpt-commits: 37fd4ed8aafa77d781b2ea38a35c17b2b84183f6 wpt-pr: 49575 --- .../webnn/conformance_tests/lstm.https.any.js | 159 ++++++++++++------ 1 file changed, 106 insertions(+), 53 deletions(-) diff --git a/testing/web-platform/tests/webnn/conformance_tests/lstm.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/lstm.https.any.js index 13bf49261c125..e52add43f94d5 100644 --- a/testing/web-platform/tests/webnn/conformance_tests/lstm.https.any.js +++ b/testing/web-platform/tests/webnn/conformance_tests/lstm.https.any.js @@ -70,22 +70,26 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -126,26 +130,31 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmPeepholeWeight': { 'data': [0, 0, 0, 0, 0, 0], - 'descriptor': {shape: [1, 6], dataType: 'float32'} + 'descriptor': {shape: [1, 6], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -183,26 +192,31 @@ const lstmTests = [ 'inputs': { 'lstmInput': { 'data': [1, 2, 2, 1], - 'descriptor': {shape: [1, 2, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 2, 2], dataType: 'float32'}, + 'constant': true }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmInitialHiddenState': { 'data': [0, 0, 0, 0], @@ -248,26 +262,31 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmInitialCellState': { 'data': [0, 0, 0, 0], - 'descriptor': {shape: [1, 2, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 2, 2], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -309,22 +328,26 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -366,22 +389,26 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -427,22 +454,26 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -484,22 +515,26 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -541,22 +576,26 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -597,26 +636,31 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmPeepholeWeight': { 'data': [0, 0, 0, 0, 0, 0], - 'descriptor': {shape: [1, 6], dataType: 'float32'} + 'descriptor': {shape: [1, 6], dataType: 'float32'}, + 'constant': true }, 'lstmInitialHiddenState': { 'data': [0, 0, 0, 0], @@ -675,22 +719,26 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true } }, 'operators': [{ @@ -737,26 +785,31 @@ const lstmTests = [ }, 'lstmWeight': { 'data': [1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2, 1, -1, 2, -2], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentWeight': { 'data': [ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ], - 'descriptor': {shape: [1, 8, 2], dataType: 'float32'} + 'descriptor': {shape: [1, 8, 2], dataType: 'float32'}, + 'constant': true }, 'lstmBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmRecurrentBias': { 'data': [1, 2, 1, 2, 1, 2, 1, 2], - 'descriptor': {shape: [1, 8], dataType: 'float32'} + 'descriptor': {shape: [1, 8], dataType: 'float32'}, + 'constant': true }, 'lstmPeepholeWeight': { 'data': [0, 0, 0, 0, 0, 0], - 'descriptor': {shape: [1, 6], dataType: 'float32'} + 'descriptor': {shape: [1, 6], dataType: 'float32'}, + 'constant': true }, 'lstmInitialHiddenState': { 'data': [0, 0, 0, 0],