Skip to content
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

Fix/fold matmul add #584

Merged
merged 147 commits into from
May 11, 2022
Merged
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
82f7ffd
support dump quant error for layers
aaltonenzhangjizhao Sep 7, 2021
c6be91e
fix bug
aaltonenzhangjizhao Sep 7, 2021
5116e5f
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 7, 2021
a7acff0
remove useless code
aaltonenzhangjizhao Sep 7, 2021
603b174
format code
aaltonenzhangjizhao Sep 7, 2021
ab9bb7f
small change
aaltonenzhangjizhao Sep 7, 2021
8ade489
fix ofstream
aaltonenzhangjizhao Sep 7, 2021
18abf27
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 7, 2021
41da2e4
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 8, 2021
f263ae3
Merge branch 'kendryte:master' into master
aaltonenzhang Sep 8, 2021
71cfe07
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 9, 2021
ffdbe9f
refine weights quantilization with minimize mse
aaltonenzhangjizhao Sep 9, 2021
c743ba9
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Sep 9, 2021
4817e2a
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 10, 2021
46bab8d
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 14, 2021
970f8c5
Merge branch 'master' into master
aaltonenzhang Sep 14, 2021
5e3cbf1
Update config.yml
aaltonenzhang Sep 14, 2021
99ea98e
Update config.yml
aaltonenzhang Sep 15, 2021
82d7a7e
Update test_runner.py
aaltonenzhang Sep 15, 2021
13a607f
Update config.yml
aaltonenzhang Sep 15, 2021
7e1157d
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 15, 2021
b5a3b72
Merge branch 'kendryte:master' into master
aaltonenzhang Sep 15, 2021
89d8a41
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 17, 2021
c3bbcab
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 17, 2021
727fccb
Merge branch 'kendryte:master' into master
aaltonenzhang Sep 17, 2021
9bb02cb
regist evaluators for quant related IRs and support dump quant error …
aaltonenzhangjizhao Sep 17, 2021
34f02c7
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Sep 17, 2021
01af662
remove useless files
aaltonenzhangjizhao Sep 17, 2021
14d4529
remove useless file
aaltonenzhangjizhao Sep 17, 2021
a50a0a6
remove useless file
aaltonenzhangjizhao Sep 17, 2021
67df3a3
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 22, 2021
e4aed30
specify quant mode
aaltonenzhangjizhao Sep 23, 2021
9295538
fix range
aaltonenzhangjizhao Sep 23, 2021
b3ceaed
Update convolution.cpp
aaltonenzhang Sep 23, 2021
989ff7f
Update quantizer.cpp
aaltonenzhang Sep 23, 2021
fff7734
Update quantizer.cpp
aaltonenzhang Sep 24, 2021
f7f8344
Update quantizer.cpp
aaltonenzhang Sep 24, 2021
ab7fc41
snake style
aaltonenzhangjizhao Sep 24, 2021
1734fac
Update quantizer.cpp
aaltonenzhang Sep 24, 2021
f022df4
remove assert
aaltonenzhangjizhao Sep 24, 2021
9e800f8
fix data type
aaltonenzhangjizhao Sep 24, 2021
ba5dd3d
Update quantizer.cpp
aaltonenzhang Sep 24, 2021
34aacc9
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 26, 2021
ba90fb8
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 27, 2021
c25c8b0
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Sep 27, 2021
fc6ab28
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Sep 29, 2021
c9698fb
Merge branch 'kendryte:master' into master
aaltonenzhang Sep 29, 2021
d4eeccf
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 9, 2021
e5cb288
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 9, 2021
5eb3826
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 12, 2021
f997863
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 12, 2021
7ed1ddf
dump op range for import graph
aaltonenzhangjizhao Oct 13, 2021
bbe7e23
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Oct 13, 2021
f18d2e9
add count_include_pad in tflite pool importer
aaltonenzhangjizhao Oct 14, 2021
d8bbb77
revert
aaltonenzhangjizhao Oct 14, 2021
5367fd7
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 15, 2021
c271fc2
dump output range in order
aaltonenzhangjizhao Oct 15, 2021
1d2d920
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 15, 2021
1fafce8
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 18, 2021
8f3f5b6
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 18, 2021
2325f32
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 21, 2021
1eb7c9a
support dump range for noptq
aaltonenzhangjizhao Oct 22, 2021
6f5c4bf
fix test_runner
aaltonenzhangjizhao Oct 22, 2021
739b338
fix bug
aaltonenzhangjizhao Oct 22, 2021
c2bc183
format issue
aaltonenzhangjizhao Oct 25, 2021
5c3b7e5
format issue
aaltonenzhangjizhao Oct 25, 2021
15b050e
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Oct 28, 2021
878b020
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 1, 2021
f7ecc25
add k230 target in config.yml
aaltonenzhangjizhao Nov 2, 2021
2987357
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 2, 2021
b9d3fde
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 5, 2021
f362b14
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 8, 2021
47bd7ad
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 9, 2021
71baed8
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 10, 2021
89928f8
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 10, 2021
7f26861
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 12, 2021
cc5a347
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 16, 2021
fa0b208
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 17, 2021
12dd70f
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 19, 2021
98badf4
add bitcast clamp motion pass
aaltonenzhangjizhao Nov 22, 2021
291b483
apply code-format changes
aaltonenzhang Nov 22, 2021
b240636
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 22, 2021
8665a69
Merge branch 'kendryte:master' into master
aaltonenzhang Nov 23, 2021
3e1c553
add do_letterbox flag
aaltonenzhangjizhao Nov 23, 2021
c1f22bb
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Nov 23, 2021
181cf38
apply code-format changes
aaltonenzhang Nov 23, 2021
b2b9678
revert bitcast motion, do it in another branch
aaltonenzhangjizhao Nov 24, 2021
cd6ffcf
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Nov 24, 2021
1cd72a3
specify do_letterbox flag for each preprocess test cases
aaltonenzhangjizhao Nov 24, 2021
2b7ed49
fix config
aaltonenzhangjizhao Nov 24, 2021
5531139
flag for ncc
aaltonenzhangjizhao Nov 24, 2021
e15051e
use input_shpae to judge whether do letterbox or not
aaltonenzhangjizhao Nov 24, 2021
01fa001
fix typo
aaltonenzhangjizhao Nov 24, 2021
e14fd56
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 24, 2021
63a1cc3
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 26, 2021
cf8342e
Merge branch 'kendryte:master' into master
aaltonenzhang Nov 26, 2021
6db3e03
fix letterbox bug
aaltonenzhangjizhao Nov 26, 2021
94d40d1
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Nov 26, 2021
2f78119
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 29, 2021
58f2471
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Nov 30, 2021
45f0ba3
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 1, 2021
0b72808
judge input shape according to both input layout and network framewor…
aaltonenzhangjizhao Dec 1, 2021
d2bc5d6
apply code-format changes
aaltonenzhang Dec 1, 2021
f63048e
fix shape
aaltonenzhangjizhao Dec 1, 2021
44edc70
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Dec 1, 2021
13be75e
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 3, 2021
dc396c2
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 7, 2021
11d4042
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 10, 2021
27cefca
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 15, 2021
8c643f0
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 21, 2021
831a2f6
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 27, 2021
9226bdf
fix dump quant error
aaltonenzhangjizhao Dec 28, 2021
fe92381
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 30, 2021
bc8cfe7
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Dec 31, 2021
b43711e
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Jan 7, 2022
32bc700
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Jan 10, 2022
16ff924
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Jan 18, 2022
ae17b31
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Jan 24, 2022
8c9df81
dump data for each layer before and after quant
aaltonenzhangjizhao Jan 24, 2022
145cfc8
apply code-format changes
aaltonenzhang Jan 24, 2022
52329ec
fix data_dir
aaltonenzhangjizhao Jan 26, 2022
c2074e7
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao Jan 26, 2022
5ab7af3
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Feb 8, 2022
4fedcf8
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Feb 28, 2022
0481997
fix bias round issue
aaltonenzhangjizhao Feb 28, 2022
98dbb90
apply code-format changes
aaltonenzhang Feb 28, 2022
6958281
formatted
aaltonenzhangjizhao Feb 28, 2022
5b9ae96
fix data type
aaltonenzhangjizhao Feb 28, 2022
8e6f917
data type
aaltonenzhangjizhao Feb 28, 2022
477d34b
support any bits for quant
aaltonenzhangjizhao Feb 28, 2022
7d50f5c
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Mar 18, 2022
c42c753
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Mar 31, 2022
3927c45
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Apr 6, 2022
16544e1
support int16 quant
aaltonenzhangjizhao Apr 6, 2022
ede100e
do not modify src_bin now
aaltonenzhangjizhao Apr 6, 2022
7f9e262
int16 for deq
aaltonenzhangjizhao Apr 6, 2022
9a1fc0d
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Apr 26, 2022
aa54efa
support multiple input quant
aaltonenzhangjizhao Apr 26, 2022
1f57656
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao Apr 27, 2022
e7c4241
fix set_input_tensor
aaltonenzhangjizhao Apr 27, 2022
73731ca
exclude wrong model
aaltonenzhangjizhao Apr 27, 2022
7da5112
fix no inputs condition
aaltonenzhangjizhao Apr 27, 2022
85eb1f8
Merge branch 'master' into master
aaltonenzhang Apr 28, 2022
7db5744
Update test_runner.py
aaltonenzhang Apr 28, 2022
2e00968
Merge branch 'master' of github.com:aaltonenzhang/nncase
aaltonenzhangjizhao May 5, 2022
9786f00
Merge branch 'master' of github.com:kendryte/nncase
aaltonenzhangjizhao May 5, 2022
e584461
fold matmul-bitcast-add pattern
aaltonenzhangjizhao May 9, 2022
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
10 changes: 8 additions & 2 deletions src/transforms/neutral/fold_matmul_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/
#include <nncase/ir/ops/binary.h>
#include <nncase/ir/ops/bitcast.h>
#include <nncase/ir/ops/constant.h>
#include <nncase/ir/ops/matmul.h>
#include <nncase/ir/visitor.h>
Expand All @@ -26,11 +27,12 @@ bool fold_matmul_add_transform::on_try_match(node &node, transform_context &cont
{
matmul *mm = nullptr;
binary *add = nullptr;
bitcast *bc = nullptr;
constant *bias_constant = nullptr;
constant *add_constant = nullptr;
if ((add = node_cast<binary>(node))
&& (add->binary_op() == binary_add)
&& (((mm = try_get_direct_parent<matmul>(*add, 0)) && (add_constant = try_get_direct_parent<constant>(*add, 1))) || ((mm = try_get_direct_parent<matmul>(*add, 1)) && (add_constant = try_get_direct_parent<constant>(*add, 0))))
&& ((((mm = try_get_direct_parent<matmul>(*add, 0)) && (add_constant = try_get_direct_parent<constant>(*add, 1))) || ((mm = try_get_direct_parent<matmul>(*add, 1)) && (add_constant = try_get_direct_parent<constant>(*add, 0)))) || ((bc = try_get_direct_parent<bitcast>(*add, 0)) && (mm = try_get_direct_parent<matmul>(*bc)) && (add_constant = try_get_direct_parent<constant>(*add, 1))) || ((bc = try_get_direct_parent<bitcast>(*add, 1)) && (mm = try_get_direct_parent<matmul>(*bc)) && (add_constant = try_get_direct_parent<constant>(*add, 0))))
&& (mm->fused_activation() == value_range<float>::full())
&& (bias_constant = node_cast<constant>(mm->bias().connection()->owner()))
&& (bias_constant->data().size() == add_constant->data().size()))
Expand Down Expand Up @@ -79,12 +81,16 @@ void fold_matmul_add_transform::process(transform_context &context)

// create new matmul
auto new_mm = context.graph.emplace<matmul>(old_mm->input_a().shape(), old_mm->input_b().shape(), mm_act);
auto new_bc = context.graph.emplace<bitcast>(new_mm->output().type(), new_mm->output().shape(), add->output().shape());

new_bc->name(old_mm->name() + "/bitcast");
new_mm->name(old_mm->name());
new_mm->input_a().connect(*context.inputs[0]->connection());
new_mm->input_b().connect(*context.inputs[1]->connection());
new_mm->bias().connect(new_bias->output());
new_bc->input().connect(new_mm->output());

auto inputs = context.outputs[0]->connections();
for (auto &in : dup(inputs))
in->connect(new_mm->output());
in->connect(new_bc->output());
}