Skip to content

Commit 6a820eb

Browse files
fujunweichromium-wpt-export-bot
authored andcommitted
webnn: fuse QDQ for pool2d on tflite
For the TFLite kernel of pooling [1], the `|input scaler scale - output scaler scale|` must be less than 1.0e-6, and zero point of output tensor must be the same as input. [1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/tflite/src/tensorflow/lite/kernels/pooling.cc;l=101 Bug: 401281047 Change-Id: Ice3b25613e2b646667b652f00800e105069604e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6515696 Reviewed-by: Phillis Tang <[email protected]> Reviewed-by: ningxin hu <[email protected]> Commit-Queue: Junwei Fu <[email protected]> Cr-Commit-Position: refs/heads/main@{#1457350}
1 parent 4b41123 commit 6a820eb

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed

webnn/conformance_tests/qdq_subgraph.https.any.js

+164
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,170 @@ const subgraphTests = [
10071007
}
10081008
}
10091009
},
1010+
{
1011+
'name': 'quantized averagePool2d',
1012+
'graph': {
1013+
'inputs': {
1014+
'input': {
1015+
'data': [
1016+
49.1112174987793, 11.907459259033203,
1017+
21.115795135498047, 70.7490005493164,
1018+
],
1019+
'descriptor': {shape: [1, 2, 2, 1], dataType: 'float32'},
1020+
'constant': false
1021+
},
1022+
'inputScale': {
1023+
'data': [0.3921568859368563],
1024+
'descriptor': {shape: [1], dataType: 'float32'},
1025+
'constant': true
1026+
},
1027+
'inputZeroPoint': {
1028+
'data': [16],
1029+
'descriptor': {shape: [1], dataType: 'int8'},
1030+
'constant': true
1031+
},
1032+
'outputScale': {
1033+
'data': [0.3921568859368563],
1034+
'descriptor': {shape: [1], dataType: 'float32'},
1035+
'constant': true
1036+
},
1037+
'outputZeroPoint': {
1038+
'data': [16],
1039+
'descriptor': {shape: [1], dataType: 'int8'},
1040+
'constant': true
1041+
},
1042+
},
1043+
'operators': [
1044+
{
1045+
'name': 'quantizeLinear',
1046+
'arguments': [
1047+
{'input': 'input'},
1048+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1049+
],
1050+
'outputs': 'quantizedInput'
1051+
},
1052+
{
1053+
'name': 'dequantizeLinear',
1054+
'arguments': [
1055+
{'input': 'quantizedInput'},
1056+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1057+
],
1058+
'outputs': 'dequantizedInput'
1059+
},
1060+
{
1061+
'name': 'averagePool2d',
1062+
'arguments': [{'input': 'dequantizedInput'}, {'options': {'layout': 'nhwc'}}],
1063+
'outputs': 'averagePool2dOutput'
1064+
},
1065+
{
1066+
'name': 'quantizeLinear',
1067+
'arguments': [
1068+
{'input': 'averagePool2dOutput'},
1069+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1070+
],
1071+
'outputs': 'quantizedAveragePool2dOutput'
1072+
},
1073+
{
1074+
'name': 'dequantizeLinear',
1075+
'arguments': [
1076+
{'input': 'quantizedAveragePool2dOutput'},
1077+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1078+
],
1079+
'outputs': 'output'
1080+
}
1081+
],
1082+
'expectedOutputs': {
1083+
'output': {
1084+
'data': [
1085+
30.196081161499023,
1086+
],
1087+
'descriptor': {shape: [1, 1, 1, 1], dataType: 'float32'}
1088+
}
1089+
}
1090+
}
1091+
},
1092+
{
1093+
'name': 'quantized maxPool2d',
1094+
'graph': {
1095+
'inputs': {
1096+
'input': {
1097+
'data': [
1098+
49.1112174987793, 11.907459259033203,
1099+
21.115795135498047, 70.7490005493164,
1100+
],
1101+
'descriptor': {shape: [1, 2, 2, 1], dataType: 'float32'},
1102+
'constant': false
1103+
},
1104+
'inputScale': {
1105+
'data': [0.3921568859368563],
1106+
'descriptor': {shape: [1], dataType: 'float32'},
1107+
'constant': true
1108+
},
1109+
'inputZeroPoint': {
1110+
'data': [16],
1111+
'descriptor': {shape: [1], dataType: 'int8'},
1112+
'constant': true
1113+
},
1114+
'outputScale': {
1115+
'data': [0.3921568859368563],
1116+
'descriptor': {shape: [1], dataType: 'float32'},
1117+
'constant': true
1118+
},
1119+
'outputZeroPoint': {
1120+
'data': [16],
1121+
'descriptor': {shape: [1], dataType: 'int8'},
1122+
'constant': true
1123+
},
1124+
},
1125+
'operators': [
1126+
{
1127+
'name': 'quantizeLinear',
1128+
'arguments': [
1129+
{'input': 'input'},
1130+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1131+
],
1132+
'outputs': 'quantizedInput'
1133+
},
1134+
{
1135+
'name': 'dequantizeLinear',
1136+
'arguments': [
1137+
{'input': 'quantizedInput'},
1138+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1139+
],
1140+
'outputs': 'dequantizedInput'
1141+
},
1142+
{
1143+
'name': 'maxPool2d',
1144+
'arguments': [{'input': 'dequantizedInput'}, {'options': {'layout': 'nhwc'}}],
1145+
'outputs': 'maxPool2dOutput'
1146+
},
1147+
{
1148+
'name': 'quantizeLinear',
1149+
'arguments': [
1150+
{'input': 'maxPool2dOutput'},
1151+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1152+
],
1153+
'outputs': 'quantizedMaxPool2dOutput'
1154+
},
1155+
{
1156+
'name': 'dequantizeLinear',
1157+
'arguments': [
1158+
{'input': 'quantizedMaxPool2dOutput'},
1159+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1160+
],
1161+
'outputs': 'output'
1162+
}
1163+
],
1164+
'expectedOutputs': {
1165+
'output': {
1166+
'data': [
1167+
43.529415130615234,
1168+
],
1169+
'descriptor': {shape: [1, 1, 1, 1], dataType: 'float32'}
1170+
}
1171+
}
1172+
}
1173+
},
10101174
];
10111175

10121176
if (navigator.ml) {

0 commit comments

Comments
 (0)