Skip to content

Conversation

@BruceDai
Copy link
Contributor

@BruceDai BruceDai commented Nov 2, 2022

@huningxin @fdwr I added these scripts to generate float64 inputs test data and float32 expected data for WebNN concat tests of WPT, PTAL, thanks.

@BruceDai
Copy link
Contributor Author

BruceDai commented Nov 3, 2022

Link web-platform-tests/wpt#36782 .

@BruceDai BruceDai force-pushed the gen_concat_test_data branch from e91e690 to 1230193 Compare November 3, 2022 12:59
let pos = 0;
for (const shape of inputShapes) {
const size = sizeOfShape(shape);
const precisionData =
Copy link
Contributor Author

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": [
Copy link
Contributor Author

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": {
Copy link
Contributor Author

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.

@BruceDai BruceDai changed the title [tool] Add scripts to generate test data for WebNN concat tests of WPT. [tool] Add scripts to generate test data for WPT WebNN operations tests Nov 4, 2022
@BruceDai BruceDai force-pushed the gen_concat_test_data branch from a8141f1 to d1c1c62 Compare November 8, 2022 02:07
@@ -0,0 +1,344 @@
{
"inputsData": {
"float64Data": [
Copy link

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.

Copy link
Contributor Author

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool.

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.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then typo

Copy link
Contributor Author

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]);
Copy link

@fdwr fdwr Nov 10, 2022

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 @@
{
Copy link

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)

toSaveDataDict['expectedData'][expectedDataCategory] =
utils.getPrecisionData(result, precisionType);
} else {
continue;
Copy link

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);
...

const tests = jsonDict.tests;

for (const test of tests) {
const expectedDataCategory = test.expected.data;
Copy link

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?

Copy link
Contributor Author

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 ||
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int16Array?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@BruceDai BruceDai left a 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 ||
Copy link
Contributor Author

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.

const tests = jsonDict.tests;

for (const test of tests) {
const expectedDataCategory = test.expected.data;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated by expectedDataSource, thanks.

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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, thanks.

@BruceDai BruceDai changed the title [tool] Add scripts to generate test data for WPT WebNN operations tests [WIP][tool] Add scripts to generate test data for WPT WebNN operations tests Mar 13, 2023
@BruceDai
Copy link
Contributor Author

Thanks all for reviewing and sharing guidelines. 👍 👍
Let me close this earlier several PRs, and new PR of generating baseline scripts including fp16 baseline data will submit later.

@BruceDai BruceDai closed this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants