Skip to content

Commit 7190027

Browse files
wangw-1991chromium-wpt-export-bot
authored andcommitted
[WebNN] Fuse QDQ for reduce on tflite
This CL supports fusing `dq->reduce->q` subgraph on tflite. QDQ fusion only support reduce operation with kSum, kMean, kMax and kMin kinds. Input and output operands have to be dequantized from ints8, the scale and zero point of input and output have to be scaler. Bug: 401281047 Change-Id: Ibc727be20e4ef6a9e6ba923499c5799dd8b512f5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6566130 Reviewed-by: ningxin hu <[email protected]> Commit-Queue: Wei4 Wang <[email protected]> Reviewed-by: Phillis Tang <[email protected]> Cr-Commit-Position: refs/heads/main@{#1465308}
1 parent cef1762 commit 7190027

File tree

1 file changed

+328
-0
lines changed

1 file changed

+328
-0
lines changed

webnn/conformance_tests/qdq_subgraph.https.any.js

Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,334 @@ const subgraphTests = [
18461846
}
18471847
}
18481848
},
1849+
{
1850+
'name': 'quantized reduceMax',
1851+
'graph': {
1852+
'inputs': {
1853+
'input': {
1854+
'data': [
1855+
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
1856+
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
1857+
],
1858+
'descriptor': {shape: [2, 3], dataType: 'float32'},
1859+
'constant': false
1860+
},
1861+
'inputScale': {
1862+
'data': [0.003921568859368563],
1863+
'descriptor': {shape: [1], dataType: 'float32'},
1864+
'constant': true
1865+
},
1866+
'inputZeroPoint': {
1867+
'data': [0],
1868+
'descriptor': {shape: [1], dataType: 'int8'},
1869+
'constant': true
1870+
},
1871+
'outputScale': {
1872+
'data': [0.003921568859368563],
1873+
'descriptor': {shape: [1], dataType: 'float32'},
1874+
'constant': true
1875+
},
1876+
'outputZeroPoint': {
1877+
'data': [0],
1878+
'descriptor': {shape: [1], dataType: 'int8'},
1879+
'constant': true
1880+
},
1881+
},
1882+
'operators': [
1883+
{
1884+
'name': 'quantizeLinear',
1885+
'arguments': [
1886+
{'input': 'input'},
1887+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1888+
],
1889+
'outputs': 'quantizedInput'
1890+
},
1891+
{
1892+
'name': 'dequantizeLinear',
1893+
'arguments': [
1894+
{'input': 'quantizedInput'},
1895+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1896+
],
1897+
'outputs': 'dequantizedInput'
1898+
},
1899+
{
1900+
'name': 'reduceMax',
1901+
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
1902+
'outputs': 'reduceMaxOutput'
1903+
},
1904+
{
1905+
'name': 'quantizeLinear',
1906+
'arguments': [
1907+
{'input': 'reduceMaxOutput'},
1908+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1909+
],
1910+
'outputs': 'quantizedReduceMaxOutput'
1911+
},
1912+
{
1913+
'name': 'dequantizeLinear',
1914+
'arguments': [
1915+
{'input': 'quantizedReduceMaxOutput'},
1916+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1917+
],
1918+
'outputs': 'output'
1919+
}
1920+
],
1921+
'expectedOutputs': {
1922+
'output': {
1923+
'data': [
1924+
0.49803924560546875, -0.003921568859368563,
1925+
],
1926+
'descriptor': {shape: [2], dataType: 'float32'}
1927+
}
1928+
}
1929+
}
1930+
},
1931+
{
1932+
'name': 'quantized reduceMin',
1933+
'graph': {
1934+
'inputs': {
1935+
'input': {
1936+
'data': [
1937+
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
1938+
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
1939+
],
1940+
'descriptor': {shape: [2, 3], dataType: 'float32'},
1941+
'constant': false
1942+
},
1943+
'inputScale': {
1944+
'data': [0.003921568859368563],
1945+
'descriptor': {shape: [1], dataType: 'float32'},
1946+
'constant': true
1947+
},
1948+
'inputZeroPoint': {
1949+
'data': [0],
1950+
'descriptor': {shape: [1], dataType: 'int8'},
1951+
'constant': true
1952+
},
1953+
'outputScale': {
1954+
'data': [0.003921568859368563],
1955+
'descriptor': {shape: [1], dataType: 'float32'},
1956+
'constant': true
1957+
},
1958+
'outputZeroPoint': {
1959+
'data': [0],
1960+
'descriptor': {shape: [1], dataType: 'int8'},
1961+
'constant': true
1962+
},
1963+
},
1964+
'operators': [
1965+
{
1966+
'name': 'quantizeLinear',
1967+
'arguments': [
1968+
{'input': 'input'},
1969+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1970+
],
1971+
'outputs': 'quantizedInput'
1972+
},
1973+
{
1974+
'name': 'dequantizeLinear',
1975+
'arguments': [
1976+
{'input': 'quantizedInput'},
1977+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
1978+
],
1979+
'outputs': 'dequantizedInput'
1980+
},
1981+
{
1982+
'name': 'reduceMin',
1983+
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
1984+
'outputs': 'reduceMinOutput'
1985+
},
1986+
{
1987+
'name': 'quantizeLinear',
1988+
'arguments': [
1989+
{'input': 'reduceMinOutput'},
1990+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1991+
],
1992+
'outputs': 'quantizedReduceMinOutput'
1993+
},
1994+
{
1995+
'name': 'dequantizeLinear',
1996+
'arguments': [
1997+
{'input': 'quantizedReduceMinOutput'},
1998+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
1999+
],
2000+
'outputs': 'output'
2001+
}
2002+
],
2003+
'expectedOutputs': {
2004+
'output': {
2005+
'data': [
2006+
0.0470588281750679, -0.20000001788139343,
2007+
],
2008+
'descriptor': {shape: [2], dataType: 'float32'}
2009+
}
2010+
}
2011+
}
2012+
},
2013+
{
2014+
'name': 'quantized reduceMean',
2015+
'graph': {
2016+
'inputs': {
2017+
'input': {
2018+
'data': [
2019+
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
2020+
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
2021+
],
2022+
'descriptor': {shape: [2, 3], dataType: 'float32'},
2023+
'constant': false
2024+
},
2025+
'inputScale': {
2026+
'data': [0.003921568859368563],
2027+
'descriptor': {shape: [1], dataType: 'float32'},
2028+
'constant': true
2029+
},
2030+
'inputZeroPoint': {
2031+
'data': [0],
2032+
'descriptor': {shape: [1], dataType: 'int8'},
2033+
'constant': true
2034+
},
2035+
'outputScale': {
2036+
'data': [0.003921568859368563],
2037+
'descriptor': {shape: [1], dataType: 'float32'},
2038+
'constant': true
2039+
},
2040+
'outputZeroPoint': {
2041+
'data': [0],
2042+
'descriptor': {shape: [1], dataType: 'int8'},
2043+
'constant': true
2044+
},
2045+
},
2046+
'operators': [
2047+
{
2048+
'name': 'quantizeLinear',
2049+
'arguments': [
2050+
{'input': 'input'},
2051+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
2052+
],
2053+
'outputs': 'quantizedInput'
2054+
},
2055+
{
2056+
'name': 'dequantizeLinear',
2057+
'arguments': [
2058+
{'input': 'quantizedInput'},
2059+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
2060+
],
2061+
'outputs': 'dequantizedInput'
2062+
},
2063+
{
2064+
'name': 'reduceMean',
2065+
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
2066+
'outputs': 'reduceMeanOutput'
2067+
},
2068+
{
2069+
'name': 'quantizeLinear',
2070+
'arguments': [
2071+
{'input': 'reduceMeanOutput'},
2072+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
2073+
],
2074+
'outputs': 'quantizedReduceMeanOutput'
2075+
},
2076+
{
2077+
'name': 'dequantizeLinear',
2078+
'arguments': [
2079+
{'input': 'quantizedReduceMeanOutput'},
2080+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
2081+
],
2082+
'outputs': 'output'
2083+
}
2084+
],
2085+
'expectedOutputs': {
2086+
'output': {
2087+
'data': [
2088+
0.29411765933036804, -0.09019608050584793,
2089+
],
2090+
'descriptor': {shape: [2], dataType: 'float32'}
2091+
}
2092+
}
2093+
}
2094+
},
2095+
{
2096+
'name': 'quantized reduceSum',
2097+
'graph': {
2098+
'inputs': {
2099+
'input': {
2100+
'data': [
2101+
1.6811466217041016, 0.0479511022567749, 0.33355462551116943,
2102+
-0.1988269537687301, -0.0041167140007019, -0.0634240251779556,
2103+
],
2104+
'descriptor': {shape: [2, 3], dataType: 'float32'},
2105+
'constant': false
2106+
},
2107+
'inputScale': {
2108+
'data': [0.003921568859368563],
2109+
'descriptor': {shape: [1], dataType: 'float32'},
2110+
'constant': true
2111+
},
2112+
'inputZeroPoint': {
2113+
'data': [0],
2114+
'descriptor': {shape: [1], dataType: 'int8'},
2115+
'constant': true
2116+
},
2117+
'outputScale': {
2118+
'data': [0.003921568859368563],
2119+
'descriptor': {shape: [1], dataType: 'float32'},
2120+
'constant': true
2121+
},
2122+
'outputZeroPoint': {
2123+
'data': [0],
2124+
'descriptor': {shape: [1], dataType: 'int8'},
2125+
'constant': true
2126+
},
2127+
},
2128+
'operators': [
2129+
{
2130+
'name': 'quantizeLinear',
2131+
'arguments': [
2132+
{'input': 'input'},
2133+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
2134+
],
2135+
'outputs': 'quantizedInput'
2136+
},
2137+
{
2138+
'name': 'dequantizeLinear',
2139+
'arguments': [
2140+
{'input': 'quantizedInput'},
2141+
{'scale': 'inputScale', 'zeroPoint': 'inputZeroPoint'}
2142+
],
2143+
'outputs': 'dequantizedInput'
2144+
},
2145+
{
2146+
'name': 'reduceSum',
2147+
'arguments': [{'input': 'dequantizedInput'}, {'options': {'axes': [1]}}],
2148+
'outputs': 'reduceSumOutput'
2149+
},
2150+
{
2151+
'name': 'quantizeLinear',
2152+
'arguments': [
2153+
{'input': 'reduceSumOutput'},
2154+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
2155+
],
2156+
'outputs': 'quantizedReduceSumOutput'
2157+
},
2158+
{
2159+
'name': 'dequantizeLinear',
2160+
'arguments': [
2161+
{'input': 'quantizedReduceSumOutput'},
2162+
{'scale': 'outputScale', 'zeroPoint': 'outputZeroPoint'}
2163+
],
2164+
'outputs': 'output'
2165+
}
2166+
],
2167+
'expectedOutputs': {
2168+
'output': {
2169+
'data': [
2170+
0.49803924560546875, -0.2666666805744171,
2171+
],
2172+
'descriptor': {shape: [2], dataType: 'float32'}
2173+
}
2174+
}
2175+
}
2176+
},
18492177
];
18502178

18512179
if (navigator.ml) {

0 commit comments

Comments
 (0)