From 5732af4c82fe75fc7c095687c60617cddb1200ac Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Sat, 16 Nov 2024 01:55:25 +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 bb08e459dcd6e..c8c6044ade8fb 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 @@ -730,6 +730,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 @@ -739,11 +1530,13 @@ descriptor shape : [ +2 +2 ] dataType : ' -uint8 +int8 ' } ' @@ -824,20 +1617,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 @@ -847,6 +1705,7 @@ descriptor shape : [ +6 4 ] dataType @@ -866,14 +1725,13 @@ name : ' dequantizeLinear -int8 -4D -constant +uint4 +1D tensor -broadcasting -scale -and -zeroPoint +with +even +input +size ' ' graph @@ -895,11 +1753,8 @@ data ' : [ -- -124 +15 0 -23 -122 ] ' descriptor @@ -909,15 +1764,12 @@ descriptor shape : [ -1 -1 -2 2 ] dataType : ' -int8 +uint4 ' } ' @@ -936,13 +1788,12 @@ data ' : [ -0 +1 . -2800687253475189 -- -4 +1202747821807861 +1 . -617084980010986 +1202747821807861 ] ' descriptor @@ -953,7 +1804,6 @@ shape : [ 2 -1 ] dataType : @@ -977,7 +1827,8 @@ data ' : [ -12 +0 +1 ] ' descriptor @@ -987,11 +1838,12 @@ descriptor shape : [ +2 ] dataType : ' -int8 +uint4 ' } ' @@ -1071,22 +1923,13 @@ data ' : [ -- -38 -. -08934783935547 -- -3 -. -3608245849609375 -- -50 +16 . -787933349609375 +804121017456055 - -507 +1 . -87933349609375 +1202747821807861 ] ' descriptor @@ -1096,9 +1939,6 @@ descriptor shape : [ -1 -1 -2 2 ] dataType @@ -1122,7 +1962,7 @@ uint4 1D tensor with -even +odd input size ' @@ -1146,8 +1986,9 @@ data ' : [ -15 -0 +10 +12 +14 ] ' descriptor @@ -1157,7 +1998,7 @@ descriptor shape : [ -2 +3 ] dataType : @@ -1184,9 +2025,6 @@ data 1 . 1202747821807861 -1 -. -1202747821807861 ] ' descriptor @@ -1196,7 +2034,7 @@ descriptor shape : [ -2 +1 ] dataType : @@ -1220,7 +2058,7 @@ data ' : [ -0 +2 ] ' descriptor @@ -1230,6 +2068,7 @@ descriptor shape : [ +1 ] dataType : @@ -1314,10 +2153,15 @@ data ' : [ -16 +8 . -804121017456055 -0 +962198257446289 +11 +. +202747344970703 +13 +. +443297386169434 ] ' descriptor @@ -1327,7 +2171,7 @@ descriptor shape : [ -2 +3 ] dataType : @@ -1347,12 +2191,11 @@ name ' dequantizeLinear uint4 -1D +4D +constant tensor -with -odd -input -size +broadcasting +zeroPoint ' ' graph @@ -1374,9 +2217,10 @@ data ' : [ +0 +1 10 -12 -14 +15 ] ' descriptor @@ -1386,7 +2230,10 @@ descriptor shape : [ -3 +1 +1 +2 +2 ] dataType : @@ -1410,9 +2257,13 @@ data ' : [ -1 +9 . -1202747821807861 +343092918395996 +- +4 +. +617084980010986 ] ' descriptor @@ -1422,6 +2273,7 @@ descriptor shape : [ +2 1 ] dataType @@ -1447,8 +2299,7 @@ data : [ 2 -1 -4 +3 ] ' descriptor @@ -1458,7 +2309,8 @@ descriptor shape : [ -3 +2 +1 ] dataType : @@ -1543,15 +2395,22 @@ data ' : [ -8 +- +18 . -962198257446289 -12 +686185836791992 +- +9 . -323022842407227 -11 +343092918395996 +- +32 . -202747344970703 +31959533691406 +- +55 +. +40502166748047 ] ' descriptor @@ -1561,7 +2420,10 @@ descriptor shape : [ -3 +1 +1 +2 +2 ] dataType : @@ -1581,11 +2443,16 @@ name ' dequantizeLinear uint4 -4D -constant -tensor -broadcasting -zeroPoint +3D +input +with +block_size += +[ +1 +1 +2 +] ' ' graph @@ -1622,8 +2489,7 @@ shape [ 1 1 -2 -2 +4 ] dataType : @@ -1663,8 +2529,8 @@ descriptor shape : [ -2 1 +2 ] dataType : @@ -1699,6 +2565,7 @@ descriptor shape : [ +1 2 ] dataType @@ -1789,13 +2656,13 @@ data . 686185836791992 - -18 +9 . -686185836791992 +343092918395996 - -36 +32 . -93667984008789 +31959533691406 - 55 . @@ -1811,8 +2678,7 @@ shape [ 1 1 -2 -2 +4 ] dataType : @@ -1898,6 +2764,9 @@ data 1 . 1202747821807861 +1 +. +1202747821807861 ] ' descriptor @@ -1907,6 +2776,7 @@ descriptor shape : [ +2 ] dataType : @@ -2139,6 +3009,7 @@ descriptor shape : [ +1 ] dataType : @@ -2164,8 +3035,6 @@ data [ - 3 -0 -0 ] ' descriptor @@ -2175,7 +3044,7 @@ descriptor shape : [ -3 +1 ] dataType : @@ -2263,10 +3132,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 26481c3a6e5eb..7967af044866d 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 @@ -548,6 +548,9 @@ data : [ 128 +128 +128 +128 ] ' descriptor @@ -557,6 +560,7 @@ descriptor shape : [ +4 ] dataType : @@ -674,13 +678,13 @@ name ' quantizeLinear float32 -4D +2D constant tensor broadcasting -scale -and zeroPoint +and +scale ' ' graph @@ -725,8 +729,6 @@ descriptor shape : [ -1 -1 2 2 ] @@ -752,13 +754,9 @@ data ' : [ -0 -. -2800687253475189 -- -4 +9 . -617084980010986 +343092918395996 ] ' descriptor @@ -768,7 +766,6 @@ descriptor shape : [ -2 1 ] dataType @@ -803,6 +800,7 @@ descriptor shape : [ +1 ] dataType : @@ -887,10 +885,10 @@ data ' : [ -119 -111 -126 +128 127 +129 +129 ] ' descriptor @@ -900,8 +898,6 @@ descriptor shape : [ -1 -1 2 2 ] @@ -923,14 +919,13 @@ name ' quantizeLinear float32 +4D +constant tensor -with -int4 +broadcasting +scale +and zeroPoint -which -has -odd -size ' ' graph @@ -952,9 +947,20 @@ data ' : [ +- +2 +. +549168109893799 +- 4 . 794857501983643 +8 +. +413617134094238 +6 +. +108623504638672 ] ' descriptor @@ -964,6 +970,10 @@ descriptor shape : [ +1 +1 +2 +2 ] dataType : @@ -987,9 +997,13 @@ data ' : [ -1 +0 . -1202747821807861 +2800687253475189 +- +4 +. +617084980010986 ] ' descriptor @@ -999,6 +1013,8 @@ descriptor shape : [ +2 +1 ] dataType : @@ -1022,8 +1038,8 @@ data ' : [ -- -4 +128 +128 ] ' descriptor @@ -1033,11 +1049,13 @@ descriptor shape : [ +2 +1 ] dataType : ' -int4 +uint8 ' } ' @@ -1117,8 +1135,10 @@ data ' : [ -- -1 +119 +111 +126 +127 ] ' descriptor @@ -1128,11 +1148,15 @@ descriptor shape : [ +1 +1 +2 +2 ] dataType : ' -int4 +uint8 ' } } @@ -1147,14 +1171,18 @@ name ' quantizeLinear float32 -tensor +3D +input with -int4 -zeroPoint -which -has -even -size +implicit +block_size += +[ +1 +2 +1 +] +. ' ' graph @@ -1176,12 +1204,20 @@ data ' : [ +- +2 +. +549168109893799 +- 4 . 794857501983643 -3 +8 . -23434354545 +413617134094238 +6 +. +108623504638672 ] ' descriptor @@ -1191,7 +1227,9 @@ descriptor shape : [ -2 +1 +4 +1 ] dataType : @@ -1215,9 +1253,13 @@ data ' : [ -1 +0 . -1202747821807861 +2800687253475189 +- +4 +. +617084980010986 ] ' descriptor @@ -1227,6 +1269,8 @@ descriptor shape : [ +2 +1 ] dataType : @@ -1250,10 +1294,8 @@ data ' : [ -- -6 -- -5 +128 +189 ] ' descriptor @@ -1264,11 +1306,12 @@ shape : [ 2 +1 ] dataType : ' -int4 +uint8 ' } ' @@ -1348,10 +1391,10 @@ data ' : [ -- -2 -- -2 +119 +111 +187 +188 ] ' descriptor @@ -1361,12 +1404,14 @@ descriptor shape : [ -2 +1 +4 +1 ] dataType : ' -int4 +uint8 ' } } @@ -1381,14 +1426,13 @@ name ' quantizeLinear float32 -2D tensor with int4 zeroPoint which has -even +odd size ' ' @@ -1414,19 +1458,6 @@ data 4 . 794857501983643 -3 -. -23434354545 -2 -. -794857501983643 -5 -. -794857501983643 -0 -7 -. -23434354545 ] ' descriptor @@ -1436,8 +1467,6 @@ descriptor shape : [ -3 -2 ] dataType : @@ -1464,9 +1493,6 @@ data 1 . 1202747821807861 -2 -. -1202747821807861 ] ' descriptor @@ -1476,7 +1502,6 @@ descriptor shape : [ -2 ] dataType : @@ -1501,9 +1526,7 @@ data : [ - -6 -- -5 +4 ] ' descriptor @@ -1513,7 +1536,6 @@ descriptor shape : [ -2 ] dataType : @@ -1599,17 +1621,7 @@ data : [ - -2 -- -3 -- -4 -- -3 -- -5 -- -2 +1 ] ' descriptor @@ -1619,8 +1631,6 @@ descriptor shape : [ -3 -2 ] dataType : @@ -1642,11 +1652,11 @@ quantizeLinear float32 tensor with -uint4 +int4 zeroPoint which has -odd +even size ' ' @@ -1672,16 +1682,9 @@ data 4 . 794857501983643 -2 -. -794857501983643 -1 -. -794857501983643 -0 3 . -794857501983643 +23434354545 ] ' descriptor @@ -1691,7 +1694,7 @@ descriptor shape : [ -5 +2 ] dataType : @@ -1718,6 +1721,9 @@ data 1 . 1202747821807861 +1 +. +1202747821807861 ] ' descriptor @@ -1727,6 +1733,7 @@ descriptor shape : [ +2 ] dataType : @@ -1750,7 +1757,10 @@ data ' : [ -12 +- +6 +- +5 ] ' descriptor @@ -1760,11 +1770,12 @@ descriptor shape : [ +2 ] dataType : ' -uint4 +int4 ' } ' @@ -1844,11 +1855,10 @@ data ' : [ -16 -14 -13 -12 -15 +- +2 +- +2 ] ' descriptor @@ -1858,12 +1868,12 @@ descriptor shape : [ -5 +2 ] dataType : ' -uint4 +int4 ' } } @@ -1878,9 +1888,10 @@ name ' quantizeLinear float32 +2D tensor with -uint4 +int4 zeroPoint which has @@ -1913,6 +1924,16 @@ data 3 . 23434354545 +2 +. +794857501983643 +5 +. +794857501983643 +0 +7 +. +23434354545 ] ' descriptor @@ -1922,6 +1943,7 @@ descriptor shape : [ +3 2 ] dataType @@ -1949,6 +1971,9 @@ data 1 . 1202747821807861 +2 +. +1202747821807861 ] ' descriptor @@ -1958,6 +1983,7 @@ descriptor shape : [ +2 ] dataType : @@ -1981,7 +2007,9 @@ data ' : [ -1 +- +6 +- 5 ] ' @@ -1997,7 +2025,7 @@ shape dataType : ' -uint4 +int4 ' } ' @@ -2077,12 +2105,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 @@ -2096,6 +3039,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 3c3d0cf788918..f06d73dc2f5ab 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 @@ -377,20 +377,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 @@ -434,7 +519,7 @@ uint8 shape : [ -5 +2 ] } } @@ -453,8 +538,9 @@ of zero_point is not -broadcastable -to +the +same +as the shape of @@ -593,9 +679,14 @@ of input is not +one +of +{ +int4 +uint4 int8 -or uint8 +} . ' input @@ -659,9 +750,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 aa0bde2a61c43..d510a5a25df96 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 @@ -377,20 +377,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 @@ -421,6 +506,8 @@ shape : [ 2 +1 +5 ] } zeroPoint @@ -434,6 +521,8 @@ int8 shape : [ +2 +1 5 ] } @@ -453,8 +542,9 @@ of zero_point is not -broadcastable -to +the +same +as the shape of @@ -503,6 +593,7 @@ shape : [ 2 +5 ] } } @@ -555,6 +646,8 @@ float16 shape : [ +3 +1 5 ] } @@ -569,6 +662,8 @@ int8 shape : [ +3 +1 5 ] } @@ -590,6 +685,8 @@ input is not float32 +or +float16 . ' input @@ -654,6 +751,8 @@ scale is not float32 +or +float16 . ' input