-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[webnn] Add float32 tests for WebNN hardSwish op #38712
Merged
Honry
merged 2 commits into
web-platform-tests:master
from
BruceDai:add_webnn_hardSwish_tests
Mar 1, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// META: title=test WebNN API tanh operation | ||
// META: global=window,dedicatedworker | ||
// META: script=./resources/utils.js | ||
// META: timeout=long | ||
|
||
'use strict'; | ||
|
||
// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-hard-swish | ||
|
||
testWebNNOperation('hardSwish', buildOperationWithSingleInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,334 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"name": "hardSwish float32 1D tensor", | ||
"inputs": { | ||
"x": { | ||
"shape": [24], | ||
"data": [ | ||
0.7341583533045579, | ||
9.118859151005996, | ||
3.545238531520827, | ||
2.621943879280181, | ||
-6.445507690595167, | ||
-1.6835596550754381, | ||
5.523179785756591, | ||
-5.958856051028132, | ||
-9.169189933081544, | ||
6.420943542920213, | ||
-3.293031330275471, | ||
1.0410166785810624, | ||
-7.246322671816956, | ||
-0.9472730969847909, | ||
-5.778352255817807, | ||
3.185229125228698, | ||
-7.261818072290236, | ||
4.174602615173795, | ||
3.7802628241590686, | ||
-6.07124038718255, | ||
-9.909919471919547, | ||
-7.744259390113584, | ||
-8.286120816748381, | ||
8.083491160956697 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
"expected": { | ||
"name": "output", | ||
"shape": [24], | ||
"data": [ | ||
0.4569105803966522, | ||
9.11885929107666, | ||
3.545238494873047, | ||
2.4567370414733887, | ||
0, | ||
-0.3693843185901642, | ||
5.52318000793457, | ||
0, | ||
0, | ||
6.420943737030029, | ||
0, | ||
0.7011276483535767, | ||
0, | ||
-0.3240821659564972, | ||
0, | ||
3.1852290630340576, | ||
0, | ||
4.174602508544922, | ||
3.7802627086639404, | ||
0, | ||
0, | ||
0, | ||
0, | ||
8.083491325378418 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
{ | ||
"name": "hardSwish float32 2D tensor", | ||
"inputs": { | ||
"x": { | ||
"shape": [4, 6], | ||
"data": [ | ||
0.7341583533045579, | ||
9.118859151005996, | ||
3.545238531520827, | ||
2.621943879280181, | ||
-6.445507690595167, | ||
-1.6835596550754381, | ||
5.523179785756591, | ||
-5.958856051028132, | ||
-9.169189933081544, | ||
6.420943542920213, | ||
-3.293031330275471, | ||
1.0410166785810624, | ||
-7.246322671816956, | ||
-0.9472730969847909, | ||
-5.778352255817807, | ||
3.185229125228698, | ||
-7.261818072290236, | ||
4.174602615173795, | ||
3.7802628241590686, | ||
-6.07124038718255, | ||
-9.909919471919547, | ||
-7.744259390113584, | ||
-8.286120816748381, | ||
8.083491160956697 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
"expected": { | ||
"name": "output", | ||
"shape": [4, 6], | ||
"data": [ | ||
0.4569105803966522, | ||
9.11885929107666, | ||
3.545238494873047, | ||
2.4567370414733887, | ||
0, | ||
-0.3693843185901642, | ||
5.52318000793457, | ||
0, | ||
0, | ||
6.420943737030029, | ||
0, | ||
0.7011276483535767, | ||
0, | ||
-0.3240821659564972, | ||
0, | ||
3.1852290630340576, | ||
0, | ||
4.174602508544922, | ||
3.7802627086639404, | ||
0, | ||
0, | ||
0, | ||
0, | ||
8.083491325378418 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
{ | ||
"name": "hardSwish float32 3D tensor", | ||
"inputs": { | ||
"x": { | ||
"shape": [2, 3, 4], | ||
"data": [ | ||
0.7341583533045579, | ||
9.118859151005996, | ||
3.545238531520827, | ||
2.621943879280181, | ||
-6.445507690595167, | ||
-1.6835596550754381, | ||
5.523179785756591, | ||
-5.958856051028132, | ||
-9.169189933081544, | ||
6.420943542920213, | ||
-3.293031330275471, | ||
1.0410166785810624, | ||
-7.246322671816956, | ||
-0.9472730969847909, | ||
-5.778352255817807, | ||
3.185229125228698, | ||
-7.261818072290236, | ||
4.174602615173795, | ||
3.7802628241590686, | ||
-6.07124038718255, | ||
-9.909919471919547, | ||
-7.744259390113584, | ||
-8.286120816748381, | ||
8.083491160956697 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
"expected": { | ||
"name": "output", | ||
"shape": [2, 3, 4], | ||
"data": [ | ||
0.4569105803966522, | ||
9.11885929107666, | ||
3.545238494873047, | ||
2.4567370414733887, | ||
0, | ||
-0.3693843185901642, | ||
5.52318000793457, | ||
0, | ||
0, | ||
6.420943737030029, | ||
0, | ||
0.7011276483535767, | ||
0, | ||
-0.3240821659564972, | ||
0, | ||
3.1852290630340576, | ||
0, | ||
4.174602508544922, | ||
3.7802627086639404, | ||
0, | ||
0, | ||
0, | ||
0, | ||
8.083491325378418 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
{ | ||
"name": "hardSwish float32 4D tensor", | ||
"inputs": { | ||
"x": { | ||
"shape": [2, 2, 2, 3], | ||
"data": [ | ||
0.7341583533045579, | ||
9.118859151005996, | ||
3.545238531520827, | ||
2.621943879280181, | ||
-6.445507690595167, | ||
-1.6835596550754381, | ||
5.523179785756591, | ||
-5.958856051028132, | ||
-9.169189933081544, | ||
6.420943542920213, | ||
-3.293031330275471, | ||
1.0410166785810624, | ||
-7.246322671816956, | ||
-0.9472730969847909, | ||
-5.778352255817807, | ||
3.185229125228698, | ||
-7.261818072290236, | ||
4.174602615173795, | ||
3.7802628241590686, | ||
-6.07124038718255, | ||
-9.909919471919547, | ||
-7.744259390113584, | ||
-8.286120816748381, | ||
8.083491160956697 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
"expected": { | ||
"name": "output", | ||
"shape": [2, 2, 2, 3], | ||
"data": [ | ||
0.4569105803966522, | ||
9.11885929107666, | ||
3.545238494873047, | ||
2.4567370414733887, | ||
0, | ||
-0.3693843185901642, | ||
5.52318000793457, | ||
0, | ||
0, | ||
6.420943737030029, | ||
0, | ||
0.7011276483535767, | ||
0, | ||
-0.3240821659564972, | ||
0, | ||
3.1852290630340576, | ||
0, | ||
4.174602508544922, | ||
3.7802627086639404, | ||
0, | ||
0, | ||
0, | ||
0, | ||
8.083491325378418 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
{ | ||
"name": "hardSwish float32 5D tensor", | ||
"inputs": { | ||
"x": { | ||
"shape": [2, 1, 4, 1, 3], | ||
"data": [ | ||
0.7341583533045579, | ||
9.118859151005996, | ||
3.545238531520827, | ||
2.621943879280181, | ||
-6.445507690595167, | ||
-1.6835596550754381, | ||
5.523179785756591, | ||
-5.958856051028132, | ||
-9.169189933081544, | ||
6.420943542920213, | ||
-3.293031330275471, | ||
1.0410166785810624, | ||
-7.246322671816956, | ||
-0.9472730969847909, | ||
-5.778352255817807, | ||
3.185229125228698, | ||
-7.261818072290236, | ||
4.174602615173795, | ||
3.7802628241590686, | ||
-6.07124038718255, | ||
-9.909919471919547, | ||
-7.744259390113584, | ||
-8.286120816748381, | ||
8.083491160956697 | ||
], | ||
"type": "float32" | ||
} | ||
}, | ||
"expected": { | ||
"name": "output", | ||
"shape": [2, 1, 4, 1, 3], | ||
"data": [ | ||
0.4569105803966522, | ||
9.11885929107666, | ||
3.545238494873047, | ||
2.4567370414733887, | ||
0, | ||
-0.3693843185901642, | ||
5.52318000793457, | ||
0, | ||
0, | ||
6.420943737030029, | ||
0, | ||
0.7011276483535767, | ||
0, | ||
-0.3240821659564972, | ||
0, | ||
3.1852290630340576, | ||
0, | ||
4.174602508544922, | ||
3.7802627086639404, | ||
0, | ||
0, | ||
0, | ||
0, | ||
8.083491325378418 | ||
], | ||
"type": "float32" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fail to run these hardSwish tests by Chromium integrated WebNN API with XNNPack API back, since XNNPack API can distinguish 0.0 and -0.0.
@fdwr @huningxin Any suggestion? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed and unsigned zero can be treated as equivalent (IEEE does https://en.wikipedia.org/wiki/Signed_zero#Comparisons). I recommend that before checking for ULP differences in
assert_array_approx_equals_ulp
, first check ifexpected == actual
, and only if!=
, would you need to check ULP too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdwr Thanks for your suggestion! Yes, if actual was as same as expect one, no need to measure the ULP distance which would save testing time. Please take another look, thanks.