From 4b0bbd70be4bae0713c63d416af74427df5f1d85 Mon Sep 17 00:00:00 2001 From: Jiewei Qian Date: Thu, 20 Jun 2024 08:25:10 -0700 Subject: [PATCH] webnn: replace DataError with TypeError The spec had been updated to throw TypeError for failed input validations: https://github.com/webmachinelearning/webnn/pull/589. This CL replaces the last remaining DataErrors in lstm implementation and triangular wpt. Bug: 40206287 Change-Id: I73952ce5b407f2df1d9d3b22c0086638d092e811 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5632940 Commit-Queue: Austin Sullivan Reviewed-by: Austin Sullivan Auto-Submit: Jiewei Qian Cr-Commit-Position: refs/heads/main@{#1317381} --- webnn/validation_tests/lstm.https.any.js | 32 +++++++++---------- .../validation_tests/triangular.https.any.js | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/webnn/validation_tests/lstm.https.any.js b/webnn/validation_tests/lstm.https.any.js index c7d341a9d5aa29..2a3eaa1c20258b 100644 --- a/webnn/validation_tests/lstm.https.any.js +++ b/webnn/validation_tests/lstm.https.any.js @@ -113,7 +113,7 @@ const tests = [ ] }, { - name: '[lstm] DataError is expected if hiddenSize equals to zero', + name: '[lstm] TypeError is expected if hiddenSize equals to zero', input: kExampleInputDescriptor, weight: kExampleWeightDescriptor, recurrentWeight: kExampleRecurrentWeightDescriptor, @@ -121,7 +121,7 @@ const tests = [ hiddenSize: 0 }, { - name: '[lstm] DataError is expected if hiddenSize is too large', + name: '[lstm] TypeError is expected if hiddenSize is too large', input: kExampleInputDescriptor, weight: kExampleWeightDescriptor, recurrentWeight: kExampleRecurrentWeightDescriptor, @@ -129,7 +129,7 @@ const tests = [ hiddenSize: 4294967295, }, { - name: '[lstm] DataError is expected if steps equals to zero', + name: '[lstm] TypeError is expected if steps equals to zero', input: kExampleInputDescriptor, weight: kExampleWeightDescriptor, recurrentWeight: kExampleRecurrentWeightDescriptor, @@ -138,7 +138,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if the data type is not one of the floating point types', + '[lstm] TypeError is expected if the data type is not one of the floating point types', input: {dataType: 'uint32', dimensions: kValidInputDimensions}, weight: {dataType: 'uint32', dimensions: kValidWeightDimensions}, recurrentWeight: @@ -147,7 +147,7 @@ const tests = [ hiddenSize: hiddenSize }, { - name: '[lstm] DataError is expected if the rank of input is not 3', + name: '[lstm] TypeError is expected if the rank of input is not 3', input: {dataType: 'float32', dimensions: [steps, batchSize]}, weight: kExampleWeightDescriptor, recurrentWeight: kExampleRecurrentWeightDescriptor, @@ -156,7 +156,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if input.dimensions[0] is not equal to steps', + '[lstm] TypeError is expected if input.dimensions[0] is not equal to steps', input: {dataType: 'float32', dimensions: [1000, batchSize, inputSize]}, weight: kExampleWeightDescriptor, recurrentWeight: kExampleRecurrentWeightDescriptor, @@ -164,7 +164,7 @@ const tests = [ hiddenSize: hiddenSize }, { - name: '[lstm] DataError is expected if the shape of weight is incorrect', + name: '[lstm] TypeError is expected if the shape of weight is incorrect', input: kExampleInputDescriptor, weight: { dataType: 'float32', @@ -176,7 +176,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if the rank of recurrentWeight is not 3', + '[lstm] TypeError is expected if the rank of recurrentWeight is not 3', input: kExampleInputDescriptor, weight: kExampleWeightDescriptor, recurrentWeight: @@ -186,7 +186,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if the size of options.activations is not 3', + '[lstm] TypeError is expected if the size of options.activations is not 3', input: kExampleInputDescriptor, weight: kExampleWeightDescriptor, recurrentWeight: kExampleRecurrentWeightDescriptor, @@ -195,7 +195,7 @@ const tests = [ options: {activations: ['sigmoid', 'tanh']} }, { - name: '[lstm] DataError is expected if the rank of options.bias is not 2', + name: '[lstm] TypeError is expected if the rank of options.bias is not 2', input: {dataType: 'float16', dimensions: kValidInputDimensions}, weight: {dataType: 'float16', dimensions: kValidWeightDimensions}, recurrentWeight: @@ -206,7 +206,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if the shape of options.recurrentBias.dimensions is incorrect', + '[lstm] TypeError is expected if the shape of options.recurrentBias.dimensions is incorrect', input: {dataType: 'float16', dimensions: kValidInputDimensions}, weight: {dataType: 'float16', dimensions: kValidWeightDimensions}, recurrentWeight: @@ -219,7 +219,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if the dataType of options.peepholeWeight is incorrect', + '[lstm] TypeError is expected if the dataType of options.peepholeWeight is incorrect', input: {dataType: 'float16', dimensions: kValidInputDimensions}, weight: {dataType: 'float16', dimensions: kValidWeightDimensions}, recurrentWeight: @@ -233,7 +233,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if the dataType of options.initialHiddenState is incorrect', + '[lstm] TypeError is expected if the dataType of options.initialHiddenState is incorrect', input: {dataType: 'float16', dimensions: kValidInputDimensions}, weight: {dataType: 'float16', dimensions: kValidWeightDimensions}, recurrentWeight: @@ -249,7 +249,7 @@ const tests = [ }, { name: - '[lstm] DataError is expected if the shape of options.initialCellState is incorrect', + '[lstm] TypeError is expected if the shape of options.initialCellState is incorrect', input: kExampleInputDescriptor, weight: kExampleWeightDescriptor, recurrentWeight: kExampleRecurrentWeightDescriptor, @@ -333,8 +333,8 @@ tests.forEach( assert_array_equals(outputs[i].shape(), test.outputs[i].dimensions); } } else { - assert_throws_dom( - 'DataError', + assert_throws_js( + TypeError, () => builder.lstm( input, weight, recurrentWeight, test.steps, test.hiddenSize, options)); diff --git a/webnn/validation_tests/triangular.https.any.js b/webnn/validation_tests/triangular.https.any.js index ee8958659c7452..59694a426036ab 100644 --- a/webnn/validation_tests/triangular.https.any.js +++ b/webnn/validation_tests/triangular.https.any.js @@ -12,6 +12,6 @@ promise_test(async t => { assert_throws_js(TypeError, () => builder.triangular(input)); } } -}, "[triangular] DataError is expected if input's rank is less than 2"); +}, "[triangular] TypeError is expected if input's rank is less than 2"); validateInputFromAnotherBuilder('triangular');