-
Notifications
You must be signed in to change notification settings - Fork 8
[WIP][tool] Add scripts to generate test data for WPT WebNN operations tests #22
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
Conversation
7ede4c3 to
e91e690
Compare
|
Link web-platform-tests/wpt#36782 . |
e91e690 to
1230193
Compare
test/tool/gen-concat.js
Outdated
| let pos = 0; | ||
| for (const shape of inputShapes) { | ||
| const size = sizeOfShape(shape); | ||
| const precisionData = |
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.
This Line65 is to convert origin float64 data to float32 before invoking the implementation of concat operation, and below Line71 is to convert computed result to be float32 data based on our last synced solution. @huningxin PTAL, thank.
| @@ -0,0 +1,303 @@ | |||
| { | |||
| "tests": [ | |||
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.
This tests part is reused the tests part of test_data file for WPT WebNN concat tests.
| @@ -0,0 +1,370 @@ | |||
| { | |||
| "inputsData": { | |||
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.
These generated test data of inputsData and expectedData are used as the data of test_data file for WPT WebNN concat tests.
a8141f1 to
d1c1c62
Compare
| @@ -0,0 +1,344 @@ | |||
| { | |||
| "inputsData": { | |||
| "float64Data": [ | |||
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.
So this float64 data was cast to float32 first (and then back to float64) before passing to the baseline reference engine? Likewise, the data is also cast to float32 in the same way when passed to the web API implementation?
We just want to be sure that both inputs see the same initial tensor. If the tests are passing, then I guess they must be cast consistently.
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.
So this float64 data was cast to float32 first (and then back to float64) before passing to the baseline reference engine? Likewise, the data is also cast to float32 in the same way when passed to the web API implementation?
Yes. The float64 data was cast to float32 by same invoking new Float32Array(float64Data) before passing to baseline reference engine and web API implementation.
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.
Cool.
test/tool/README.md
Outdated
| node gen-concat.js resources\concat.json | ||
| ``` | ||
|
|
||
| , then you could see similar below output on the console, and find new / updated test data file under `test_data` folder. |
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.
Then typo
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.
Updated, thanks.
| const min = -10.0; | ||
| const max = 10.0; | ||
| const savedDataFile = path.join(path.dirname(process.argv[1]), 'test_data', 'clamp_data.json'); | ||
| const jsonDict = utils.readJsonFile(process.argv[2]); |
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.
(ignorable, just something I learned today) Huh, so I see that argv[2] in Node.js is the equivalent of argv[1] in C and Python, because argv[0] is actually node.exe itself rather than the main program/script file. Weird.
| @@ -0,0 +1,344 @@ | |||
| { | |||
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.
[minor] I see other files follow hyphen case (gen-concat.js). Should these too? (clamp-data.json)
test/tool/gen-gemm.js
Outdated
| toSaveDataDict['expectedData'][expectedDataCategory] = | ||
| utils.getPrecisionData(result, precisionType); | ||
| } else { | ||
| continue; |
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.
Is the continue not redundant given the next line will reach the bottom of the for loop? If you want to keep it, consider inverting the if test, moving the continue to the top and unindenting the normal code flow (fewer branch points make it a little easier to follow):
if (toSaveDataDict['expectedData'][expectedDataCategory] !== undefined)
{
// The expected data is already defined.
continue;
}
const precisionType = test.type;
const precisionDataA = utils.getPrecisionDataFromDataDict(toSaveDataDict['inputsData'], test.inputs.a.data, precisionType);
...
test/tool/gen-concat.js
Outdated
| const tests = jsonDict.tests; | ||
|
|
||
| for (const test of tests) { | ||
| const expectedDataCategory = test.expected.data; |
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.
Selecting which named entry is the source of your data feels more like a source than a category. How about expectedDataSource?
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.
Updated by expectedDataSource, thanks.
| // If found, it replaces it by a trio | ||
| if ( value instanceof Int8Array || | ||
| value instanceof Uint8Array || | ||
| value instanceof Uint16Array || |
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.
Int16Array?
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.
I referred to WebNN MLOperandType where didn't define "int16" type, so here I didn't add Int16Array condition, and the condition of Uint16Array is for float16 data handler.
BruceDai
left a comment
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 reviewing, I've updated PR to address your comments, please take another look, thanks.
| // If found, it replaces it by a trio | ||
| if ( value instanceof Int8Array || | ||
| value instanceof Uint8Array || | ||
| value instanceof Uint16Array || |
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.
I referred to WebNN MLOperandType where didn't define "int16" type, so here I didn't add Int16Array condition, and the condition of Uint16Array is for float16 data handler.
test/tool/gen-concat.js
Outdated
| const tests = jsonDict.tests; | ||
|
|
||
| for (const test of tests) { | ||
| const expectedDataCategory = test.expected.data; |
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.
Updated by expectedDataSource, thanks.
test/tool/README.md
Outdated
| node gen-concat.js resources\concat.json | ||
| ``` | ||
|
|
||
| , then you could see similar below output on the console, and find new / updated test data file under `test_data` folder. |
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.
Updated, thanks.
|
Thanks all for reviewing and sharing guidelines. 👍 👍 |
@huningxin @fdwr I added these scripts to generate
float64inputs test data andfloat32expected data for WebNN concat tests of WPT, PTAL, thanks.