From 3e8dbe5e900289daf9272ea8643b345682c805f5 Mon Sep 17 00:00:00 2001 From: Satya Jandhyala Date: Mon, 5 Aug 2024 15:44:43 -0700 Subject: [PATCH] Added DequantizeLinear JSONC op test. --- .../wasm/jsep/webgpu/ops/quantize_linear.ts | 4 +- js/web/test/data/ops/dequantizelinear.jsonc | 156 ++++++++++++++++++ js/web/test/suite-test-list.jsonc | 1 + 3 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 js/web/test/data/ops/dequantizelinear.jsonc diff --git a/js/web/lib/wasm/jsep/webgpu/ops/quantize_linear.ts b/js/web/lib/wasm/jsep/webgpu/ops/quantize_linear.ts index ae7b71c096763..87c1893f788cf 100644 --- a/js/web/lib/wasm/jsep/webgpu/ops/quantize_linear.ts +++ b/js/web/lib/wasm/jsep/webgpu/ops/quantize_linear.ts @@ -50,7 +50,9 @@ const validateInputs = (inputs: readonly TensorView[], attributes: DequantizeLin if (inputs[1].dims.length === 0 || (inputs[1].dims.length === 1 && inputs[1].dims[0] === 1)) { throw new Error('blockSize must be set only for block quantization.'); } - if (!inputs[1].dims.map((d, i) => i === attributes.axis || d === inputs[0].dims[i]).reduce((a, b) => a && b, true)) { + if (!inputs[1] + .dims.map((d, i) => i === attributes.axis || d === inputs[0].dims[i]) + .reduce((a, b) => a && b, true)) { throw new Error('For block qunatization, scale input shape to match the input shape except for the axis') } // Scale input rank should be same as the input rank diff --git a/js/web/test/data/ops/dequantizelinear.jsonc b/js/web/test/data/ops/dequantizelinear.jsonc new file mode 100644 index 0000000000000..383afe1e244fb --- /dev/null +++ b/js/web/test/data/ops/dequantizelinear.jsonc @@ -0,0 +1,156 @@ +[ + { + "name": "dequantizelinear", + "operator": "DequantizeLinear", + "attributes": [], + "cases": [ + { + "name": "T[4]", + "inputs": [ + { + "data": [1, 2, 3, 4], + "dims": [4], + "type": "uint8" + }, + { + "data": [0.1], + "dims": [1], + "type": "float32" + }, + { + "data": [0.0], + "dims": [1], + "type": "uint8" + } + ], + "outputs": [ + { + "data": [0.1, 0.2, 0.3, 0.4], + "dims": [4], + "type": "float32" + } + ] + } + ] + }, + { + "name": "dequantizelinear", + "operator": "DequantizeLinear", + "attributes": [ + { + "name": "axis", + "data": 1, + "type": "int" + } + ], + "cases": [ + { + "name": "T[2,2]", + "inputs": [ + { + "data": [1, 2, 3, 4], + "dims": [2, 2], + "type": "uint8" + }, + { + "data": [0.1], + "dims": [1], + "type": "float32" + }, + { + "data": [0.0], + "dims": [1], + "type": "uint8" + } + ], + "outputs": [ + { + "data": [0.1, 0.2, 0.3, 0.4], + "dims": [2, 2], + "type": "float32" + } + ] + } + ] + }, + { + "name": "dequantizelinear", + "operator": "DequantizeLinear", + "attributes": [ + { + "name": "axis", + "data": 1, + "type": "int" + } + ], + "cases": [ + { + "name": "T[2, 2, 2]", + "inputs": [ + { + "data": [1, 2, 3, 4, 5, 6, 7, 8], + "dims": [2, 2, 2], + "type": "uint8" + }, + { + "data": [0.1, 0.1], + "dims": [2], + "type": "float32" + }, + { + "data": [0.0, 0.0], + "dims": [2], + "type": "uint8" + } + ], + "outputs": [ + { + "data": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], + "dims": [2, 2, 2], + "type": "float32" + } + ] + } + ] + }, + { + "name": "dequantizelinear", + "operator": "DequantizeLinear", + "attributes": [ + { + "name": "axis", + "data": 1, + "type": "int" + } + ], + "cases": [ + { + "name": "T[2, 2, 2]", + "inputs": [ + { + "data": [1, 2, 3, 4, 5, 6, 7, 8], + "dims": [2, 2, 2], + "type": "uint8" + }, + { + "data": [0.1], + "dims": [1], + "type": "float32" + }, + { + "data": [0.0], + "dims": [1], + "type": "uint8" + } + ], + "outputs": [ + { + "data": [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8], + "dims": [2, 2, 2], + "type": "float32" + } + ] + } + ] + } +] diff --git a/js/web/test/suite-test-list.jsonc b/js/web/test/suite-test-list.jsonc index baff2afa5b7bc..ede89f7557dd8 100644 --- a/js/web/test/suite-test-list.jsonc +++ b/js/web/test/suite-test-list.jsonc @@ -1352,6 +1352,7 @@ "div.jsonc", "div_int32.jsonc", "depth-to-space.jsonc", + "dequantizelinear.jsonc", "equal.jsonc", "exp.jsonc", "expand.jsonc",