From 655c301a6e25ca6593948e238f6b48ccfc4ea009 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Sat, 16 Nov 2024 02:04:38 +0000 Subject: [PATCH] Bug 1930286 [wpt PR 49083] - webnn: Support block-wise quantization for DirectML backend, a=testonly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automatic update from web-platform-tests webnn: Support block-wise quantization for DirectML backend Block-wise quantization divides input tensors into smaller blocks that are independently quantized, resulting in faster optimization and high precision quantization [1]. It is used for popular language models, such as phi-3 mini int4 quantized model [2]. Related WG issue [3] has been opened to discussion. Firstly, this CL validates scale and zero point tensors for block-wise quantization. Besides, this CL also implements the block-wise quantization in DirectML backend by using DML_OPERATOR_QUANTIZE and DML_OPERATOR_DEQUANTIZE which are available in FL >= 6.3. More validation and conformance tests are added to verify the implementation. [1]: https://arxiv.org/abs/2110.02861 [2]: https://huggingface.co/microsoft/Phi-3-mini-4k-instruct [3]: https://github.com/webmachinelearning/webnn/issues/779 Bug: 40206287 Change-Id: I977b0be57deebd7afcae216edc3ddc3818b8c09f Cq-Include-Trybots: luci.chromium.try​:mac14.arm64-blink-rel, mac14-blink-rel, mac15.arm64-blink-rel, mac15-blink-rel, linux-blink-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5964816 Reviewed-by: Rafael Cintron Reviewed-by: ningxin hu Commit-Queue: ningxin hu Cr-Commit-Position: refs/heads/main{#1380767} -- wpt-commits: 8686b7a6d288d3b2c22b5ddb5a21773619b22b85 wpt-pr: 49083 UltraBlame original commit: 6b8a19bf1f5562bfae60549575af9c2b422b4975 --- .../dequantizeLinear.https.any.js | 1073 ++++++++++++-- .../quantizeLinear.https.any.js | 1285 +++++++++++++++-- .../dequantizeLinear.https.any.js | 118 +- .../quantizeLinear.https.any.js | 115 +- 4 files changed, 2350 insertions(+), 241 deletions(-) diff --git a/testing/web-platform/tests/webnn/conformance_tests/dequantizeLinear.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/dequantizeLinear.https.any.js index e188cc2f51b1..c6fbfd28da4c 100644 --- a/testing/web-platform/tests/webnn/conformance_tests/dequantizeLinear.https.any.js +++ b/testing/web-platform/tests/webnn/conformance_tests/dequantizeLinear.https.any.js @@ -605,6 +605,797 @@ data : [ 128 +128 +128 +128 +] +' +descriptor +' +: +{ +shape +: +[ +4 +] +dataType +: +' +uint8 +' +} +' +constant +' +: +true +} +} +' +operators +' +: +[ +{ +' +name +' +: +' +dequantizeLinear +' +' +arguments +' +: +[ +{ +' +input +' +: +' +dequantizeLinearInput +' +} +{ +' +scale +' +: +' +dequantizeLinearScale +' +} +{ +' +zeroPoint +' +: +' +dequantizeLinearZeroPoint +' +} +] +' +outputs +' +: +' +dequantizeLinearOutput +' +} +] +' +expectedOutputs +' +: +{ +' +dequantizeLinearOutput +' +: +{ +' +data +' +: +[ +- +1083 +. +798828125 +- +29 +. +127147674560547 +429 +. +388916015625 +- +5 +. +601373672485352 +] +' +descriptor +' +: +{ +shape +: +[ +4 +] +dataType +: +' +float32 +' +} +} +} +} +} +{ +' +name +' +: +' +dequantizeLinear +uint8 +1D +constant +tensor +with +implicit +block_size += +2 +. +' +' +graph +' +: +{ +' +inputs +' +: +{ +' +dequantizeLinearInput +' +: +{ +' +data +' +: +[ +12 +24 +35 +123 +] +' +descriptor +' +: +{ +shape +: +[ +4 +] +dataType +: +' +uint8 +' +} +' +constant +' +: +true +} +' +dequantizeLinearScale +' +: +{ +' +data +' +: +[ +9 +. +343092918395996 +- +4 +. +617084980010986 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +dequantizeLinearZeroPoint +' +: +{ +' +data +' +: +[ +128 +110 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +uint8 +' +} +' +constant +' +: +true +} +} +' +operators +' +: +[ +{ +' +name +' +: +' +dequantizeLinear +' +' +arguments +' +: +[ +{ +' +input +' +: +' +dequantizeLinearInput +' +} +{ +' +scale +' +: +' +dequantizeLinearScale +' +} +{ +' +zeroPoint +' +: +' +dequantizeLinearZeroPoint +' +} +] +' +outputs +' +: +' +dequantizeLinearOutput +' +} +] +' +expectedOutputs +' +: +{ +' +dequantizeLinearOutput +' +: +{ +' +data +' +: +[ +- +1083 +. +798828125 +- +971 +. +681640625 +346 +. +2813720703125 +- +60 +. +0221061706543 +] +' +descriptor +' +: +{ +shape +: +[ +4 +] +dataType +: +' +float32 +' +} +} +} +} +} +{ +' +name +' +: +' +dequantizeLinear +int8 +4D +constant +tensor +broadcasting +scale +and +zeroPoint +' +' +graph +' +: +{ +' +inputs +' +: +{ +' +dequantizeLinearInput +' +: +{ +' +data +' +: +[ +- +124 +0 +23 +122 +] +' +descriptor +' +: +{ +shape +: +[ +1 +1 +2 +2 +] +dataType +: +' +int8 +' +} +' +constant +' +: +true +} +' +dequantizeLinearScale +' +: +{ +' +data +' +: +[ +0 +. +2800687253475189 +- +4 +. +617084980010986 +] +' +descriptor +' +: +{ +shape +: +[ +2 +1 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +dequantizeLinearZeroPoint +' +: +{ +' +data +' +: +[ +12 +12 +] +' +descriptor +' +: +{ +shape +: +[ +2 +1 +] +dataType +: +' +int8 +' +} +' +constant +' +: +true +} +} +' +operators +' +: +[ +{ +' +name +' +: +' +dequantizeLinear +' +' +arguments +' +: +[ +{ +' +input +' +: +' +dequantizeLinearInput +' +} +{ +' +scale +' +: +' +dequantizeLinearScale +' +} +{ +' +zeroPoint +' +: +' +dequantizeLinearZeroPoint +' +} +] +' +outputs +' +: +' +dequantizeLinearOutput +' +} +] +' +expectedOutputs +' +: +{ +' +dequantizeLinearOutput +' +: +{ +' +data +' +: +[ +- +38 +. +08934783935547 +- +3 +. +3608245849609375 +- +50 +. +787933349609375 +- +507 +. +87933349609375 +] +' +descriptor +' +: +{ +shape +: +[ +1 +1 +2 +2 +] +dataType +: +' +float32 +' +} +} +} +} +} +{ +' +name +' +: +' +dequantizeLinear +int8 +4D +constant +tensor +with +block_size += +[ +3 +2 +] +' +' +graph +' +: +{ +' +inputs +' +: +{ +' +dequantizeLinearInput +' +: +{ +' +data +' +: +[ +- +124 +0 +23 +122 +12 +23 +45 +36 +67 +78 +- +22 +0 +- +34 +- +45 +- +56 +- +67 +89 +30 +12 +23 +56 +67 +56 +- +12 +] +' +descriptor +' +: +{ +shape +: +[ +6 +4 +] +dataType +: +' +int8 +' +} +' +constant +' +: +true +} +' +dequantizeLinearScale +' +: +{ +' +data +' +: +[ +0 +. +2800687253475189 +- +4 +. +617084980010986 +1 +. +2800687253475189 +- +3 +. +617084980010986 +] +' +descriptor +' +: +{ +shape +: +[ +2 +2 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +dequantizeLinearZeroPoint +' +: +{ +' +data +' +: +[ +1 +3 +5 +12 ] ' descriptor @@ -614,11 +1405,13 @@ descriptor shape : [ +2 +2 ] dataType : ' -uint8 +int8 ' } ' @@ -699,20 +1492,85 @@ data : [ - -1083 +35 . -798828125 +00859069824219 - -29 +0 . -127147674560547 -429 +2800687253475189 +- +92 . -388916015625 +3416976928711 - -5 +549 . -601373672485352 +43310546875 +3 +. +0807559490203857 +6 +. +1615118980407715 +- +193 +. +91757202148438 +- +152 +. +36380004882812 +18 +. +484535217285156 +21 +. +565292358398438 +115 +. +4271240234375 +13 +. +851255416870117 +- +49 +. +92267990112305 +- +64 +. +0034408569336 +245 +. +96177673339844 +285 +. +7497253417969 +107 +. +52577209472656 +32 +. +0017204284668 +0 +- +39 +. +787933349609375 +65 +. +28350830078125 +79 +. +36426544189453 +- +159 +. +1517333984375 +86 +. +81004333496094 ] ' descriptor @@ -722,6 +1580,7 @@ descriptor shape : [ +6 4 ] dataType @@ -741,14 +1600,13 @@ name : ' dequantizeLinear -int8 -4D -constant +uint4 +1D tensor -broadcasting -scale -and -zeroPoint +with +even +input +size ' ' graph @@ -770,11 +1628,8 @@ data ' : [ -- -124 +15 0 -23 -122 ] ' descriptor @@ -784,15 +1639,12 @@ descriptor shape : [ -1 -1 -2 2 ] dataType : ' -int8 +uint4 ' } ' @@ -811,13 +1663,12 @@ data ' : [ -0 +1 . -2800687253475189 -- -4 +1202747821807861 +1 . -617084980010986 +1202747821807861 ] ' descriptor @@ -828,7 +1679,6 @@ shape : [ 2 -1 ] dataType : @@ -852,7 +1702,8 @@ data ' : [ -12 +0 +1 ] ' descriptor @@ -862,11 +1713,12 @@ descriptor shape : [ +2 ] dataType : ' -int8 +uint4 ' } ' @@ -946,22 +1798,13 @@ data ' : [ -- -38 -. -08934783935547 -- -3 -. -3608245849609375 -- -50 +16 . -787933349609375 +804121017456055 - -507 +1 . -87933349609375 +1202747821807861 ] ' descriptor @@ -971,9 +1814,6 @@ descriptor shape : [ -1 -1 -2 2 ] dataType @@ -997,7 +1837,7 @@ uint4 1D tensor with -even +odd input size ' @@ -1021,8 +1861,9 @@ data ' : [ -15 -0 +10 +12 +14 ] ' descriptor @@ -1032,7 +1873,7 @@ descriptor shape : [ -2 +3 ] dataType : @@ -1059,9 +1900,6 @@ data 1 . 1202747821807861 -1 -. -1202747821807861 ] ' descriptor @@ -1071,7 +1909,7 @@ descriptor shape : [ -2 +1 ] dataType : @@ -1095,7 +1933,7 @@ data ' : [ -0 +2 ] ' descriptor @@ -1105,6 +1943,7 @@ descriptor shape : [ +1 ] dataType : @@ -1189,10 +2028,15 @@ data ' : [ -16 +8 . -804121017456055 -0 +962198257446289 +11 +. +202747344970703 +13 +. +443297386169434 ] ' descriptor @@ -1202,7 +2046,7 @@ descriptor shape : [ -2 +3 ] dataType : @@ -1222,12 +2066,11 @@ name ' dequantizeLinear uint4 -1D +4D +constant tensor -with -odd -input -size +broadcasting +zeroPoint ' ' graph @@ -1249,9 +2092,10 @@ data ' : [ +0 +1 10 -12 -14 +15 ] ' descriptor @@ -1261,7 +2105,10 @@ descriptor shape : [ -3 +1 +1 +2 +2 ] dataType : @@ -1285,9 +2132,13 @@ data ' : [ -1 +9 . -1202747821807861 +343092918395996 +- +4 +. +617084980010986 ] ' descriptor @@ -1297,6 +2148,7 @@ descriptor shape : [ +2 1 ] dataType @@ -1322,8 +2174,7 @@ data : [ 2 -1 -4 +3 ] ' descriptor @@ -1333,7 +2184,8 @@ descriptor shape : [ -3 +2 +1 ] dataType : @@ -1418,15 +2270,22 @@ data ' : [ -8 +- +18 . -962198257446289 -12 +686185836791992 +- +9 . -323022842407227 -11 +343092918395996 +- +32 . -202747344970703 +31959533691406 +- +55 +. +40502166748047 ] ' descriptor @@ -1436,7 +2295,10 @@ descriptor shape : [ -3 +1 +1 +2 +2 ] dataType : @@ -1456,11 +2318,16 @@ name ' dequantizeLinear uint4 -4D -constant -tensor -broadcasting -zeroPoint +3D +input +with +block_size += +[ +1 +1 +2 +] ' ' graph @@ -1497,8 +2364,7 @@ shape [ 1 1 -2 -2 +4 ] dataType : @@ -1538,8 +2404,8 @@ descriptor shape : [ -2 1 +2 ] dataType : @@ -1574,6 +2440,7 @@ descriptor shape : [ +1 2 ] dataType @@ -1664,13 +2531,13 @@ data . 686185836791992 - -18 +9 . -686185836791992 +343092918395996 - -36 +32 . -93667984008789 +31959533691406 - 55 . @@ -1686,8 +2553,7 @@ shape [ 1 1 -2 -2 +4 ] dataType : @@ -1773,6 +2639,9 @@ data 1 . 1202747821807861 +1 +. +1202747821807861 ] ' descriptor @@ -1782,6 +2651,7 @@ descriptor shape : [ +2 ] dataType : @@ -2014,6 +2884,7 @@ descriptor shape : [ +1 ] dataType : @@ -2039,8 +2910,6 @@ data [ - 3 -0 -0 ] ' descriptor @@ -2050,7 +2919,7 @@ descriptor shape : [ -3 +1 ] dataType : @@ -2138,10 +3007,12 @@ data 2 . 2405495643615723 -7 +11 . -841923713684082 -0 +202747344970703 +3 +. +3608243465423584 ] ' descriptor diff --git a/testing/web-platform/tests/webnn/conformance_tests/quantizeLinear.https.any.js b/testing/web-platform/tests/webnn/conformance_tests/quantizeLinear.https.any.js index 0cecbbea20d3..98d703a1a634 100644 --- a/testing/web-platform/tests/webnn/conformance_tests/quantizeLinear.https.any.js +++ b/testing/web-platform/tests/webnn/conformance_tests/quantizeLinear.https.any.js @@ -410,6 +410,9 @@ data : [ 128 +128 +128 +128 ] ' descriptor @@ -419,6 +422,7 @@ descriptor shape : [ +4 ] dataType : @@ -536,13 +540,13 @@ name ' quantizeLinear float32 -4D +2D constant tensor broadcasting -scale -and zeroPoint +and +scale ' ' graph @@ -587,8 +591,6 @@ descriptor shape : [ -1 -1 2 2 ] @@ -614,13 +616,9 @@ data ' : [ -0 -. -2800687253475189 -- -4 +9 . -617084980010986 +343092918395996 ] ' descriptor @@ -630,7 +628,6 @@ descriptor shape : [ -2 1 ] dataType @@ -665,6 +662,7 @@ descriptor shape : [ +1 ] dataType : @@ -749,10 +747,10 @@ data ' : [ -119 -111 -126 +128 127 +129 +129 ] ' descriptor @@ -762,8 +760,6 @@ descriptor shape : [ -1 -1 2 2 ] @@ -785,14 +781,13 @@ name ' quantizeLinear float32 +4D +constant tensor -with -int4 +broadcasting +scale +and zeroPoint -which -has -odd -size ' ' graph @@ -814,9 +809,20 @@ data ' : [ +- +2 +. +549168109893799 +- 4 . 794857501983643 +8 +. +413617134094238 +6 +. +108623504638672 ] ' descriptor @@ -826,6 +832,10 @@ descriptor shape : [ +1 +1 +2 +2 ] dataType : @@ -849,9 +859,13 @@ data ' : [ -1 +0 . -1202747821807861 +2800687253475189 +- +4 +. +617084980010986 ] ' descriptor @@ -861,6 +875,8 @@ descriptor shape : [ +2 +1 ] dataType : @@ -884,8 +900,8 @@ data ' : [ -- -4 +128 +128 ] ' descriptor @@ -895,11 +911,13 @@ descriptor shape : [ +2 +1 ] dataType : ' -int4 +uint8 ' } ' @@ -979,8 +997,10 @@ data ' : [ -- -1 +119 +111 +126 +127 ] ' descriptor @@ -990,11 +1010,15 @@ descriptor shape : [ +1 +1 +2 +2 ] dataType : ' -int4 +uint8 ' } } @@ -1009,14 +1033,18 @@ name ' quantizeLinear float32 -tensor +3D +input with -int4 -zeroPoint -which -has -even -size +implicit +block_size += +[ +1 +2 +1 +] +. ' ' graph @@ -1038,12 +1066,20 @@ data ' : [ +- +2 +. +549168109893799 +- 4 . 794857501983643 -3 +8 . -23434354545 +413617134094238 +6 +. +108623504638672 ] ' descriptor @@ -1053,7 +1089,9 @@ descriptor shape : [ -2 +1 +4 +1 ] dataType : @@ -1077,9 +1115,13 @@ data ' : [ -1 +0 . -1202747821807861 +2800687253475189 +- +4 +. +617084980010986 ] ' descriptor @@ -1089,6 +1131,8 @@ descriptor shape : [ +2 +1 ] dataType : @@ -1112,10 +1156,8 @@ data ' : [ -- -6 -- -5 +128 +189 ] ' descriptor @@ -1126,11 +1168,12 @@ shape : [ 2 +1 ] dataType : ' -int4 +uint8 ' } ' @@ -1210,10 +1253,10 @@ data ' : [ -- -2 -- -2 +119 +111 +187 +188 ] ' descriptor @@ -1223,12 +1266,14 @@ descriptor shape : [ -2 +1 +4 +1 ] dataType : ' -int4 +uint8 ' } } @@ -1243,14 +1288,13 @@ name ' quantizeLinear float32 -2D tensor with int4 zeroPoint which has -even +odd size ' ' @@ -1276,19 +1320,6 @@ data 4 . 794857501983643 -3 -. -23434354545 -2 -. -794857501983643 -5 -. -794857501983643 -0 -7 -. -23434354545 ] ' descriptor @@ -1298,8 +1329,6 @@ descriptor shape : [ -3 -2 ] dataType : @@ -1326,9 +1355,6 @@ data 1 . 1202747821807861 -2 -. -1202747821807861 ] ' descriptor @@ -1338,7 +1364,6 @@ descriptor shape : [ -2 ] dataType : @@ -1363,9 +1388,7 @@ data : [ - -6 -- -5 +4 ] ' descriptor @@ -1375,7 +1398,6 @@ descriptor shape : [ -2 ] dataType : @@ -1461,17 +1483,7 @@ data : [ - -2 -- -3 -- -4 -- -3 -- -5 -- -2 +1 ] ' descriptor @@ -1481,8 +1493,6 @@ descriptor shape : [ -3 -2 ] dataType : @@ -1504,11 +1514,11 @@ quantizeLinear float32 tensor with -uint4 +int4 zeroPoint which has -odd +even size ' ' @@ -1534,16 +1544,9 @@ data 4 . 794857501983643 -2 -. -794857501983643 -1 -. -794857501983643 -0 3 . -794857501983643 +23434354545 ] ' descriptor @@ -1553,7 +1556,7 @@ descriptor shape : [ -5 +2 ] dataType : @@ -1580,6 +1583,9 @@ data 1 . 1202747821807861 +1 +. +1202747821807861 ] ' descriptor @@ -1589,6 +1595,7 @@ descriptor shape : [ +2 ] dataType : @@ -1612,7 +1619,10 @@ data ' : [ -12 +- +6 +- +5 ] ' descriptor @@ -1622,11 +1632,12 @@ descriptor shape : [ +2 ] dataType : ' -uint4 +int4 ' } ' @@ -1706,11 +1717,10 @@ data ' : [ -16 -14 -13 -12 -15 +- +2 +- +2 ] ' descriptor @@ -1720,12 +1730,12 @@ descriptor shape : [ -5 +2 ] dataType : ' -uint4 +int4 ' } } @@ -1740,9 +1750,10 @@ name ' quantizeLinear float32 +2D tensor with -uint4 +int4 zeroPoint which has @@ -1775,6 +1786,16 @@ data 3 . 23434354545 +2 +. +794857501983643 +5 +. +794857501983643 +0 +7 +. +23434354545 ] ' descriptor @@ -1784,6 +1805,7 @@ descriptor shape : [ +3 2 ] dataType @@ -1811,6 +1833,9 @@ data 1 . 1202747821807861 +2 +. +1202747821807861 ] ' descriptor @@ -1820,6 +1845,7 @@ descriptor shape : [ +2 ] dataType : @@ -1843,7 +1869,9 @@ data ' : [ -1 +- +6 +- 5 ] ' @@ -1859,7 +1887,7 @@ shape dataType : ' -uint4 +int4 ' } ' @@ -1939,12 +1967,927 @@ data ' : [ -5 -8 -] -' -descriptor -' +- +2 +- +3 +- +4 +- +3 +- +5 +- +2 +] +' +descriptor +' +: +{ +shape +: +[ +3 +2 +] +dataType +: +' +int4 +' +} +} +} +} +} +{ +' +name +' +: +' +quantizeLinear +int4 +zeroPoint +with +block_size += +[ +3 +2 +] +' +' +graph +' +: +{ +' +inputs +' +: +{ +' +quantizeLinearInput +' +: +{ +' +data +' +: +[ +4 +. +794857501983643 +3 +. +23434354545 +2 +. +794857501983643 +5 +. +794857501983643 +0 +7 +. +23434354545 +4 +. +794857501983643 +3 +. +23434354545 +2 +. +794857501983643 +5 +. +794857501983643 +0 +7 +. +23434354545 +] +' +descriptor +' +: +{ +shape +: +[ +3 +4 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearScale +' +: +{ +' +data +' +: +[ +1 +. +1202747821807861 +2 +. +1202747821807861 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearZeroPoint +' +: +{ +' +data +' +: +[ +- +6 +- +5 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +int4 +' +} +' +constant +' +: +true +} +} +' +operators +' +: +[ +{ +' +name +' +: +' +quantizeLinear +' +' +arguments +' +: +[ +{ +' +input +' +: +' +quantizeLinearInput +' +} +{ +' +scale +' +: +' +quantizeLinearScale +' +} +{ +' +zeroPoint +' +: +' +quantizeLinearZeroPoint +' +} +] +' +outputs +' +: +' +quantizeLinearOutput +' +} +] +' +expectedOutputs +' +: +{ +' +quantizeLinearOutput +' +: +{ +' +data +' +: +[ +- +2 +- +3 +- +4 +- +3 +- +5 +0 +- +2 +- +3 +- +4 +- +1 +- +5 +- +2 +] +' +descriptor +' +: +{ +shape +: +[ +3 +4 +] +dataType +: +' +int4 +' +} +} +} +} +} +{ +' +name +' +: +' +quantizeLinear +float32 +tensor +with +uint4 +zeroPoint +which +has +odd +size +' +' +graph +' +: +{ +' +inputs +' +: +{ +' +quantizeLinearInput +' +: +{ +' +data +' +: +[ +4 +. +794857501983643 +2 +. +794857501983643 +1 +. +794857501983643 +0 +3 +. +794857501983643 +] +' +descriptor +' +: +{ +shape +: +[ +5 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearScale +' +: +{ +' +data +' +: +[ +1 +. +1202747821807861 +] +' +descriptor +' +: +{ +shape +: +[ +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearZeroPoint +' +: +{ +' +data +' +: +[ +12 +] +' +descriptor +' +: +{ +shape +: +[ +] +dataType +: +' +uint4 +' +} +' +constant +' +: +true +} +} +' +operators +' +: +[ +{ +' +name +' +: +' +quantizeLinear +' +' +arguments +' +: +[ +{ +' +input +' +: +' +quantizeLinearInput +' +} +{ +' +scale +' +: +' +quantizeLinearScale +' +} +{ +' +zeroPoint +' +: +' +quantizeLinearZeroPoint +' +} +] +' +outputs +' +: +' +quantizeLinearOutput +' +} +] +' +expectedOutputs +' +: +{ +' +quantizeLinearOutput +' +: +{ +' +data +' +: +[ +16 +14 +13 +12 +15 +] +' +descriptor +' +: +{ +shape +: +[ +5 +] +dataType +: +' +uint4 +' +} +} +} +} +} +{ +' +name +' +: +' +quantizeLinear +float32 +tensor +with +uint4 +zeroPoint +which +has +even +size +' +' +graph +' +: +{ +' +inputs +' +: +{ +' +quantizeLinearInput +' +: +{ +' +data +' +: +[ +4 +. +794857501983643 +3 +. +23434354545 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearScale +' +: +{ +' +data +' +: +[ +1 +. +1202747821807861 +1 +. +1202747821807861 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearZeroPoint +' +: +{ +' +data +' +: +[ +1 +5 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +uint4 +' +} +' +constant +' +: +true +} +} +' +operators +' +: +[ +{ +' +name +' +: +' +quantizeLinear +' +' +arguments +' +: +[ +{ +' +input +' +: +' +quantizeLinearInput +' +} +{ +' +scale +' +: +' +quantizeLinearScale +' +} +{ +' +zeroPoint +' +: +' +quantizeLinearZeroPoint +' +} +] +' +outputs +' +: +' +quantizeLinearOutput +' +} +] +' +expectedOutputs +' +: +{ +' +quantizeLinearOutput +' +: +{ +' +data +' +: +[ +5 +8 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +uint4 +' +} +} +} +} +} +{ +' +name +' +: +' +quantizeLinear +uint4 +zeroPoint +with +block_size += +3 +' +' +graph +' +: +{ +' +inputs +' +: +{ +' +quantizeLinearInput +' +: +{ +' +data +' +: +[ +4 +. +794857501983643 +3 +. +23434354545 +1 +. +794857501983643 +2 +. +23434354545 +4 +. +794857501983643 +3 +. +23434354545 +] +' +descriptor +' +: +{ +shape +: +[ +6 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearScale +' +: +{ +' +data +' +: +[ +1 +. +1202747821807861 +1 +. +1202747821807861 +] +' +descriptor +' +: +{ +shape +: +[ +2 +] +dataType +: +' +float32 +' +} +' +constant +' +: +true +} +' +quantizeLinearZeroPoint +' +: +{ +' +data +' +: +[ +1 +5 +] +' +descriptor +' : { shape @@ -1958,6 +2901,106 @@ dataType uint4 ' } +' +constant +' +: +true +} +} +' +operators +' +: +[ +{ +' +name +' +: +' +quantizeLinear +' +' +arguments +' +: +[ +{ +' +input +' +: +' +quantizeLinearInput +' +} +{ +' +scale +' +: +' +quantizeLinearScale +' +} +{ +' +zeroPoint +' +: +' +quantizeLinearZeroPoint +' +} +] +' +outputs +' +: +' +quantizeLinearOutput +' +} +] +' +expectedOutputs +' +: +{ +' +quantizeLinearOutput +' +: +{ +' +data +' +: +[ +5 +4 +3 +7 +9 +8 +] +' +descriptor +' +: +{ +shape +: +[ +6 +] +dataType +: +' +uint4 +' +} } } } diff --git a/testing/web-platform/tests/webnn/validation_tests/dequantizeLinear.https.any.js b/testing/web-platform/tests/webnn/validation_tests/dequantizeLinear.https.any.js index 7bb47d2c764a..9e7724d98903 100644 --- a/testing/web-platform/tests/webnn/validation_tests/dequantizeLinear.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/dequantizeLinear.https.any.js @@ -318,20 +318,105 @@ name [ dequantizeLinear ] +Test +block +- +wise +quantization +with +block_size += +[ +2 +2 +5 +] +. +' +input +: +{ +dataType +: +' +uint8 +' +shape +: +[ +6 +4 +5 +] +} +scale +: +{ +dataType +: +' +float32 +' +shape +: +[ +3 +2 +1 +] +} +zeroPoint +: +{ +dataType +: +' +uint8 +' +shape +: +[ +3 +2 +1 +] +} +output +: +{ +dataType +: +' +float32 +' +shape +: +[ +6 +4 +5 +] +} +} +{ +name +: +' +[ +dequantizeLinear +] Throw if the -shape -of scale +size is not -broadcastable -to -the -shape +a +factor of input +size . ' input @@ -375,7 +460,7 @@ uint8 shape : [ -5 +2 ] } } @@ -394,8 +479,9 @@ of zero_point is not -broadcastable -to +the +same +as the shape of @@ -534,9 +620,14 @@ of input is not +one +of +{ +int4 +uint4 int8 -or uint8 +} . ' input @@ -600,9 +691,14 @@ of zero_point is not +one +of +{ +int4 +uint4 int8 -or uint8 +} . ' input diff --git a/testing/web-platform/tests/webnn/validation_tests/quantizeLinear.https.any.js b/testing/web-platform/tests/webnn/validation_tests/quantizeLinear.https.any.js index 978d6783396c..7ce5e84a9700 100644 --- a/testing/web-platform/tests/webnn/validation_tests/quantizeLinear.https.any.js +++ b/testing/web-platform/tests/webnn/validation_tests/quantizeLinear.https.any.js @@ -318,20 +318,105 @@ name [ quantizeLinear ] +Test +block +- +wise +quantization +with +block_size += +[ +3 +2 +5 +] +. +' +input +: +{ +dataType +: +' +float32 +' +shape +: +[ +6 +4 +5 +] +} +scale +: +{ +dataType +: +' +float32 +' +shape +: +[ +2 +2 +1 +] +} +zeroPoint +: +{ +dataType +: +' +int8 +' +shape +: +[ +2 +2 +1 +] +} +output +: +{ +dataType +: +' +int8 +' +shape +: +[ +6 +4 +5 +] +} +} +{ +name +: +' +[ +quantizeLinear +] Throw if the -shape -of scale +size is not -broadcastable -to -the -shape +a +factor of input +size . ' input @@ -362,6 +447,8 @@ shape : [ 2 +1 +5 ] } zeroPoint @@ -375,6 +462,8 @@ int8 shape : [ +2 +1 5 ] } @@ -394,8 +483,9 @@ of zero_point is not -broadcastable -to +the +same +as the shape of @@ -444,6 +534,7 @@ shape : [ 2 +5 ] } } @@ -496,6 +587,8 @@ float16 shape : [ +3 +1 5 ] } @@ -510,6 +603,8 @@ int8 shape : [ +3 +1 5 ] } @@ -531,6 +626,8 @@ input is not float32 +or +float16 . ' input @@ -595,6 +692,8 @@ scale is not float32 +or +float16 . ' input