[webnn] Add float32 tests for WebNN sigmoid op. (#37343)
diff --git a/webnn/resources/test_data/sigmoid.json b/webnn/resources/test_data/sigmoid.json
new file mode 100644
index 0000000..c233336
--- /dev/null
+++ b/webnn/resources/test_data/sigmoid.json
@@ -0,0 +1,334 @@
+{
+ "tests": [
+ {
+ "name": "sigmoid float32 1D tensor",
+ "inputs": {
+ "x": {
+ "shape": [24],
+ "data": [
+ -0.3769951326450487,
+ -0.6848450678710742,
+ -5.98887201399973,
+ 4.431885748123033,
+ -0.9386848809986663,
+ 4.591195578857441,
+ -2.5067027776293456,
+ 1.5669522849917055,
+ -2.596473257404651,
+ -3.647293770068697,
+ 2.6785236795981433,
+ -3.105160168372808,
+ 2.258501824714781,
+ -0.2865157795154527,
+ 4.640436413897461,
+ 1.0606156163391969,
+ -3.536252613252593,
+ 0.44104409560934066,
+ 4.79146007344656,
+ 2.0745488579530846,
+ 0.8354471082395971,
+ -5.433595857448718,
+ -4.184835816765236,
+ -2.484982429169702
+ ],
+ "type": "float32"
+ }
+ },
+ "expected": {
+ "name": "output",
+ "shape": [24],
+ "data": [
+ 0.4068518280982971,
+ 0.33518078923225403,
+ 0.0025002227630466223,
+ 0.9882476925849915,
+ 0.28116607666015625,
+ 0.9899610877037048,
+ 0.07538963109254837,
+ 0.8273487091064453,
+ 0.0693657398223877,
+ 0.02539960853755474,
+ 0.9357474446296692,
+ 0.04289489984512329,
+ 0.9053813815116882,
+ 0.42885708808898926,
+ 0.9904388189315796,
+ 0.7428081631660461,
+ 0.0282981526106596,
+ 0.6085078120231628,
+ 0.9917680025100708,
+ 0.8884047269821167,
+ 0.6975054740905762,
+ 0.004348373040556908,
+ 0.014996387995779514,
+ 0.07691769301891327
+ ],
+ "type": "float32"
+ }
+ },
+ {
+ "name": "sigmoid float32 2D tensor",
+ "inputs": {
+ "x": {
+ "shape": [4, 6],
+ "data": [
+ -0.3769951326450487,
+ -0.6848450678710742,
+ -5.98887201399973,
+ 4.431885748123033,
+ -0.9386848809986663,
+ 4.591195578857441,
+ -2.5067027776293456,
+ 1.5669522849917055,
+ -2.596473257404651,
+ -3.647293770068697,
+ 2.6785236795981433,
+ -3.105160168372808,
+ 2.258501824714781,
+ -0.2865157795154527,
+ 4.640436413897461,
+ 1.0606156163391969,
+ -3.536252613252593,
+ 0.44104409560934066,
+ 4.79146007344656,
+ 2.0745488579530846,
+ 0.8354471082395971,
+ -5.433595857448718,
+ -4.184835816765236,
+ -2.484982429169702
+ ],
+ "type": "float32"
+ }
+ },
+ "expected": {
+ "name": "output",
+ "shape": [4, 6],
+ "data": [
+ 0.4068518280982971,
+ 0.33518078923225403,
+ 0.0025002227630466223,
+ 0.9882476925849915,
+ 0.28116607666015625,
+ 0.9899610877037048,
+ 0.07538963109254837,
+ 0.8273487091064453,
+ 0.0693657398223877,
+ 0.02539960853755474,
+ 0.9357474446296692,
+ 0.04289489984512329,
+ 0.9053813815116882,
+ 0.42885708808898926,
+ 0.9904388189315796,
+ 0.7428081631660461,
+ 0.0282981526106596,
+ 0.6085078120231628,
+ 0.9917680025100708,
+ 0.8884047269821167,
+ 0.6975054740905762,
+ 0.004348373040556908,
+ 0.014996387995779514,
+ 0.07691769301891327
+ ],
+ "type": "float32"
+ }
+ },
+ {
+ "name": "sigmoid float32 3D tensor",
+ "inputs": {
+ "x": {
+ "shape": [2, 3, 4],
+ "data": [
+ -0.3769951326450487,
+ -0.6848450678710742,
+ -5.98887201399973,
+ 4.431885748123033,
+ -0.9386848809986663,
+ 4.591195578857441,
+ -2.5067027776293456,
+ 1.5669522849917055,
+ -2.596473257404651,
+ -3.647293770068697,
+ 2.6785236795981433,
+ -3.105160168372808,
+ 2.258501824714781,
+ -0.2865157795154527,
+ 4.640436413897461,
+ 1.0606156163391969,
+ -3.536252613252593,
+ 0.44104409560934066,
+ 4.79146007344656,
+ 2.0745488579530846,
+ 0.8354471082395971,
+ -5.433595857448718,
+ -4.184835816765236,
+ -2.484982429169702
+ ],
+ "type": "float32"
+ }
+ },
+ "expected": {
+ "name": "output",
+ "shape": [2, 3, 4],
+ "data": [
+ 0.4068518280982971,
+ 0.33518078923225403,
+ 0.0025002227630466223,
+ 0.9882476925849915,
+ 0.28116607666015625,
+ 0.9899610877037048,
+ 0.07538963109254837,
+ 0.8273487091064453,
+ 0.0693657398223877,
+ 0.02539960853755474,
+ 0.9357474446296692,
+ 0.04289489984512329,
+ 0.9053813815116882,
+ 0.42885708808898926,
+ 0.9904388189315796,
+ 0.7428081631660461,
+ 0.0282981526106596,
+ 0.6085078120231628,
+ 0.9917680025100708,
+ 0.8884047269821167,
+ 0.6975054740905762,
+ 0.004348373040556908,
+ 0.014996387995779514,
+ 0.07691769301891327
+ ],
+ "type": "float32"
+ }
+ },
+ {
+ "name": "sigmoid float32 4D tensor",
+ "inputs": {
+ "x": {
+ "shape": [2, 2, 2, 3],
+ "data": [
+ -0.3769951326450487,
+ -0.6848450678710742,
+ -5.98887201399973,
+ 4.431885748123033,
+ -0.9386848809986663,
+ 4.591195578857441,
+ -2.5067027776293456,
+ 1.5669522849917055,
+ -2.596473257404651,
+ -3.647293770068697,
+ 2.6785236795981433,
+ -3.105160168372808,
+ 2.258501824714781,
+ -0.2865157795154527,
+ 4.640436413897461,
+ 1.0606156163391969,
+ -3.536252613252593,
+ 0.44104409560934066,
+ 4.79146007344656,
+ 2.0745488579530846,
+ 0.8354471082395971,
+ -5.433595857448718,
+ -4.184835816765236,
+ -2.484982429169702
+ ],
+ "type": "float32"
+ }
+ },
+ "expected": {
+ "name": "output",
+ "shape": [2, 2, 2, 3],
+ "data": [
+ 0.4068518280982971,
+ 0.33518078923225403,
+ 0.0025002227630466223,
+ 0.9882476925849915,
+ 0.28116607666015625,
+ 0.9899610877037048,
+ 0.07538963109254837,
+ 0.8273487091064453,
+ 0.0693657398223877,
+ 0.02539960853755474,
+ 0.9357474446296692,
+ 0.04289489984512329,
+ 0.9053813815116882,
+ 0.42885708808898926,
+ 0.9904388189315796,
+ 0.7428081631660461,
+ 0.0282981526106596,
+ 0.6085078120231628,
+ 0.9917680025100708,
+ 0.8884047269821167,
+ 0.6975054740905762,
+ 0.004348373040556908,
+ 0.014996387995779514,
+ 0.07691769301891327
+ ],
+ "type": "float32"
+ }
+ },
+ {
+ "name": "sigmoid float32 5D tensor",
+ "inputs": {
+ "x": {
+ "shape": [2, 1, 4, 1, 3],
+ "data": [
+ -0.3769951326450487,
+ -0.6848450678710742,
+ -5.98887201399973,
+ 4.431885748123033,
+ -0.9386848809986663,
+ 4.591195578857441,
+ -2.5067027776293456,
+ 1.5669522849917055,
+ -2.596473257404651,
+ -3.647293770068697,
+ 2.6785236795981433,
+ -3.105160168372808,
+ 2.258501824714781,
+ -0.2865157795154527,
+ 4.640436413897461,
+ 1.0606156163391969,
+ -3.536252613252593,
+ 0.44104409560934066,
+ 4.79146007344656,
+ 2.0745488579530846,
+ 0.8354471082395971,
+ -5.433595857448718,
+ -4.184835816765236,
+ -2.484982429169702
+ ],
+ "type": "float32"
+ }
+ },
+ "expected": {
+ "name": "output",
+ "shape": [2, 1, 4, 1, 3],
+ "data": [
+ 0.4068518280982971,
+ 0.33518078923225403,
+ 0.0025002227630466223,
+ 0.9882476925849915,
+ 0.28116607666015625,
+ 0.9899610877037048,
+ 0.07538963109254837,
+ 0.8273487091064453,
+ 0.0693657398223877,
+ 0.02539960853755474,
+ 0.9357474446296692,
+ 0.04289489984512329,
+ 0.9053813815116882,
+ 0.42885708808898926,
+ 0.9904388189315796,
+ 0.7428081631660461,
+ 0.0282981526106596,
+ 0.6085078120231628,
+ 0.9917680025100708,
+ 0.8884047269821167,
+ 0.6975054740905762,
+ 0.004348373040556908,
+ 0.014996387995779514,
+ 0.07691769301891327
+ ],
+ "type": "float32"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/webnn/resources/utils.js b/webnn/resources/utils.js
index 90a56b0..86335f7 100644
--- a/webnn/resources/utils.js
+++ b/webnn/resources/utils.js
@@ -79,6 +79,7 @@
leakyRelu: {ULP: {float32: 1, float16: 1}},
relu: {ULP: {float32: 0, float16: 0}},
reshape: {ULP: {float32: 0, float16: 0}},
+ sigmoid: {ULP: {float32: 32+2, float16: 3}}, // float32 (leaving a few ULP for roundoff)
slice: {ULP: {float32: 0, float16: 0}},
softmax: {ULP: {float32: getSoftmaxPrecisionTolerance, float16: getSoftmaxPrecisionTolerance}},
transpose: {ULP: {float32: 0, float16: 0}},
diff --git a/webnn/sigmoid.https.any.js b/webnn/sigmoid.https.any.js
new file mode 100644
index 0000000..cb22b6e
--- /dev/null
+++ b/webnn/sigmoid.https.any.js
@@ -0,0 +1,10 @@
+// META: title=test WebNN API sigmoid operation
+// META: global=window,dedicatedworker
+// META: script=./resources/utils.js
+// META: timeout=long
+
+'use strict';
+
+// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-sigmoid
+
+testWebNNOperation('sigmoid', '/webnn/resources/test_data/sigmoid.json', buildOperationWithSingleInput);
\ No newline at end of file