Skip to content

[WebNN] Fuse QDQ for reduce on tflite #52672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
328 changes: 328 additions & 0 deletions webnn/conformance_tests/qdq_subgraph.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,334 @@ const subgraphTests = [
}
}
},
{
'name': 'quantized reduceMax',
'graph': {
'inputs': {
'input': {
'data': [
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
],
'descriptor': {shape: [2, 3], dataType: 'float32'},
'constant': false
},
'inputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'inputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
'outputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'outputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
},
'operators': [
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'input'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'quantizedInput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedInput'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'dequantizedInput'
},
{
'name': 'reduceMax',
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
'outputs': 'reduceMaxOutput'
},
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'reduceMaxOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'quantizedReduceMaxOutput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedReduceMaxOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'output'
}
],
'expectedOutputs': {
'output': {
'data': [
0.49803924560546875, -0.003921568859368563,
],
'descriptor': {shape: [2], dataType: 'float32'}
}
}
}
},
{
'name': 'quantized reduceMin',
'graph': {
'inputs': {
'input': {
'data': [
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
],
'descriptor': {shape: [2, 3], dataType: 'float32'},
'constant': false
},
'inputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'inputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
'outputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'outputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
},
'operators': [
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'input'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'quantizedInput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedInput'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'dequantizedInput'
},
{
'name': 'reduceMin',
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
'outputs': 'reduceMinOutput'
},
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'reduceMinOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'quantizedReduceMinOutput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedReduceMinOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'output'
}
],
'expectedOutputs': {
'output': {
'data': [
0.0470588281750679, -0.20000001788139343,
],
'descriptor': {shape: [2], dataType: 'float32'}
}
}
}
},
{
'name': 'quantized reduceMean',
'graph': {
'inputs': {
'input': {
'data': [
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
],
'descriptor': {shape: [2, 3], dataType: 'float32'},
'constant': false
},
'inputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'inputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
'outputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'outputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
},
'operators': [
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'input'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'quantizedInput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedInput'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'dequantizedInput'
},
{
'name': 'reduceMean',
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
'outputs': 'reduceMeanOutput'
},
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'reduceMeanOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'quantizedReduceMeanOutput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedReduceMeanOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'output'
}
],
'expectedOutputs': {
'output': {
'data': [
0.29411765933036804, -0.09019608050584793,
],
'descriptor': {shape: [2], dataType: 'float32'}
}
}
}
},
{
'name': 'quantized reduceSum',
'graph': {
'inputs': {
'input': {
'data': [
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
],
'descriptor': {shape: [2, 3], dataType: 'float32'},
'constant': false
},
'inputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'inputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
'outputScale': {
'data': [0.003921568859368563],
'descriptor': {shape: [1], dataType: 'float32'},
'constant': true
},
'outputZeroPoint': {
'data': [0],
'descriptor': {shape: [1], dataType: 'int8'},
'constant': true
},
},
'operators': [
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'input'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'quantizedInput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedInput'},
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
],
'outputs': 'dequantizedInput'
},
{
'name': 'reduceSum',
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
'outputs': 'reduceSumOutput'
},
{
'name': 'quantizeLinear',
'arguments': [
{'input': 'reduceSumOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'quantizedReduceSumOutput'
},
{
'name': 'dequantizeLinear',
'arguments': [
{'input': 'quantizedReduceSumOutput'},
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
],
'outputs': 'output'
}
],
'expectedOutputs': {
'output': {
'data': [
0.49803924560546875, -0.2666666805744171,
],
'descriptor': {shape: [2], dataType: 'float32'}
}
}
}
},
];

if (navigator.ml) {
Expand Down