From 026514121bda3eb380543d211d63c873f07b95ce Mon Sep 17 00:00:00 2001 From: BruceDai Date: Wed, 15 May 2024 15:57:21 +0800 Subject: [PATCH 1/5] Upgrade node vesrion to 18 for CI --- .github/workflows/build_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index d18eb5e..6ae62c7 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -25,7 +25,7 @@ jobs: - uses: actions/setup-node@v3.5.1 with: - node-version: '14.x' + node-version: '18.x' - run: npm install From a7105c883ecbcabb26c48e9293945779c123c5cb Mon Sep 17 00:00:00 2001 From: BruceDai Date: Wed, 15 May 2024 16:00:41 +0800 Subject: [PATCH 2/5] Generate fp16 and fp32 baseline data for softsign operator --- package.json | 3 + test/tools/README.md | 23 + test/tools/gen-operator-with-single-input.js | 78 ++ test/tools/resources/softsign.json | 216 +++++ test/tools/test-data-wpt/softsign.json | 884 +++++++++++++++++++ test/tools/test-data/softsign-data.json | 240 +++++ test/tools/utils.js | 236 +++++ 7 files changed, 1680 insertions(+) create mode 100644 test/tools/README.md create mode 100644 test/tools/gen-operator-with-single-input.js create mode 100644 test/tools/resources/softsign.json create mode 100644 test/tools/test-data-wpt/softsign.json create mode 100644 test/tools/test-data/softsign-data.json create mode 100644 test/tools/utils.js diff --git a/package.json b/package.json index d526960..3fea11d 100644 --- a/package.json +++ b/package.json @@ -23,5 +23,8 @@ "eslint-plugin-jsdoc": "^30.3.1", "eslint-plugin-prefer-arrow": "^1.2.2", "mocha": "^9.0.3" + }, + "dependencies": { + "@petamoriken/float16": "^3.8.7" } } diff --git a/test/tools/README.md b/test/tools/README.md new file mode 100644 index 0000000..2fc620d --- /dev/null +++ b/test/tools/README.md @@ -0,0 +1,23 @@ +How to generate test-data file for WPT tests? + +Step 1: Please prepare resources JSON file which includes those tests +to test each operator of WebNN API without specified inputs and outputs +data. + +Step 2: Implement generate test-data scripts + +Step 3: Execute command for generating test-data files for WPT tests + +```shell +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 +./test-data/softsign-data.json, +and raw WPT test-data file as being ./test-data-wpt/softsign.json. + + +You can manually modify some test data in +./test-data/softsign-data.json, +then execute Step 3, to update ./test-data-wpt/softsign.json. \ No newline at end of file diff --git a/test/tools/gen-operator-with-single-input.js b/test/tools/gen-operator-with-single-input.js new file mode 100644 index 0000000..96d123e --- /dev/null +++ b/test/tools/gen-operator-with-single-input.js @@ -0,0 +1,78 @@ +'use strict'; + +/* eslint guard-for-in: 0 */ + +import path from 'path'; +import {softsign} from '../../src/softsign.js'; +import {Tensor} from '../../src/lib/tensor.js'; +import {utils} from './utils.js'; + +(() => { + function computeBySingleInput(operatorName, input, options = {}) { + const operatorMappingDict = { + 'softsign': softsign, + }; + const inputTensor = new Tensor(input.shape, input.data); + const outputTensor = + operatorMappingDict[operatorName](inputTensor, options); + return outputTensor.data; + } + + const testDataFileName = path.basename(process.argv[2]); + const operatorString = + testDataFileName.slice(0, testDataFileName.indexOf('.json')); + const savedDataFile = path.join( + path.dirname(process.argv[1]), 'test-data', + `${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); + toSaveDataDict['expectedData'] = {}; + const tests = jsonDict.tests; + const wptTests = JSON.parse(JSON.stringify(tests)); + for (const test of tests) { + console.log(`name ${test.name}`); + const precisionDataInput = utils.getPrecisionDataFromDataDict( + toSaveDataDict['inputsData'], test.inputs.input.data, + test.inputs.input.type); + 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.writeJsonFile(toSaveDataDict, savedDataFile); + console.log(`[ Done ] Saved test data into ${savedDataFile}.`); + + const wptConformanceTestsDict = {tests: []}; + for (const test of wptTests) { + // update inputs data + for (const inputName in test.inputs) { + test.inputs[inputName].data = + typeof test.inputs[inputName].data === 'number' || + (typeof test.inputs[inputName].data === 'object' && + typeof test.inputs[inputName].data[0] === 'number') ? + test.inputs[inputName].data : + toSaveDataDict['inputsData'][test.inputs[inputName].data]; + } + // update weights (scale, bias, and etc.) data of options + if (test.options) { + for (const optionName in test.options) { + if (test.options[optionName].data) { + test.options[optionName].data = + toSaveDataDict['inputsData'][test.options[optionName].data]; + } + } + } + // update expected data + 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.`); +})(); diff --git a/test/tools/resources/softsign.json b/test/tools/resources/softsign.json new file mode 100644 index 0000000..b103cfa --- /dev/null +++ b/test/tools/resources/softsign.json @@ -0,0 +1,216 @@ +{ + "tests": [ + { + "name": "softsign positive float32 1D tensor", + "inputs": { + "input": { + "shape": [24], + "data": "float641DPositiveInput", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [24], + "data": "float321DPositiveDefault", + "type": "float32" + } + }, + { + "name": "softsign negative float32 1D tensor", + "inputs": { + "input": { + "shape": [24], + "data": "float641DNegativeInput", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [24], + "data": "float321DNegativeDefault", + "type": "float32" + } + }, + { + "name": "softsign float32 2D tensor", + "inputs": { + "input": { + "shape": [4, 6], + "data": "float642DInput", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [4, 6], + "data": "float322DDefault", + "type": "float32" + } + }, + { + "name": "softsign float32 3D tensor", + "inputs": { + "input": { + "shape": [2, 3, 4], + "data": "float642DInput", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [2, 3, 4], + "data": "float322DDefault", + "type": "float32" + } + }, + { + "name": "softsign float32 4D tensor", + "inputs": { + "input": { + "shape": [1, 2, 3, 4], + "data": "float642DInput", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [1, 2, 3, 4], + "data": "float322DDefault", + "type": "float32" + } + }, + { + "name": "softsign float32 5D tensor", + "inputs": { + "input": { + "shape": [1, 2, 1, 3, 4], + "data": "float642DInput", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [1, 2, 1, 3, 4], + "data": "float322DDefault", + "type": "float32" + } + }, + { + "name": "softsign positive float16 1D tensor", + "inputs": { + "input": { + "shape": [24], + "data": "float641DPositiveInput", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [24], + "data": "float161DPositiveDefault", + "type": "float16" + } + }, + { + "name": "softsign negative float16 1D tensor", + "inputs": { + "input": { + "shape": [24], + "data": "float641DNegativeInput", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [24], + "data": "float161DNegativeDefault", + "type": "float16" + } + }, + { + "name": "softsign float16 2D tensor", + "inputs": { + "input": { + "shape": [4, 6], + "data": "float642DInput", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [4, 6], + "data": "float162DDefault", + "type": "float16" + } + }, + { + "name": "softsign float16 3D tensor", + "inputs": { + "input": { + "shape": [2, 3, 4], + "data": "float642DInput", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [2, 3, 4], + "data": "float162DDefault", + "type": "float16" + } + }, + { + "name": "softsign float16 4D tensor", + "inputs": { + "input": { + "shape": [1, 2, 3, 4], + "data": "float642DInput", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [1, 2, 3, 4], + "data": "float162DDefault", + "type": "float16" + } + }, + { + "name": "softsign float16 5D tensor", + "inputs": { + "input": { + "shape": [1, 2, 1, 3, 4], + "data": "float642DInput", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [1, 2, 1, 3, 4], + "data": "float162DDefault", + "type": "float16" + } + } + ], + "inputsData": { + "float641DPositiveInput": { + "shape": [24], + "type": "float64", + "sign": "positive" + }, + "float641DNegativeInput": { + "shape": [24], + "type": "float64", + "sign": "negative" + }, + "float642DInput": { + "shape": [24], + "type": "float64" + } + }, + "inputsDataRange": { + "max": 10, + "min": -10 + } +} \ No newline at end of file diff --git a/test/tools/test-data-wpt/softsign.json b/test/tools/test-data-wpt/softsign.json new file mode 100644 index 0000000..31df44d --- /dev/null +++ b/test/tools/test-data-wpt/softsign.json @@ -0,0 +1,884 @@ +{ + "tests": [ + { + "name": "softsign positive float32 1D tensor", + "inputs": { + "input": { + "shape": [ + 24 + ], + "data": [ + 1.5834133593790956, + 4.0787189411490115, + 8.883356617490337, + 8.070860233252166, + 8.211773633019915, + 2.4554003891197818, + 0.653374178120758, + 7.866281154604682, + 3.1239552336192666, + 8.013792390668268, + 3.9409862749371283, + 1.8131727337833081, + 2.390676102273188, + 1.3359680092645565, + 9.416410839467265, + 0.44325690899325254, + 5.236662013213598, + 9.424242359034539, + 7.816190418459348, + 5.849185795081855, + 8.780370640491928, + 5.1205157788312246, + 7.1172223514005095, + 4.59910661262345 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 24 + ], + "data": [ + 0.6129152178764343, + 0.8030999898910522, + 0.8988198041915894, + 0.8897568583488464, + 0.8914432525634766, + 0.7105979323387146, + 0.3951762318611145, + 0.8872131109237671, + 0.7575143575668335, + 0.8890588879585266, + 0.7976112365722656, + 0.6445294618606567, + 0.7050735354423523, + 0.5719119310379028, + 0.9039976596832275, + 0.30712267756462097, + 0.8396578431129456, + 0.9040697813034058, + 0.8865723013877869, + 0.8539972305297852, + 0.8977543711662292, + 0.8366150856018066, + 0.8768051266670227, + 0.8214001059532166 + ], + "type": "float32" + } + }, + { + "name": "softsign negative float32 1D tensor", + "inputs": { + "input": { + "shape": [ + 24 + ], + "data": [ + -2.5978440095516913, + -0.4449555447737712, + -9.095475232407683, + -3.7480076975512873, + -1.3867289790255697, + -8.220328902868987, + -3.538342320320556, + -9.364588742025619, + -6.283252341501335, + -5.0020120266550006, + -8.245729151019969, + -3.775470497728266, + -4.087254829132392, + -7.3816760861585795, + -5.882921529710956, + -8.338910337100263, + -6.6015492897072185, + -4.491942000901396, + -3.524778486355298, + -4.439912258765581, + -5.2342625634221225, + -1.5911732471016933, + -9.106277545690418, + -8.523774275382141 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 24 + ], + "data": [ + -0.7220557928085327, + -0.3079372048377991, + -0.9009457230567932, + -0.7893853783607483, + -0.5810165405273438, + -0.891543984413147, + -0.7796552181243896, + -0.9035176634788513, + -0.8626986742019653, + -0.8333892226219177, + -0.8918419480323792, + -0.7905965447425842, + -0.8034303188323975, + -0.8806921243667603, + -0.8547128438949585, + -0.8929211497306824, + -0.8684478402137756, + -0.8179150223731995, + -0.7789947390556335, + -0.8161734938621521, + -0.8395960927009583, + -0.6140744686126709, + -0.9010515809059143, + -0.894999623298645 + ], + "type": "float32" + } + }, + { + "name": "softsign float32 2D tensor", + "inputs": { + "input": { + "shape": [ + 4, + 6 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 4, + 6 + ], + "data": [ + -0.8929736614227295, + -0.8737397789955139, + 0.7297033667564392, + -0.8965135812759399, + -0.7613669633865356, + 0.8844983577728271, + 0.8692847490310669, + 0.8583170175552368, + 0.3988332748413086, + 0.8530665636062622, + -0.24710771441459656, + 0.5595548748970032, + -0.9086434245109558, + 0.8735038042068481, + -0.03013519011437893, + -0.798778235912323, + 0.8624640107154846, + -0.7252188920974731, + 0.7531687617301941, + 0.88132643699646, + -0.8942321538925171, + 0.8770874738693237, + -0.8329461812973022, + -0.8871282935142517 + ], + "type": "float32" + } + }, + { + "name": "softsign float32 3D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 3, + 4 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 3, + 4 + ], + "data": [ + -0.8929736614227295, + -0.8737397789955139, + 0.7297033667564392, + -0.8965135812759399, + -0.7613669633865356, + 0.8844983577728271, + 0.8692847490310669, + 0.8583170175552368, + 0.3988332748413086, + 0.8530665636062622, + -0.24710771441459656, + 0.5595548748970032, + -0.9086434245109558, + 0.8735038042068481, + -0.03013519011437893, + -0.798778235912323, + 0.8624640107154846, + -0.7252188920974731, + 0.7531687617301941, + 0.88132643699646, + -0.8942321538925171, + 0.8770874738693237, + -0.8329461812973022, + -0.8871282935142517 + ], + "type": "float32" + } + }, + { + "name": "softsign float32 4D tensor", + "inputs": { + "input": { + "shape": [ + 1, + 2, + 3, + 4 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 1, + 2, + 3, + 4 + ], + "data": [ + -0.8929736614227295, + -0.8737397789955139, + 0.7297033667564392, + -0.8965135812759399, + -0.7613669633865356, + 0.8844983577728271, + 0.8692847490310669, + 0.8583170175552368, + 0.3988332748413086, + 0.8530665636062622, + -0.24710771441459656, + 0.5595548748970032, + -0.9086434245109558, + 0.8735038042068481, + -0.03013519011437893, + -0.798778235912323, + 0.8624640107154846, + -0.7252188920974731, + 0.7531687617301941, + 0.88132643699646, + -0.8942321538925171, + 0.8770874738693237, + -0.8329461812973022, + -0.8871282935142517 + ], + "type": "float32" + } + }, + { + "name": "softsign float32 5D tensor", + "inputs": { + "input": { + "shape": [ + 1, + 2, + 1, + 3, + 4 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 1, + 2, + 1, + 3, + 4 + ], + "data": [ + -0.8929736614227295, + -0.8737397789955139, + 0.7297033667564392, + -0.8965135812759399, + -0.7613669633865356, + 0.8844983577728271, + 0.8692847490310669, + 0.8583170175552368, + 0.3988332748413086, + 0.8530665636062622, + -0.24710771441459656, + 0.5595548748970032, + -0.9086434245109558, + 0.8735038042068481, + -0.03013519011437893, + -0.798778235912323, + 0.8624640107154846, + -0.7252188920974731, + 0.7531687617301941, + 0.88132643699646, + -0.8942321538925171, + 0.8770874738693237, + -0.8329461812973022, + -0.8871282935142517 + ], + "type": "float32" + } + }, + { + "name": "softsign positive float16 1D tensor", + "inputs": { + "input": { + "shape": [ + 24 + ], + "data": [ + 1.5834133593790956, + 4.0787189411490115, + 8.883356617490337, + 8.070860233252166, + 8.211773633019915, + 2.4554003891197818, + 0.653374178120758, + 7.866281154604682, + 3.1239552336192666, + 8.013792390668268, + 3.9409862749371283, + 1.8131727337833081, + 2.390676102273188, + 1.3359680092645565, + 9.416410839467265, + 0.44325690899325254, + 5.236662013213598, + 9.424242359034539, + 7.816190418459348, + 5.849185795081855, + 8.780370640491928, + 5.1205157788312246, + 7.1172223514005095, + 4.59910661262345 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 24 + ], + "data": [ + 0.61279296875, + 0.80322265625, + 0.89892578125, + 0.8896484375, + 0.8916015625, + 0.71044921875, + 0.395263671875, + 0.88720703125, + 0.75732421875, + 0.88916015625, + 0.7978515625, + 0.64453125, + 0.705078125, + 0.57177734375, + 0.90380859375, + 0.30712890625, + 0.83984375, + 0.90380859375, + 0.88671875, + 0.85400390625, + 0.89794921875, + 0.83642578125, + 0.876953125, + 0.8212890625 + ], + "type": "float16" + } + }, + { + "name": "softsign negative float16 1D tensor", + "inputs": { + "input": { + "shape": [ + 24 + ], + "data": [ + -2.5978440095516913, + -0.4449555447737712, + -9.095475232407683, + -3.7480076975512873, + -1.3867289790255697, + -8.220328902868987, + -3.538342320320556, + -9.364588742025619, + -6.283252341501335, + -5.0020120266550006, + -8.245729151019969, + -3.775470497728266, + -4.087254829132392, + -7.3816760861585795, + -5.882921529710956, + -8.338910337100263, + -6.6015492897072185, + -4.491942000901396, + -3.524778486355298, + -4.439912258765581, + -5.2342625634221225, + -1.5911732471016933, + -9.106277545690418, + -8.523774275382141 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 24 + ], + "data": [ + -0.72216796875, + -0.30810546875, + -0.90087890625, + -0.78955078125, + -0.5810546875, + -0.8916015625, + -0.77978515625, + -0.9033203125, + -0.86279296875, + -0.83349609375, + -0.8916015625, + -0.79052734375, + -0.80322265625, + -0.880859375, + -0.8544921875, + -0.89306640625, + -0.86865234375, + -0.81787109375, + -0.77880859375, + -0.81640625, + -0.83935546875, + -0.6142578125, + -0.90087890625, + -0.89501953125 + ], + "type": "float16" + } + }, + { + "name": "softsign float16 2D tensor", + "inputs": { + "input": { + "shape": [ + 4, + 6 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 4, + 6 + ], + "data": [ + -0.89306640625, + -0.87353515625, + 0.7294921875, + -0.896484375, + -0.76123046875, + 0.88427734375, + 0.869140625, + 0.8583984375, + 0.39892578125, + 0.85302734375, + -0.2470703125, + 0.5595703125, + -0.90869140625, + 0.87353515625, + -0.0301361083984375, + -0.798828125, + 0.8623046875, + -0.72509765625, + 0.7529296875, + 0.88134765625, + -0.89404296875, + 0.876953125, + -0.8330078125, + -0.88720703125 + ], + "type": "float16" + } + }, + { + "name": "softsign float16 3D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 3, + 4 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 3, + 4 + ], + "data": [ + -0.89306640625, + -0.87353515625, + 0.7294921875, + -0.896484375, + -0.76123046875, + 0.88427734375, + 0.869140625, + 0.8583984375, + 0.39892578125, + 0.85302734375, + -0.2470703125, + 0.5595703125, + -0.90869140625, + 0.87353515625, + -0.0301361083984375, + -0.798828125, + 0.8623046875, + -0.72509765625, + 0.7529296875, + 0.88134765625, + -0.89404296875, + 0.876953125, + -0.8330078125, + -0.88720703125 + ], + "type": "float16" + } + }, + { + "name": "softsign float16 4D tensor", + "inputs": { + "input": { + "shape": [ + 1, + 2, + 3, + 4 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 1, + 2, + 3, + 4 + ], + "data": [ + -0.89306640625, + -0.87353515625, + 0.7294921875, + -0.896484375, + -0.76123046875, + 0.88427734375, + 0.869140625, + 0.8583984375, + 0.39892578125, + 0.85302734375, + -0.2470703125, + 0.5595703125, + -0.90869140625, + 0.87353515625, + -0.0301361083984375, + -0.798828125, + 0.8623046875, + -0.72509765625, + 0.7529296875, + 0.88134765625, + -0.89404296875, + 0.876953125, + -0.8330078125, + -0.88720703125 + ], + "type": "float16" + } + }, + { + "name": "softsign float16 5D tensor", + "inputs": { + "input": { + "shape": [ + 1, + 2, + 1, + 3, + 4 + ], + "data": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 1, + 2, + 1, + 3, + 4 + ], + "data": [ + -0.89306640625, + -0.87353515625, + 0.7294921875, + -0.896484375, + -0.76123046875, + 0.88427734375, + 0.869140625, + 0.8583984375, + 0.39892578125, + 0.85302734375, + -0.2470703125, + 0.5595703125, + -0.90869140625, + 0.87353515625, + -0.0301361083984375, + -0.798828125, + 0.8623046875, + -0.72509765625, + 0.7529296875, + 0.88134765625, + -0.89404296875, + 0.876953125, + -0.8330078125, + -0.88720703125 + ], + "type": "float16" + } + } + ] +} \ No newline at end of file diff --git a/test/tools/test-data/softsign-data.json b/test/tools/test-data/softsign-data.json new file mode 100644 index 0000000..d12f0e1 --- /dev/null +++ b/test/tools/test-data/softsign-data.json @@ -0,0 +1,240 @@ +{ + "inputsData": { + "float641DPositiveInput": [ + 1.5834133593790956, + 4.0787189411490115, + 8.883356617490337, + 8.070860233252166, + 8.211773633019915, + 2.4554003891197818, + 0.653374178120758, + 7.866281154604682, + 3.1239552336192666, + 8.013792390668268, + 3.9409862749371283, + 1.8131727337833081, + 2.390676102273188, + 1.3359680092645565, + 9.416410839467265, + 0.44325690899325254, + 5.236662013213598, + 9.424242359034539, + 7.816190418459348, + 5.849185795081855, + 8.780370640491928, + 5.1205157788312246, + 7.1172223514005095, + 4.59910661262345 + ], + "float641DNegativeInput": [ + -2.5978440095516913, + -0.4449555447737712, + -9.095475232407683, + -3.7480076975512873, + -1.3867289790255697, + -8.220328902868987, + -3.538342320320556, + -9.364588742025619, + -6.283252341501335, + -5.0020120266550006, + -8.245729151019969, + -3.775470497728266, + -4.087254829132392, + -7.3816760861585795, + -5.882921529710956, + -8.338910337100263, + -6.6015492897072185, + -4.491942000901396, + -3.524778486355298, + -4.439912258765581, + -5.2342625634221225, + -1.5911732471016933, + -9.106277545690418, + -8.523774275382141 + ], + "float642DInput": [ + -8.343496173533422, + -6.92015211612679, + 2.699638761922575, + -8.663104577031863, + -3.190534368785616, + 7.657887080586452, + 6.650215091182602, + 6.058011004380681, + 0.6634320403254037, + 5.805803683155526, + -0.32821124531446344, + 1.270430403469046, + -9.946119978610852, + 6.905375202832072, + -0.031071535439890496, + -3.9696409293645862, + 6.270823207970878, + -2.6392608577007914, + 3.051350503137261, + 7.42647683445869, + -8.454667518154086, + 7.135868292466057, + -4.9860941550065885, + -7.859615086397076 + ] + }, + "expectedData": { + "float321DPositiveDefault": [ + 0.6129152178764343, + 0.8030999898910522, + 0.8988198041915894, + 0.8897568583488464, + 0.8914432525634766, + 0.7105979323387146, + 0.3951762318611145, + 0.8872131109237671, + 0.7575143575668335, + 0.8890588879585266, + 0.7976112365722656, + 0.6445294618606567, + 0.7050735354423523, + 0.5719119310379028, + 0.9039976596832275, + 0.30712267756462097, + 0.8396578431129456, + 0.9040697813034058, + 0.8865723013877869, + 0.8539972305297852, + 0.8977543711662292, + 0.8366150856018066, + 0.8768051266670227, + 0.8214001059532166 + ], + "float321DNegativeDefault": [ + -0.7220557928085327, + -0.3079372048377991, + -0.9009457230567932, + -0.7893853783607483, + -0.5810165405273438, + -0.891543984413147, + -0.7796552181243896, + -0.9035176634788513, + -0.8626986742019653, + -0.8333892226219177, + -0.8918419480323792, + -0.7905965447425842, + -0.8034303188323975, + -0.8806921243667603, + -0.8547128438949585, + -0.8929211497306824, + -0.8684478402137756, + -0.8179150223731995, + -0.7789947390556335, + -0.8161734938621521, + -0.8395960927009583, + -0.6140744686126709, + -0.9010515809059143, + -0.894999623298645 + ], + "float322DDefault": [ + -0.8929736614227295, + -0.8737397789955139, + 0.7297033667564392, + -0.8965135812759399, + -0.7613669633865356, + 0.8844983577728271, + 0.8692847490310669, + 0.8583170175552368, + 0.3988332748413086, + 0.8530665636062622, + -0.24710771441459656, + 0.5595548748970032, + -0.9086434245109558, + 0.8735038042068481, + -0.03013519011437893, + -0.798778235912323, + 0.8624640107154846, + -0.7252188920974731, + 0.7531687617301941, + 0.88132643699646, + -0.8942321538925171, + 0.8770874738693237, + -0.8329461812973022, + -0.8871282935142517 + ], + "float161DPositiveDefault": [ + 0.61279296875, + 0.80322265625, + 0.89892578125, + 0.8896484375, + 0.8916015625, + 0.71044921875, + 0.395263671875, + 0.88720703125, + 0.75732421875, + 0.88916015625, + 0.7978515625, + 0.64453125, + 0.705078125, + 0.57177734375, + 0.90380859375, + 0.30712890625, + 0.83984375, + 0.90380859375, + 0.88671875, + 0.85400390625, + 0.89794921875, + 0.83642578125, + 0.876953125, + 0.8212890625 + ], + "float161DNegativeDefault": [ + -0.72216796875, + -0.30810546875, + -0.90087890625, + -0.78955078125, + -0.5810546875, + -0.8916015625, + -0.77978515625, + -0.9033203125, + -0.86279296875, + -0.83349609375, + -0.8916015625, + -0.79052734375, + -0.80322265625, + -0.880859375, + -0.8544921875, + -0.89306640625, + -0.86865234375, + -0.81787109375, + -0.77880859375, + -0.81640625, + -0.83935546875, + -0.6142578125, + -0.90087890625, + -0.89501953125 + ], + "float162DDefault": [ + -0.89306640625, + -0.87353515625, + 0.7294921875, + -0.896484375, + -0.76123046875, + 0.88427734375, + 0.869140625, + 0.8583984375, + 0.39892578125, + 0.85302734375, + -0.2470703125, + 0.5595703125, + -0.90869140625, + 0.87353515625, + -0.0301361083984375, + -0.798828125, + 0.8623046875, + -0.72509765625, + 0.7529296875, + 0.88134765625, + -0.89404296875, + 0.876953125, + -0.8330078125, + -0.88720703125 + ] + } +} \ No newline at end of file diff --git a/test/tools/utils.js b/test/tools/utils.js new file mode 100644 index 0000000..a00bfec --- /dev/null +++ b/test/tools/utils.js @@ -0,0 +1,236 @@ +'use strict'; + +import fs from 'fs'; +import path from 'path'; +import {Float16Array} from '@petamoriken/float16'; + +import {Tensor, sizeOfShape} from '../../src/lib/tensor.js'; +import {neg} from '../../src/unary.js'; +import {transpose} from '../../src/transpose.js'; + + +/** + * Convert data as required precision type. + * @param {Array} input + * @param {String} precisionType + * @return {Array} + */ +function getPrecisionData(input, precisionType) { + let data; + const isNumber = typeof input === 'number'; + if (isNumber) { + input = [input]; + } + switch (precisionType) { + case 'float32': + data = new Float32Array(input); + break; + case 'float16': + data = new Float16Array(input); + break; + case 'float64': + data = new Float64Array(input); + break; + case 'uint8': + data = new Uint8Array(input); + break; + case 'uint32': + data = new Uint32Array(input); + break; + case 'int64': + // data = new BigInt64Array(input.map(x => BigInt(x))); + // data = new Array(input.map(x => BigInt(x).toString())); + data = new Int32Array(input); + break; + default: + break; + } + if (isNumber) { + data = data[0]; + } + return data; +} + + +/** + * Get converted data from given data dict with specified field and precision type. + * @param {Object} srcDataDict + * @param {String} source + * @param {String} precisionType + * @return {Array} + */ +function getPrecisionDataFromDataDict(srcDataDict, source, precisionType) { + const feedData = srcDataDict[source]; + return getPrecisionData(feedData, precisionType); +} + +/** + * Get a random number between the specified values + * @param {Number} min + * @param {Number} max + * @param {String} type default 'float64' + * @param {String} sign default 'positive' + * @return {Number} + */ +function getRandom(min, max, type = 'float64', sign = 'positive') { + if (sign === 'positive') { + if (min < 0) { + min = 0; + } + } else if (sign === 'negative') { + if (max > 0) { + max = 0; + } + } + + if (type === 'float64' || type === 'float32' || type === 'float16') { + return Math.random() * (max - min) + min; + } else if (type === 'int32') { + min = Math.ceil(min) + 1; + max = Math.floor(max) - 1; + // The maximum is exclusive and the minimum is inclusive + return Math.floor(Math.random() * (max - min) + min); + } else if (type === 'int64'||type === 'uint32') { + return Math.floor(Math.random() * (max - min + 1) + min); + } else if (type === 'uint8') { + let randomUint8Value; + if (Math.random() < 0.2) { + randomUint8Value = 0; + } else { + randomUint8Value = Math.floor(Math.random() * 255); + } + return randomUint8Value; + } +} + +/** + * Get random numbers between the specified values + * @param {Number} min + * @param {Number} max + * @param {Number} size + * @param {String} [type='float64'] + * @param {String} [sign='mixed'] + * @return {Array} + */ +function getRandomNumbers(min, max, size, type = 'float64', sign='mixed') { + const data = new Array(size); + for (let i = 0; i < size; i++) { + data[i] = getRandom(min, max, type, sign); + } + return getPrecisionData(data, type); +} + +/** + * Prepare input data by specified config of inputsDataInfo, dataFile, min, + * max parameters . + * @param {Object} inputsDataInfo information object for input data + * @param {String} dataFile saved data file path + * @param {Number} min + * @param {Number} max + * @return {Object} + */ +function prepareInputsData(inputsDataInfo, dataFile, min, max) { + const dstDataDict = {inputsData: {}}; + let srcDataDict = {}; + if (fs.existsSync(dataFile)) { + srcDataDict = utils.readJsonFile(dataFile); + } + for (const source in inputsDataInfo) { + // reserve last input data when generating new required input data + if (srcDataDict['inputsData'] !== undefined && + srcDataDict['inputsData'][source] !== undefined) { + dstDataDict['inputsData'][source] = srcDataDict['inputsData'][source]; + } else { + const targetDataInfo = inputsDataInfo[source]; + if (targetDataInfo.data !== undefined) { + const srcDataInfo = inputsDataInfo[targetDataInfo.data]; + const inputTensor = new Tensor( + srcDataInfo.shape, dstDataDict['inputsData'][targetDataInfo.data]); + let outputTensor; + if (targetDataInfo.processCategory === 'transpose') { + outputTensor = transpose( + inputTensor, {permutation: targetDataInfo.permutation}); + } else if (targetDataInfo.processCategory === 'negative') { + outputTensor = neg(inputTensor); + } + console.log(`source ${source}`); + dstDataDict['inputsData'][source] = outputTensor.data; + } else { + const total = sizeOfShape(targetDataInfo.shape); + const sign = targetDataInfo.sign; + const type = targetDataInfo.type; + if (targetDataInfo.dataRange) { + min = targetDataInfo.dataRange[0]; + max = targetDataInfo.dataRange[1]; + } + const generatedNumbers = + utils.getRandomNumbers(min, max, total, type, sign); + dstDataDict['inputsData'][source] = generatedNumbers; + } + } + } + return dstDataDict; +} + +/** + * Get JSON object from specified JSON file. + * @param {String} filePath + * @return {Object} + */ +function readJsonFile(filePath) { + let inputFile; + if (path.isAbsolute(filePath)) { + inputFile = filePath; + } else { + inputFile = + path.join(path.dirname(process.argv[1]), filePath); + } + const content = fs.readFileSync(inputFile).toString(); + const jsonDict = JSON.parse( + content.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, + (m, g) => g ? '' : m)); + return jsonDict; +} + +/** + * Save JSON infomation into file. + * @param {Object} jsonDict + * @param {String} saveFile + */ +function writeJsonFile(jsonDict, saveFile) { + const parentDirectory = path.dirname(saveFile); + if (!fs.existsSync(parentDirectory)) { + fs.mkdirSync(parentDirectory); + } + const jsonString = JSON.stringify(jsonDict, function(key, value) { + // the replacer function is looking for some typed arrays. + // If found, it replaces it by a trio + if ( value instanceof Int8Array || + value instanceof Uint8Array || + value instanceof Uint16Array || + value instanceof Int32Array || + value instanceof Uint32Array || + value instanceof Float32Array || + value instanceof Float16Array || + value instanceof Float64Array ) { + if (value.length ===1) { // value instanceof Uint8Array && + const result = []; + result[0] = value[0]; + return result; + } else { + return Array.apply([], value); + } + } + return value; + }, 2); + fs.writeFileSync(saveFile, jsonString); +} + +export const utils = { + getPrecisionData: getPrecisionData, + getPrecisionDataFromDataDict: getPrecisionDataFromDataDict, + getRandomNumbers: getRandomNumbers, + prepareInputsData: prepareInputsData, + readJsonFile: readJsonFile, + writeJsonFile: writeJsonFile, +}; From 991a9f0cf2d72450cacdd116be382f5cc8b0af45 Mon Sep 17 00:00:00 2001 From: BruceDai Date: Tue, 28 May 2024 11:38:01 +0800 Subject: [PATCH 3/5] Generate baseline data for gelu operator --- test/tools/gen-operator-with-single-input.js | 6 +- test/tools/resources/gelu.json | 210 +++++ test/tools/test-data-wpt/gelu.json | 784 +++++++++++++++++++ test/tools/test-data/gelu-data.json | 93 +++ 4 files changed, 1092 insertions(+), 1 deletion(-) create mode 100644 test/tools/resources/gelu.json create mode 100644 test/tools/test-data-wpt/gelu.json create mode 100644 test/tools/test-data/gelu-data.json diff --git a/test/tools/gen-operator-with-single-input.js b/test/tools/gen-operator-with-single-input.js index 96d123e..6725aee 100644 --- a/test/tools/gen-operator-with-single-input.js +++ b/test/tools/gen-operator-with-single-input.js @@ -4,12 +4,14 @@ import path from 'path'; import {softsign} from '../../src/softsign.js'; +import {gelu} from '../../src/gelu.js'; import {Tensor} from '../../src/lib/tensor.js'; import {utils} from './utils.js'; (() => { function computeBySingleInput(operatorName, input, options = {}) { const operatorMappingDict = { + 'gelu': gelu, 'softsign': softsign, }; const inputTensor = new Tensor(input.shape, input.data); @@ -55,7 +57,9 @@ import {utils} from './utils.js'; (typeof test.inputs[inputName].data === 'object' && typeof test.inputs[inputName].data[0] === 'number') ? test.inputs[inputName].data : - toSaveDataDict['inputsData'][test.inputs[inputName].data]; + utils.getPrecisionDataFromDataDict( + toSaveDataDict['inputsData'], test.inputs[inputName].data, + test.inputs[inputName].type); } // update weights (scale, bias, and etc.) data of options if (test.options) { diff --git a/test/tools/resources/gelu.json b/test/tools/resources/gelu.json new file mode 100644 index 0000000..be2d0ce --- /dev/null +++ b/test/tools/resources/gelu.json @@ -0,0 +1,210 @@ +{ + "tests": [ + { + "name": "gelu float32 0D scalar", + "inputs": { + "input": { + "shape": [], + "data": "float64DataScalar", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [], + "data": "float32DataScalar", + "type": "float32" + } + }, + { + "name": "gelu float16 0D scalar", + "inputs": { + "input": { + "shape": [], + "data": "float64DataScalar", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [], + "data": "float16DataScalar", + "type": "float16" + } + }, + { + "name": "gelu float32 1D tensor", + "inputs": { + "input": { + "shape": [24], + "data": "float64Data", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [24], + "data": "float32Data", + "type": "float32" + } + }, + { + "name": "gelu float16 1D tensor", + "inputs": { + "input": { + "shape": [24], + "data": "float64Data", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [24], + "data": "float16Data", + "type": "float16" + } + }, + { + "name": "gelu float32 2D tensor", + "inputs": { + "input": { + "shape": [4, 6], + "data": "float64Data", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [4, 6], + "data": "float32Data", + "type": "float32" + } + }, + { + "name": "gelu float16 2D tensor", + "inputs": { + "input": { + "shape": [4, 6], + "data": "float64Data", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [4, 6], + "data": "float16Data", + "type": "float16" + } + }, + { + "name": "gelu float32 3D tensor", + "inputs": { + "input": { + "shape": [2, 3, 4], + "data": "float64Data", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [2, 3, 4], + "data": "float32Data", + "type": "float32" + } + }, + { + "name": "gelu float16 3D tensor", + "inputs": { + "input": { + "shape": [2, 3, 4], + "data": "float64Data", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [2, 3, 4], + "data": "float16Data", + "type": "float16" + } + }, + { + "name": "gelu float32 4D tensor", + "inputs": { + "input": { + "shape": [2, 2, 2, 3], + "data": "float64Data", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [2, 2, 2, 3], + "data": "float32Data", + "type": "float32" + } + }, + { + "name": "gelu float16 4D tensor", + "inputs": { + "input": { + "shape": [2, 2, 2, 3], + "data": "float64Data", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [2, 2, 2, 3], + "data": "float16Data", + "type": "float16" + } + }, + { + "name": "gelu float32 5D tensor", + "inputs": { + "input": { + "shape": [2, 1, 4, 1, 3], + "data": "float64Data", + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [2, 1, 4, 1, 3], + "data": "float32Data", + "type": "float32" + } + }, + { + "name": "gelu float16 5D tensor", + "inputs": { + "input": { + "shape": [2, 1, 4, 1, 3], + "data": "float64Data", + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [2, 1, 4, 1, 3], + "data": "float16Data", + "type": "float16" + } + } + ], + "inputsData": { + "float64DataScalar": { + "shape": [1], + "type": "float64" + }, + "float64Data": { + "shape": [24], + "type": "float64" + } + }, + "inputsDataRange": { + "max": 1, + "min": -1 + } +} \ No newline at end of file diff --git a/test/tools/test-data-wpt/gelu.json b/test/tools/test-data-wpt/gelu.json new file mode 100644 index 0000000..a22684b --- /dev/null +++ b/test/tools/test-data-wpt/gelu.json @@ -0,0 +1,784 @@ +{ + "tests": [ + { + "name": "gelu float32 0D scalar", + "inputs": { + "input": { + "shape": [], + "data": [ + -0.044885843992233276 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [], + "data": [ + -0.021639423444867134 + ], + "type": "float32" + } + }, + { + "name": "gelu float16 0D scalar", + "inputs": { + "input": { + "shape": [], + "data": [ + -0.044891357421875 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [], + "data": [ + -0.021636962890625 + ], + "type": "float16" + } + }, + { + "name": "gelu float32 1D tensor", + "inputs": { + "input": { + "shape": [ + 24 + ], + "data": [ + 0.878292441368103, + -0.09706497937440872, + 0.1367187649011612, + 0.46406492590904236, + -0.26635801792144775, + -0.8252315521240234, + 0.8530909419059753, + 0.3846154808998108, + 0.6772316694259644, + -0.4811072051525116, + 0.2983909249305725, + 0.6777864098548889, + -0.526228129863739, + 0.3497541546821594, + -0.12918996810913086, + 0.5853934288024902, + -0.8950720429420471, + 0.028302494436502457, + -0.09901237487792969, + -0.8838679790496826, + -0.596120297908783, + 0.31863871216773987, + 0.4794037640094757, + -0.06489315629005432 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 24 + ], + "data": [ + 0.7115113139152527, + -0.0447796992957592, + 0.07579325884580612, + 0.3149605691432953, + -0.10520657151937485, + -0.16885890066623688, + 0.6851989030838013, + 0.24989959597587585, + 0.508513331413269, + -0.1516546905040741, + 0.18419598042964935, + 0.509049117565155, + -0.15753419697284698, + 0.22270187735557556, + -0.05795508995652199, + 0.42198580503463745, + -0.1659233123064041, + 0.014470770955085754, + -0.04560155048966408, + -0.1665063202381134, + -0.1642593890428543, + 0.19914908707141876, + 0.3279957175254822, + -0.030767757445573807 + ], + "type": "float32" + } + }, + { + "name": "gelu float16 1D tensor", + "inputs": { + "input": { + "shape": [ + 24 + ], + "data": [ + 0.87841796875, + -0.0970458984375, + 0.13671875, + 0.464111328125, + -0.266357421875, + -0.8251953125, + 0.85302734375, + 0.384521484375, + 0.67724609375, + -0.481201171875, + 0.29833984375, + 0.677734375, + -0.5263671875, + 0.349853515625, + -0.129150390625, + 0.58544921875, + -0.89501953125, + 0.0283050537109375, + -0.0989990234375, + -0.8837890625, + -0.59619140625, + 0.318603515625, + 0.4794921875, + -0.06488037109375 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 24 + ], + "data": [ + 0.71142578125, + -0.044769287109375, + 0.0758056640625, + 0.31494140625, + -0.105224609375, + -0.1688232421875, + 0.68505859375, + 0.2498779296875, + 0.50830078125, + -0.151611328125, + 0.1842041015625, + 0.5087890625, + -0.1575927734375, + 0.2227783203125, + -0.057952880859375, + 0.422119140625, + -0.1658935546875, + 0.01447296142578125, + -0.04559326171875, + -0.16650390625, + -0.164306640625, + 0.1990966796875, + 0.328125, + -0.03076171875 + ], + "type": "float16" + } + }, + { + "name": "gelu float32 2D tensor", + "inputs": { + "input": { + "shape": [ + 4, + 6 + ], + "data": [ + 0.878292441368103, + -0.09706497937440872, + 0.1367187649011612, + 0.46406492590904236, + -0.26635801792144775, + -0.8252315521240234, + 0.8530909419059753, + 0.3846154808998108, + 0.6772316694259644, + -0.4811072051525116, + 0.2983909249305725, + 0.6777864098548889, + -0.526228129863739, + 0.3497541546821594, + -0.12918996810913086, + 0.5853934288024902, + -0.8950720429420471, + 0.028302494436502457, + -0.09901237487792969, + -0.8838679790496826, + -0.596120297908783, + 0.31863871216773987, + 0.4794037640094757, + -0.06489315629005432 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 4, + 6 + ], + "data": [ + 0.7115113139152527, + -0.0447796992957592, + 0.07579325884580612, + 0.3149605691432953, + -0.10520657151937485, + -0.16885890066623688, + 0.6851989030838013, + 0.24989959597587585, + 0.508513331413269, + -0.1516546905040741, + 0.18419598042964935, + 0.509049117565155, + -0.15753419697284698, + 0.22270187735557556, + -0.05795508995652199, + 0.42198580503463745, + -0.1659233123064041, + 0.014470770955085754, + -0.04560155048966408, + -0.1665063202381134, + -0.1642593890428543, + 0.19914908707141876, + 0.3279957175254822, + -0.030767757445573807 + ], + "type": "float32" + } + }, + { + "name": "gelu float16 2D tensor", + "inputs": { + "input": { + "shape": [ + 4, + 6 + ], + "data": [ + 0.87841796875, + -0.0970458984375, + 0.13671875, + 0.464111328125, + -0.266357421875, + -0.8251953125, + 0.85302734375, + 0.384521484375, + 0.67724609375, + -0.481201171875, + 0.29833984375, + 0.677734375, + -0.5263671875, + 0.349853515625, + -0.129150390625, + 0.58544921875, + -0.89501953125, + 0.0283050537109375, + -0.0989990234375, + -0.8837890625, + -0.59619140625, + 0.318603515625, + 0.4794921875, + -0.06488037109375 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 4, + 6 + ], + "data": [ + 0.71142578125, + -0.044769287109375, + 0.0758056640625, + 0.31494140625, + -0.105224609375, + -0.1688232421875, + 0.68505859375, + 0.2498779296875, + 0.50830078125, + -0.151611328125, + 0.1842041015625, + 0.5087890625, + -0.1575927734375, + 0.2227783203125, + -0.057952880859375, + 0.422119140625, + -0.1658935546875, + 0.01447296142578125, + -0.04559326171875, + -0.16650390625, + -0.164306640625, + 0.1990966796875, + 0.328125, + -0.03076171875 + ], + "type": "float16" + } + }, + { + "name": "gelu float32 3D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 3, + 4 + ], + "data": [ + 0.878292441368103, + -0.09706497937440872, + 0.1367187649011612, + 0.46406492590904236, + -0.26635801792144775, + -0.8252315521240234, + 0.8530909419059753, + 0.3846154808998108, + 0.6772316694259644, + -0.4811072051525116, + 0.2983909249305725, + 0.6777864098548889, + -0.526228129863739, + 0.3497541546821594, + -0.12918996810913086, + 0.5853934288024902, + -0.8950720429420471, + 0.028302494436502457, + -0.09901237487792969, + -0.8838679790496826, + -0.596120297908783, + 0.31863871216773987, + 0.4794037640094757, + -0.06489315629005432 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 3, + 4 + ], + "data": [ + 0.7115113139152527, + -0.0447796992957592, + 0.07579325884580612, + 0.3149605691432953, + -0.10520657151937485, + -0.16885890066623688, + 0.6851989030838013, + 0.24989959597587585, + 0.508513331413269, + -0.1516546905040741, + 0.18419598042964935, + 0.509049117565155, + -0.15753419697284698, + 0.22270187735557556, + -0.05795508995652199, + 0.42198580503463745, + -0.1659233123064041, + 0.014470770955085754, + -0.04560155048966408, + -0.1665063202381134, + -0.1642593890428543, + 0.19914908707141876, + 0.3279957175254822, + -0.030767757445573807 + ], + "type": "float32" + } + }, + { + "name": "gelu float16 3D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 3, + 4 + ], + "data": [ + 0.87841796875, + -0.0970458984375, + 0.13671875, + 0.464111328125, + -0.266357421875, + -0.8251953125, + 0.85302734375, + 0.384521484375, + 0.67724609375, + -0.481201171875, + 0.29833984375, + 0.677734375, + -0.5263671875, + 0.349853515625, + -0.129150390625, + 0.58544921875, + -0.89501953125, + 0.0283050537109375, + -0.0989990234375, + -0.8837890625, + -0.59619140625, + 0.318603515625, + 0.4794921875, + -0.06488037109375 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 3, + 4 + ], + "data": [ + 0.71142578125, + -0.044769287109375, + 0.0758056640625, + 0.31494140625, + -0.105224609375, + -0.1688232421875, + 0.68505859375, + 0.2498779296875, + 0.50830078125, + -0.151611328125, + 0.1842041015625, + 0.5087890625, + -0.1575927734375, + 0.2227783203125, + -0.057952880859375, + 0.422119140625, + -0.1658935546875, + 0.01447296142578125, + -0.04559326171875, + -0.16650390625, + -0.164306640625, + 0.1990966796875, + 0.328125, + -0.03076171875 + ], + "type": "float16" + } + }, + { + "name": "gelu float32 4D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 2, + 2, + 3 + ], + "data": [ + 0.878292441368103, + -0.09706497937440872, + 0.1367187649011612, + 0.46406492590904236, + -0.26635801792144775, + -0.8252315521240234, + 0.8530909419059753, + 0.3846154808998108, + 0.6772316694259644, + -0.4811072051525116, + 0.2983909249305725, + 0.6777864098548889, + -0.526228129863739, + 0.3497541546821594, + -0.12918996810913086, + 0.5853934288024902, + -0.8950720429420471, + 0.028302494436502457, + -0.09901237487792969, + -0.8838679790496826, + -0.596120297908783, + 0.31863871216773987, + 0.4794037640094757, + -0.06489315629005432 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 2, + 2, + 3 + ], + "data": [ + 0.7115113139152527, + -0.0447796992957592, + 0.07579325884580612, + 0.3149605691432953, + -0.10520657151937485, + -0.16885890066623688, + 0.6851989030838013, + 0.24989959597587585, + 0.508513331413269, + -0.1516546905040741, + 0.18419598042964935, + 0.509049117565155, + -0.15753419697284698, + 0.22270187735557556, + -0.05795508995652199, + 0.42198580503463745, + -0.1659233123064041, + 0.014470770955085754, + -0.04560155048966408, + -0.1665063202381134, + -0.1642593890428543, + 0.19914908707141876, + 0.3279957175254822, + -0.030767757445573807 + ], + "type": "float32" + } + }, + { + "name": "gelu float16 4D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 2, + 2, + 3 + ], + "data": [ + 0.87841796875, + -0.0970458984375, + 0.13671875, + 0.464111328125, + -0.266357421875, + -0.8251953125, + 0.85302734375, + 0.384521484375, + 0.67724609375, + -0.481201171875, + 0.29833984375, + 0.677734375, + -0.5263671875, + 0.349853515625, + -0.129150390625, + 0.58544921875, + -0.89501953125, + 0.0283050537109375, + -0.0989990234375, + -0.8837890625, + -0.59619140625, + 0.318603515625, + 0.4794921875, + -0.06488037109375 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 2, + 2, + 3 + ], + "data": [ + 0.71142578125, + -0.044769287109375, + 0.0758056640625, + 0.31494140625, + -0.105224609375, + -0.1688232421875, + 0.68505859375, + 0.2498779296875, + 0.50830078125, + -0.151611328125, + 0.1842041015625, + 0.5087890625, + -0.1575927734375, + 0.2227783203125, + -0.057952880859375, + 0.422119140625, + -0.1658935546875, + 0.01447296142578125, + -0.04559326171875, + -0.16650390625, + -0.164306640625, + 0.1990966796875, + 0.328125, + -0.03076171875 + ], + "type": "float16" + } + }, + { + "name": "gelu float32 5D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 1, + 4, + 1, + 3 + ], + "data": [ + 0.878292441368103, + -0.09706497937440872, + 0.1367187649011612, + 0.46406492590904236, + -0.26635801792144775, + -0.8252315521240234, + 0.8530909419059753, + 0.3846154808998108, + 0.6772316694259644, + -0.4811072051525116, + 0.2983909249305725, + 0.6777864098548889, + -0.526228129863739, + 0.3497541546821594, + -0.12918996810913086, + 0.5853934288024902, + -0.8950720429420471, + 0.028302494436502457, + -0.09901237487792969, + -0.8838679790496826, + -0.596120297908783, + 0.31863871216773987, + 0.4794037640094757, + -0.06489315629005432 + ], + "type": "float32" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 1, + 4, + 1, + 3 + ], + "data": [ + 0.7115113139152527, + -0.0447796992957592, + 0.07579325884580612, + 0.3149605691432953, + -0.10520657151937485, + -0.16885890066623688, + 0.6851989030838013, + 0.24989959597587585, + 0.508513331413269, + -0.1516546905040741, + 0.18419598042964935, + 0.509049117565155, + -0.15753419697284698, + 0.22270187735557556, + -0.05795508995652199, + 0.42198580503463745, + -0.1659233123064041, + 0.014470770955085754, + -0.04560155048966408, + -0.1665063202381134, + -0.1642593890428543, + 0.19914908707141876, + 0.3279957175254822, + -0.030767757445573807 + ], + "type": "float32" + } + }, + { + "name": "gelu float16 5D tensor", + "inputs": { + "input": { + "shape": [ + 2, + 1, + 4, + 1, + 3 + ], + "data": [ + 0.87841796875, + -0.0970458984375, + 0.13671875, + 0.464111328125, + -0.266357421875, + -0.8251953125, + 0.85302734375, + 0.384521484375, + 0.67724609375, + -0.481201171875, + 0.29833984375, + 0.677734375, + -0.5263671875, + 0.349853515625, + -0.129150390625, + 0.58544921875, + -0.89501953125, + 0.0283050537109375, + -0.0989990234375, + -0.8837890625, + -0.59619140625, + 0.318603515625, + 0.4794921875, + -0.06488037109375 + ], + "type": "float16" + } + }, + "expected": { + "name": "output", + "shape": [ + 2, + 1, + 4, + 1, + 3 + ], + "data": [ + 0.71142578125, + -0.044769287109375, + 0.0758056640625, + 0.31494140625, + -0.105224609375, + -0.1688232421875, + 0.68505859375, + 0.2498779296875, + 0.50830078125, + -0.151611328125, + 0.1842041015625, + 0.5087890625, + -0.1575927734375, + 0.2227783203125, + -0.057952880859375, + 0.422119140625, + -0.1658935546875, + 0.01447296142578125, + -0.04559326171875, + -0.16650390625, + -0.164306640625, + 0.1990966796875, + 0.328125, + -0.03076171875 + ], + "type": "float16" + } + } + ] +} \ No newline at end of file diff --git a/test/tools/test-data/gelu-data.json b/test/tools/test-data/gelu-data.json new file mode 100644 index 0000000..534f2bf --- /dev/null +++ b/test/tools/test-data/gelu-data.json @@ -0,0 +1,93 @@ +{ + "inputsData": { + "float64DataScalar": [ + -0.044885845624167864 + ], + "float64Data": [ + 0.8782924345704477, + -0.09706497776701806, + 0.1367187672039556, + 0.46406491981662557, + -0.26635802629759375, + -0.8252315662130498, + 0.853090918197347, + 0.3846154905320942, + 0.6772316793454944, + -0.4811071995656535, + 0.29839091278502794, + 0.6777863973820542, + -0.5262281183797937, + 0.3497541608592383, + -0.12918996895751977, + 0.5853934375200058, + -0.8950720643968815, + 0.028302494550672908, + -0.0990123770792839, + -0.8838679808470014, + -0.5961202846499938, + 0.3186387025271662, + 0.4794037697361717, + -0.06489315429048403 + ] + }, + "expectedData": { + "float32DataScalar": [ + -0.021639423444867134 + ], + "float16DataScalar": [ + -0.021636962890625 + ], + "float32Data": [ + 0.7115113139152527, + -0.0447796992957592, + 0.07579325884580612, + 0.3149605691432953, + -0.10520657151937485, + -0.16885890066623688, + 0.6851989030838013, + 0.24989959597587585, + 0.508513331413269, + -0.1516546905040741, + 0.18419598042964935, + 0.509049117565155, + -0.15753419697284698, + 0.22270187735557556, + -0.05795508995652199, + 0.42198580503463745, + -0.1659233123064041, + 0.014470770955085754, + -0.04560155048966408, + -0.1665063202381134, + -0.1642593890428543, + 0.19914908707141876, + 0.3279957175254822, + -0.030767757445573807 + ], + "float16Data": [ + 0.71142578125, + -0.044769287109375, + 0.0758056640625, + 0.31494140625, + -0.105224609375, + -0.1688232421875, + 0.68505859375, + 0.2498779296875, + 0.50830078125, + -0.151611328125, + 0.1842041015625, + 0.5087890625, + -0.1575927734375, + 0.2227783203125, + -0.057952880859375, + 0.422119140625, + -0.1658935546875, + 0.01447296142578125, + -0.04559326171875, + -0.16650390625, + -0.164306640625, + 0.1990966796875, + 0.328125, + -0.03076171875 + ] + } +} \ No newline at end of file From 0496091437fe57c2cf70f7165ad7d6596ecefb6f Mon Sep 17 00:00:00 2001 From: BruceDai Date: Wed, 29 May 2024 15:58:01 +0800 Subject: [PATCH 4/5] Update baseline data as float32 from original float64 for softsign tests --- test/tools/test-data-wpt/softsign.json | 576 ++++++++++++------------- 1 file changed, 288 insertions(+), 288 deletions(-) diff --git a/test/tools/test-data-wpt/softsign.json b/test/tools/test-data-wpt/softsign.json index 31df44d..e185e3d 100644 --- a/test/tools/test-data-wpt/softsign.json +++ b/test/tools/test-data-wpt/softsign.json @@ -8,30 +8,30 @@ 24 ], "data": [ - 1.5834133593790956, - 4.0787189411490115, - 8.883356617490337, - 8.070860233252166, - 8.211773633019915, - 2.4554003891197818, - 0.653374178120758, - 7.866281154604682, - 3.1239552336192666, - 8.013792390668268, - 3.9409862749371283, - 1.8131727337833081, - 2.390676102273188, - 1.3359680092645565, - 9.416410839467265, - 0.44325690899325254, - 5.236662013213598, - 9.424242359034539, - 7.816190418459348, - 5.849185795081855, - 8.780370640491928, - 5.1205157788312246, - 7.1172223514005095, - 4.59910661262345 + 1.5834133625030518, + 4.078719139099121, + 8.883357048034668, + 8.070859909057617, + 8.211773872375488, + 2.4554004669189453, + 0.653374195098877, + 7.866281032562256, + 3.123955249786377, + 8.013792037963867, + 3.940986156463623, + 1.813172698020935, + 2.3906760215759277, + 1.335968017578125, + 9.416410446166992, + 0.4432569146156311, + 5.236661911010742, + 9.42424201965332, + 7.816190242767334, + 5.849185943603516, + 8.780370712280273, + 5.120515823364258, + 7.117222309112549, + 4.599106788635254 ], "type": "float32" } @@ -78,30 +78,30 @@ 24 ], "data": [ - -2.5978440095516913, - -0.4449555447737712, - -9.095475232407683, - -3.7480076975512873, - -1.3867289790255697, - -8.220328902868987, - -3.538342320320556, - -9.364588742025619, - -6.283252341501335, - -5.0020120266550006, - -8.245729151019969, - -3.775470497728266, - -4.087254829132392, - -7.3816760861585795, - -5.882921529710956, - -8.338910337100263, - -6.6015492897072185, - -4.491942000901396, - -3.524778486355298, - -4.439912258765581, - -5.2342625634221225, - -1.5911732471016933, - -9.106277545690418, - -8.523774275382141 + -2.597844123840332, + -0.4449555575847626, + -9.095475196838379, + -3.7480077743530273, + -1.3867290019989014, + -8.220329284667969, + -3.538342237472534, + -9.364588737487793, + -6.283252239227295, + -5.002012252807617, + -8.245729446411133, + -3.775470495223999, + -4.087255001068115, + -7.381676197052002, + -5.8829216957092285, + -8.338910102844238, + -6.60154914855957, + -4.491941928863525, + -3.5247786045074463, + -4.43991231918335, + -5.234262466430664, + -1.5911732912063599, + -9.106277465820312, + -8.523774147033691 ], "type": "float32" } @@ -149,30 +149,30 @@ 6 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.343496322631836, + -6.920152187347412, + 2.699638843536377, + -8.663105010986328, + -3.1905343532562256, + 7.657886981964111, + 6.650215148925781, + 6.058011054992676, + 0.6634320616722107, + 5.8058037757873535, + -0.32821124792099, + 1.2704304456710815, + -9.946120262145996, + 6.905375003814697, + -0.031071536242961884, + -3.9696409702301025, + 6.270823001861572, + -2.639260768890381, + 3.0513505935668945, + 7.426476955413818, + -8.454667091369629, + 7.135868072509766, + -4.986093997955322, + -7.859614849090576 ], "type": "float32" } @@ -222,30 +222,30 @@ 4 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.343496322631836, + -6.920152187347412, + 2.699638843536377, + -8.663105010986328, + -3.1905343532562256, + 7.657886981964111, + 6.650215148925781, + 6.058011054992676, + 0.6634320616722107, + 5.8058037757873535, + -0.32821124792099, + 1.2704304456710815, + -9.946120262145996, + 6.905375003814697, + -0.031071536242961884, + -3.9696409702301025, + 6.270823001861572, + -2.639260768890381, + 3.0513505935668945, + 7.426476955413818, + -8.454667091369629, + 7.135868072509766, + -4.986093997955322, + -7.859614849090576 ], "type": "float32" } @@ -297,30 +297,30 @@ 4 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.343496322631836, + -6.920152187347412, + 2.699638843536377, + -8.663105010986328, + -3.1905343532562256, + 7.657886981964111, + 6.650215148925781, + 6.058011054992676, + 0.6634320616722107, + 5.8058037757873535, + -0.32821124792099, + 1.2704304456710815, + -9.946120262145996, + 6.905375003814697, + -0.031071536242961884, + -3.9696409702301025, + 6.270823001861572, + -2.639260768890381, + 3.0513505935668945, + 7.426476955413818, + -8.454667091369629, + 7.135868072509766, + -4.986093997955322, + -7.859614849090576 ], "type": "float32" } @@ -374,30 +374,30 @@ 4 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.343496322631836, + -6.920152187347412, + 2.699638843536377, + -8.663105010986328, + -3.1905343532562256, + 7.657886981964111, + 6.650215148925781, + 6.058011054992676, + 0.6634320616722107, + 5.8058037757873535, + -0.32821124792099, + 1.2704304456710815, + -9.946120262145996, + 6.905375003814697, + -0.031071536242961884, + -3.9696409702301025, + 6.270823001861572, + -2.639260768890381, + 3.0513505935668945, + 7.426476955413818, + -8.454667091369629, + 7.135868072509766, + -4.986093997955322, + -7.859614849090576 ], "type": "float32" } @@ -448,30 +448,30 @@ 24 ], "data": [ - 1.5834133593790956, - 4.0787189411490115, - 8.883356617490337, - 8.070860233252166, - 8.211773633019915, - 2.4554003891197818, - 0.653374178120758, - 7.866281154604682, - 3.1239552336192666, - 8.013792390668268, - 3.9409862749371283, - 1.8131727337833081, - 2.390676102273188, - 1.3359680092645565, - 9.416410839467265, - 0.44325690899325254, - 5.236662013213598, - 9.424242359034539, - 7.816190418459348, - 5.849185795081855, - 8.780370640491928, - 5.1205157788312246, - 7.1172223514005095, - 4.59910661262345 + 1.5830078125, + 4.078125, + 8.8828125, + 8.0703125, + 8.2109375, + 2.455078125, + 0.6533203125, + 7.8671875, + 3.123046875, + 8.015625, + 3.94140625, + 1.8134765625, + 2.390625, + 1.3359375, + 9.4140625, + 0.443359375, + 5.23828125, + 9.421875, + 7.81640625, + 5.84765625, + 8.78125, + 5.12109375, + 7.1171875, + 4.59765625 ], "type": "float16" } @@ -518,30 +518,30 @@ 24 ], "data": [ - -2.5978440095516913, - -0.4449555447737712, - -9.095475232407683, - -3.7480076975512873, - -1.3867289790255697, - -8.220328902868987, - -3.538342320320556, - -9.364588742025619, - -6.283252341501335, - -5.0020120266550006, - -8.245729151019969, - -3.775470497728266, - -4.087254829132392, - -7.3816760861585795, - -5.882921529710956, - -8.338910337100263, - -6.6015492897072185, - -4.491942000901396, - -3.524778486355298, - -4.439912258765581, - -5.2342625634221225, - -1.5911732471016933, - -9.106277545690418, - -8.523774275382141 + -2.59765625, + -0.445068359375, + -9.09375, + -3.748046875, + -1.38671875, + -8.21875, + -3.5390625, + -9.3671875, + -6.28515625, + -5.00390625, + -8.2421875, + -3.775390625, + -4.0859375, + -7.3828125, + -5.8828125, + -8.3359375, + -6.6015625, + -4.4921875, + -3.525390625, + -4.44140625, + -5.234375, + -1.5908203125, + -9.109375, + -8.5234375 ], "type": "float16" } @@ -589,30 +589,30 @@ 6 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.34375, + -6.921875, + 2.69921875, + -8.6640625, + -3.19140625, + 7.65625, + 6.6484375, + 6.05859375, + 0.66357421875, + 5.8046875, + -0.328125, + 1.2705078125, + -9.9453125, + 6.90625, + -0.03106689453125, + -3.96875, + 6.26953125, + -2.638671875, + 3.05078125, + 7.42578125, + -8.453125, + 7.13671875, + -4.984375, + -7.859375 ], "type": "float16" } @@ -662,30 +662,30 @@ 4 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.34375, + -6.921875, + 2.69921875, + -8.6640625, + -3.19140625, + 7.65625, + 6.6484375, + 6.05859375, + 0.66357421875, + 5.8046875, + -0.328125, + 1.2705078125, + -9.9453125, + 6.90625, + -0.03106689453125, + -3.96875, + 6.26953125, + -2.638671875, + 3.05078125, + 7.42578125, + -8.453125, + 7.13671875, + -4.984375, + -7.859375 ], "type": "float16" } @@ -737,30 +737,30 @@ 4 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.34375, + -6.921875, + 2.69921875, + -8.6640625, + -3.19140625, + 7.65625, + 6.6484375, + 6.05859375, + 0.66357421875, + 5.8046875, + -0.328125, + 1.2705078125, + -9.9453125, + 6.90625, + -0.03106689453125, + -3.96875, + 6.26953125, + -2.638671875, + 3.05078125, + 7.42578125, + -8.453125, + 7.13671875, + -4.984375, + -7.859375 ], "type": "float16" } @@ -814,30 +814,30 @@ 4 ], "data": [ - -8.343496173533422, - -6.92015211612679, - 2.699638761922575, - -8.663104577031863, - -3.190534368785616, - 7.657887080586452, - 6.650215091182602, - 6.058011004380681, - 0.6634320403254037, - 5.805803683155526, - -0.32821124531446344, - 1.270430403469046, - -9.946119978610852, - 6.905375202832072, - -0.031071535439890496, - -3.9696409293645862, - 6.270823207970878, - -2.6392608577007914, - 3.051350503137261, - 7.42647683445869, - -8.454667518154086, - 7.135868292466057, - -4.9860941550065885, - -7.859615086397076 + -8.34375, + -6.921875, + 2.69921875, + -8.6640625, + -3.19140625, + 7.65625, + 6.6484375, + 6.05859375, + 0.66357421875, + 5.8046875, + -0.328125, + 1.2705078125, + -9.9453125, + 6.90625, + -0.03106689453125, + -3.96875, + 6.26953125, + -2.638671875, + 3.05078125, + 7.42578125, + -8.453125, + 7.13671875, + -4.984375, + -7.859375 ], "type": "float16" } From 6741480382caa3902acab96c0bc9cab0d5eba921 Mon Sep 17 00:00:00 2001 From: BruceDai Date: Wed, 29 May 2024 16:08:37 +0800 Subject: [PATCH 5/5] Update README --- test/tools/README.md | 49 ++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/test/tools/README.md b/test/tools/README.md index 2fc620d..b4058d5 100644 --- a/test/tools/README.md +++ b/test/tools/README.md @@ -1,23 +1,28 @@ -How to generate test-data file for WPT tests? - -Step 1: Please prepare resources JSON file which includes those tests -to test each operator of WebNN API without specified inputs and outputs -data. - -Step 2: Implement generate test-data scripts - -Step 3: Execute command for generating test-data files for WPT tests - -```shell -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 -./test-data/softsign-data.json, -and raw WPT test-data file as being ./test-data-wpt/softsign.json. - - -You can manually modify some test data in -./test-data/softsign-data.json, +How to generate test-data file for WPT tests? + +Step 1: Please prepare resources JSON file which includes those tests +to test each operator of WebNN API without specified inputs and outputs +data. + +Step 2: Implement generate test-data scripts + +Step 3: Execute command for generating test-data files for WPT tests. +```shell +node gen-operator-with-single-input.js resources\.json +``` + +Take an example for softsign operator tests: + +```shell +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 +./test-data/softsign-data.json, +and raw WPT test-data file as being ./test-data-wpt/softsign.json. + + +You can manually modify some test data in +./test-data/softsign-data.json, then execute Step 3, to update ./test-data-wpt/softsign.json. \ No newline at end of file