Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceDai committed Dec 9, 2024
1 parent 6741480 commit 9a222ab
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 2,180 deletions.
4 changes: 2 additions & 2 deletions test/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Take an example for softsign operator tests:
node gen-operator-with-single-input.js resources\softsign.json
```

then, you can find two generated folders named 'test-data' and
'test-data-wpt'. There're raw test data as being
Then you can find two generated folders named 'test-data' and
'test-data-wpt'. They're raw test data as being
./test-data/softsign-data.json,
and raw WPT test-data file as being ./test-data-wpt/softsign.json.

Expand Down
17 changes: 8 additions & 9 deletions test/tools/gen-operator-with-single-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {utils} from './utils.js';
'softsign': softsign,
};
const inputTensor = new Tensor(input.shape, input.data);
const outputTensor =
operatorMappingDict[operatorName](inputTensor, options);
const outputTensor = operatorMappingDict[operatorName](inputTensor, options);
return outputTensor.data;
}

Expand All @@ -28,21 +27,20 @@ import {utils} from './utils.js';
`${operatorString}-data.json`);
const jsonDict = utils.readJsonFile(process.argv[2]);
const inputsDataInfo = jsonDict.inputsData;
const inputsDataRange = jsonDict.inputsDataRange;
const toSaveDataDict = utils.prepareInputsData(
inputsDataInfo, savedDataFile, inputsDataRange.min, inputsDataRange.max);
inputsDataInfo, savedDataFile, jsonDict.inputsDataRange);
toSaveDataDict['expectedData'] = {};
const tests = jsonDict.tests;
const wptTests = JSON.parse(JSON.stringify(tests));
for (const test of tests) {
console.log(`name ${test.name}`);
console.log(`Test case name: ${test.name}`);
const precisionDataInput = utils.getPrecisionDataFromDataDict(
toSaveDataDict['inputsData'], test.inputs.input.data,
test.inputs.input.type);
test.inputs.input.dataType);
const input = {shape: test.inputs.input.shape, data: precisionDataInput};
const result = computeBySingleInput(operatorString, input, test.options);
toSaveDataDict['expectedData'][test.expected.data] =
utils.getPrecisionData(result, test.expected.type);
utils.getPrecisionData(result, test.expected.dataType);
}

utils.writeJsonFile(toSaveDataDict, savedDataFile);
Expand All @@ -59,7 +57,7 @@ import {utils} from './utils.js';
test.inputs[inputName].data :
utils.getPrecisionDataFromDataDict(
toSaveDataDict['inputsData'], test.inputs[inputName].data,
test.inputs[inputName].type);
test.inputs[inputName].dataType);
}
// update weights (scale, bias, and etc.) data of options
if (test.options) {
Expand All @@ -74,9 +72,10 @@ import {utils} from './utils.js';
test.expected.data = toSaveDataDict['expectedData'][test.expected.data];
wptConformanceTestsDict.tests.push(test);
}

const savedWPTDataFile = path.join(
path.dirname(process.argv[1]), 'test-data-wpt', `${operatorString}.json`);
utils.writeJsonFile(wptConformanceTestsDict, savedWPTDataFile);

console.log(`[ Done ] Generate test data file for WPT tests.`);
console.log(`[ Done ] Generate test data file ${savedWPTDataFile} for WPT tests.`);
})();
116 changes: 62 additions & 54 deletions test/tools/resources/gelu.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,206 +5,214 @@
"inputs": {
"input": {
"shape": [],
"data": "float64DataScalar",
"type": "float32"
"data": "float32DataScalarInput",
"dataType": "float32"
}
},
"expected": {
"name": "output",
"shape": [],
"data": "float32DataScalar",
"type": "float32"
"data": "float32DataScalarOutput",
"dataType": "float32"
}
},
{
"name": "gelu float16 0D scalar",
"inputs": {
"input": {
"shape": [],
"data": "float64DataScalar",
"type": "float16"
"data": "float16DataScalarInput",
"dataType": "float16"
}
},
"expected": {
"name": "output",
"shape": [],
"data": "float16DataScalar",
"type": "float16"
"data": "float16DataScalarOutput",
"dataType": "float16"
}
},
{
"name": "gelu float32 1D tensor",
"inputs": {
"input": {
"shape": [24],
"data": "float64Data",
"type": "float32"
"data": "float32DataInput",
"dataType": "float32"
}
},
"expected": {
"name": "output",
"shape": [24],
"data": "float32Data",
"type": "float32"
"data": "float32DataOutput",
"dataType": "float32"
}
},
{
"name": "gelu float16 1D tensor",
"inputs": {
"input": {
"shape": [24],
"data": "float64Data",
"type": "float16"
"data": "float16DataInput",
"dataType": "float16"
}
},
"expected": {
"name": "output",
"shape": [24],
"data": "float16Data",
"type": "float16"
"data": "float16DataOutput",
"dataType": "float16"
}
},
{
"name": "gelu float32 2D tensor",
"inputs": {
"input": {
"shape": [4, 6],
"data": "float64Data",
"type": "float32"
"data": "float32DataInput",
"dataType": "float32"
}
},
"expected": {
"name": "output",
"shape": [4, 6],
"data": "float32Data",
"type": "float32"
"data": "float32DataOutput",
"dataType": "float32"
}
},
{
"name": "gelu float16 2D tensor",
"inputs": {
"input": {
"shape": [4, 6],
"data": "float64Data",
"type": "float16"
"data": "float16DataInput",
"dataType": "float16"
}
},
"expected": {
"name": "output",
"shape": [4, 6],
"data": "float16Data",
"type": "float16"
"data": "float16DataOutput",
"dataType": "float16"
}
},
{
"name": "gelu float32 3D tensor",
"inputs": {
"input": {
"shape": [2, 3, 4],
"data": "float64Data",
"type": "float32"
"data": "float32DataInput",
"dataType": "float32"
}
},
"expected": {
"name": "output",
"shape": [2, 3, 4],
"data": "float32Data",
"type": "float32"
"data": "float32DataOutput",
"dataType": "float32"
}
},
{
"name": "gelu float16 3D tensor",
"inputs": {
"input": {
"shape": [2, 3, 4],
"data": "float64Data",
"type": "float16"
"data": "float16DataInput",
"dataType": "float16"
}
},
"expected": {
"name": "output",
"shape": [2, 3, 4],
"data": "float16Data",
"type": "float16"
"data": "float16DataOutput",
"dataType": "float16"
}
},
{
"name": "gelu float32 4D tensor",
"inputs": {
"input": {
"shape": [2, 2, 2, 3],
"data": "float64Data",
"type": "float32"
"data": "float32DataInput",
"dataType": "float32"
}
},
"expected": {
"name": "output",
"shape": [2, 2, 2, 3],
"data": "float32Data",
"type": "float32"
"data": "float32DataOutput",
"dataType": "float32"
}
},
{
"name": "gelu float16 4D tensor",
"inputs": {
"input": {
"shape": [2, 2, 2, 3],
"data": "float64Data",
"type": "float16"
"data": "float16DataInput",
"dataType": "float16"
}
},
"expected": {
"name": "output",
"shape": [2, 2, 2, 3],
"data": "float16Data",
"type": "float16"
"data": "float16DataOutput",
"dataType": "float16"
}
},
{
"name": "gelu float32 5D tensor",
"inputs": {
"input": {
"shape": [2, 1, 4, 1, 3],
"data": "float64Data",
"type": "float32"
"data": "float32DataInput",
"dataType": "float32"
}
},
"expected": {
"name": "output",
"shape": [2, 1, 4, 1, 3],
"data": "float32Data",
"type": "float32"
"data": "float32DataOutput",
"dataType": "float32"
}
},
{
"name": "gelu float16 5D tensor",
"inputs": {
"input": {
"shape": [2, 1, 4, 1, 3],
"data": "float64Data",
"type": "float16"
"data": "float16DataInput",
"dataType": "float16"
}
},
"expected": {
"name": "output",
"shape": [2, 1, 4, 1, 3],
"data": "float16Data",
"type": "float16"
"data": "float16DataOutput",
"dataType": "float16"
}
}
],
"inputsData": {
"float64DataScalar": {
"float32DataScalarInput": {
"shape": [1],
"type": "float64"
"dataType": "float32"
},
"float32DataInput": {
"shape": [24],
"dataType": "float32"
},
"float16DataScalarInput": {
"shape": [1],
"dataType": "float16"
},
"float64Data": {
"float16DataInput": {
"shape": [24],
"type": "float64"
"dataType": "float16"
}
},
"inputsDataRange": {
"max": 1,
"min": -1
"max": 1,
"min": -1
}
}
Loading

0 comments on commit 9a222ab

Please sign in to comment.