Skip to content

Mrt v2 #81

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 158 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
e978a11
Merge remote-tracking branch 'origin/wlt' into ryt_tune
declmal Aug 4, 2020
6a29b77
Merge branch 'ryt_tune' of https://github.com/CortexFoundation/cvm-ru…
declmal Aug 5, 2020
d49514d
Merge remote-tracking branch 'origin/wlt' into ryt_tune
declmal Aug 10, 2020
3a28325
update feature module: optimizor, sampler, feature data types
declmal Aug 12, 2020
e6e6433
Merge remote-tracking branch 'origin/wlt' into archRev
declmal Aug 12, 2020
241c336
update module
declmal Aug 12, 2020
33c56f6
update sym_config_infos deserialize
declmal Aug 12, 2020
41eb1bd
update sym_calibrate_gen
declmal Aug 12, 2020
8a99202
Merge remote-tracking branch 'origin/wlt' into archRev
declmal Aug 12, 2020
3b94d30
enhance framework for quantize
declmal Aug 13, 2020
d8dc1ed
update
declmal Aug 13, 2020
c05af4d
update scale and quantizer
declmal Aug 15, 2020
65d9a55
update doc for quantization
declmal Aug 15, 2020
7aff300
Merge remote-tracking branch 'origin/wlt' into archRev
declmal Aug 15, 2020
4be515e
update
declmal Aug 16, 2020
873636a
update
declmal Aug 17, 2020
f09b5c7
update exp formulation for Convolutiion
declmal Aug 17, 2020
bc2dd6b
update generalized conv quantization formalization
declmal Aug 18, 2020
0f91ba3
update form: nn ops
declmal Aug 19, 2020
e614164
update doc
declmal Aug 19, 2020
c6a265d
update form
declmal Aug 19, 2020
eab1123
update
declmal Aug 19, 2020
ff5f1a1
correct formalization
declmal Aug 20, 2020
1e91b36
update
declmal Aug 20, 2020
3712f02
update types
declmal Aug 20, 2020
1fbabbf
update quantization interfaces
declmal Aug 20, 2020
f6cc3f9
quantize interfaces
declmal Aug 21, 2020
e5fe280
update
declmal Aug 21, 2020
1213bfa
update QuantInfo
declmal Aug 21, 2020
cb7b0ef
update
declmal Aug 21, 2020
81ccb0a
update quantizers
declmal Aug 24, 2020
511e61c
update
declmal Aug 24, 2020
d61354e
update quantizer
declmal Aug 25, 2020
9b803b7
create a new module: mrt.gen
declmal Aug 26, 2020
7552588
add user interface for mrt.gen
declmal Aug 26, 2020
68946a3
update
declmal Aug 26, 2020
c65ef56
update transformer
declmal Aug 26, 2020
2e060bf
rename
declmal Aug 26, 2020
518f209
update
declmal Aug 26, 2020
896cee0
Merge remote-tracking branch 'origin/ryt_tune' into archRev
declmal Aug 26, 2020
6f92b20
update
declmal Aug 26, 2020
7687298
update
declmal Aug 27, 2020
5c793cd
update example ini
declmal Aug 27, 2020
6998902
enable calibration
declmal Aug 27, 2020
4be9177
fix bugs
declmal Aug 27, 2020
273bf5a
update arch for quantize tfm_ops
declmal Aug 27, 2020
b2b3246
udpate
declmal Aug 27, 2020
180de1f
update
declmal Aug 27, 2020
5200697
update doc
declmal Aug 27, 2020
51d73aa
update
declmal Aug 27, 2020
4baed0a
update
declmal Aug 28, 2020
e5cf8d0
enable quantization
declmal Aug 28, 2020
477f14b
update form
declmal Aug 28, 2020
12fcda2
update
declmal Aug 28, 2020
0e5d194
Merge branch 'archRev' of github.com:CortexFoundation/cvm-runtime int…
declmal Aug 28, 2020
e157170
enable evaluation
declmal Aug 29, 2020
1ae7077
fix bugs for alexnet
declmal Aug 29, 2020
31c66cb
update
declmal Aug 29, 2020
471c2ef
enable slice_channel for granularity control in quantization
declmal Aug 29, 2020
117b4e9
update sym_slice
declmal Aug 31, 2020
bd0d8df
enable channel-wise quantization
declmal Aug 31, 2020
a13d6a6
unit for conv channel-wise
declmal Aug 31, 2020
5a5f583
fix bug for channel-wise Convolution
declmal Sep 1, 2020
d18a2fc
arch rev
wlt-cortex Sep 4, 2020
b407ccc
fix bug
declmal Sep 4, 2020
48da233
update
declmal Sep 4, 2020
ba55984
update
declmal Sep 7, 2020
f770e17
enable mobilenet-v1-0.25-224-lite
declmal Sep 7, 2020
250722a
enable multiple step in slicechannel
declmal Sep 7, 2020
83ac7e5
Merge branch 'archRev' of github.com:CortexFoundation/cvm-runtime int…
declmal Sep 7, 2020
4e37aab
enable restore in gen
declmal Sep 7, 2020
e0d6e42
update
declmal Sep 7, 2020
dc774b1
update
declmal Sep 8, 2020
aaaefa7
update
declmal Sep 8, 2020
031ad90
Merge remote-tracking branch 'origin/wlt' into archRev
declmal Sep 8, 2020
cecd049
update cvm_op
declmal Sep 9, 2020
3cb05c2
update channelconv
declmal Sep 9, 2020
161e0f7
fix
declmal Sep 9, 2020
856b226
update types
declmal Sep 9, 2020
8413452
update
declmal Sep 11, 2020
c87ce80
update
declmal Sep 12, 2020
a121275
Merge remote-tracking branch 'origin/wlt' into archRev
declmal Sep 12, 2020
0ec7f46
update
declmal Sep 12, 2020
a0364b8
update
declmal Sep 12, 2020
73e0a64
update channelwise conv test
declmal Sep 12, 2020
91a4c89
updatE
declmal Sep 12, 2020
b5178e9
update
declmal Sep 12, 2020
c16a8d8
fix slice_channel bugs for groupwise conv
declmal Sep 14, 2020
4e14a96
update
declmal Sep 14, 2020
331796e
update zp
declmal Sep 14, 2020
e994ed0
update doc gen
declmal Sep 14, 2020
b1b848c
uypdate
declmal Sep 14, 2020
5468479
enable zero point
declmal Sep 15, 2020
15caab1
update
declmal Sep 15, 2020
64d46a5
enable zp for broadcast_add
declmal Sep 16, 2020
60e944e
Merge branch 'zp' of github.com:CortexFoundation/cvm-runtime into zp
declmal Sep 16, 2020
317bd3d
update
declmal Sep 16, 2020
6d7f871
update
declmal Sep 16, 2020
165d167
weigt only zero point quantization
declmal Sep 16, 2020
115c822
Merge pull request #76 from CortexFoundation/zp
declmal Sep 16, 2020
1b07994
update
declmal Sep 16, 2020
84b485d
enable resnet50_v1
declmal Sep 18, 2020
54f4aa0
enable resnet50_v2
declmal Sep 18, 2020
0fcd4ea
enable resnet18_v1
declmal Sep 18, 2020
d21c6b9
enable quickdraww resnet18_v1b_0.89
declmal Sep 18, 2020
596369a
enable qd10_resnetv1_20
declmal Sep 18, 2020
f88d844
enable densenet161
declmal Sep 18, 2020
3c019d7
enable cifar_resnet20_v1
declmal Sep 18, 2020
e256374
enable mobilenet1_0
declmal Sep 18, 2020
1cad85f
enable mobilenetv2_1.0
declmal Sep 18, 2020
31dafff
enabel shufflenet
declmal Sep 18, 2020
11b853e
enable squeezenet1.0 tf_inception_v3 vgg19
declmal Sep 18, 2020
b795c98
enable trec:
declmal Sep 18, 2020
1991cb2
enable mnist
declmal Sep 21, 2020
a47e0f8
enable yolo3_darknet53_voc
declmal Sep 21, 2020
f5d0d20
enable yolo3_mobilenet1.0_voc
declmal Sep 21, 2020
aab6018
enable ssd_512_resnet50_v1_voc
declmal Sep 21, 2020
f91f731
enable ssd_512_mobilenet1.0_voc
declmal Sep 21, 2020
54d533e
enable tf models
declmal Sep 21, 2020
cc4b407
update
declmal Sep 21, 2020
0d76ffe
add slice channel settings
declmal Sep 21, 2020
f15c6db
update docs for mrt.gen.tfm_types
declmal Sep 21, 2020
3e7e509
update
declmal Sep 21, 2020
cd7b7b4
update docs for tfm_types
declmal Sep 23, 2020
b4f9b6b
update for tfm_pass
declmal Sep 23, 2020
45ae8d9
update doc for gen tfm_base
declmal Sep 23, 2020
e36c6c4
update docs for quantize tutorial
declmal Sep 23, 2020
006ca84
Merge pull request #78 from CortexFoundation/ryt_doc
declmal Sep 23, 2020
4b05904
update accuracy comparison doc
declmal Sep 25, 2020
17236cf
update
declmal Sep 25, 2020
2c3f910
update
declmal Oct 16, 2020
b5c698e
update cvm_right_shift_channel
declmal Oct 19, 2020
7bb9660
update cvm_conv_2d_channel
declmal Oct 19, 2020
1ca7c37
update cvm_conv_2d_channel prop
declmal Oct 19, 2020
feb5240
revise
declmal Oct 19, 2020
a8c35cb
update
declmal Oct 19, 2020
5bf4922
update test for slicechannel
declmal Nov 10, 2020
6b70df1
update slicechannel: fix bug for precision
declmal Nov 10, 2020
ac634a7
update
declmal Nov 10, 2020
d0c0215
update
declmal Nov 10, 2020
1cb4f7c
update
declmal Nov 11, 2020
f9dcb86
update generalized step conv
declmal Nov 11, 2020
4a34541
update
declmal Nov 13, 2020
190013a
add mobilenet1.0
declmal Nov 13, 2020
943a33b
update
declmal Nov 13, 2020
fdb5c94
update
declmal Nov 13, 2020
1557568
rename gen to v2
declmal Nov 13, 2020
6566776
rename to V2
declmal Nov 13, 2020
b51122e
update
declmal Nov 13, 2020
f561909
update
declmal Nov 13, 2020
90b5464
update transformer
declmal Nov 16, 2020
597e589
fix bug for mrt feature get_threshold
declmal Nov 16, 2020
5838897
fix bugs for exactly
declmal Nov 16, 2020
c030527
update realize_ch
declmal Nov 17, 2020
dfa9834
update realize_ch
declmal Nov 17, 2020
c765fc0
enable channelwise quantization
declmal Nov 17, 2020
20178ac
update
declmal Nov 17, 2020
b6aa1c7
fix conflict with dev
declmal Nov 17, 2020
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
Prev Previous commit
Next Next commit
update sym_slice
  • Loading branch information
declmal committed Aug 31, 2020
commit 117b4e98d104ffc2ad6d8750d974611ae48d656c
5 changes: 4 additions & 1 deletion docs/mrt/gen.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ $$
$$

$$
Xi = \text{slice}\Big(X, \text{begin=(None,)*i+(i,)+(None,)*(ndims-i-1)}, \text{end=(None,)*i+(i+1,)+(None,)*(ndims-i-1)}, \text{step=step}\Big)
Xi = \text{slice}\Big(X, \\
\text{begin=(None,)*ichannel+(i,)+(None,)*(ndims-ichannel-1)}, \\
\text{end=(None,)*ichannel+(i+step,)+(None,)*(ndims-ichannel-1)}, \\
\text{step=(-1,)*ichannel+(step_size,)+(-1,)*(ndims-ichannel-1)}\Big)
$$

If $X$ is of channel feature and $W$ is of layer feature or vice versa, $W$ (or $X$) will also be split to be compatible with $X$ (or $W$).
Expand Down
63 changes: 62 additions & 1 deletion python/mrt/gen/tfm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from mrt.tfm_pass import OUT_KEY
from .tfm_base import register_pass, register_transformer, Transformer
from .tfm_types import get_quantizer, USQuantizer, UAQuantizer, \
FT_TYPE_EXP, AFeature, SBuffer
FT_TYPE_EXP, AFeature, SBuffer, LAYER_WISE_TYPE, \
US_QUANT_TYPE
from .tfm_utils import scale_exp, get_buffer_exp

from mrt import sim_quant_helper as sim
Expand Down Expand Up @@ -119,6 +120,49 @@ def quantize(self, op, **kwargs):
@register_pass("prepare_for_compile")
@register_transformer("Convolution")
class Convolution(tops.Convolution):
def slice_channel(self, op, **kwargs):
name, op_name = op.attr('name'), op.attr('op_name')
attr, childs = op.list_attr(), sym_iter(op.get_children())
cns = [c.attr('name') for c in childs]
cfg_dict = kwargs['cfg_dict']
infer_shapes = kwargs['infer_shapes']

gn_info = cfg_dict[name]['gn_info']
ichannel, step = gn_info['ichannel'], gn_info['step']

assert len(childs) == 2
X, W = childs
xshp = infer_shapes[cns[0]][get_entry_id(childs[0])]
wshp = infer_shapes[cns[1]][get_entry_id(childs[1])]
assert len(xshp) == len(wshp) == 4 and \
xshp[1] == wshp[1] and xshp[1]%step == 0

xi_cfg_info, wi_cfg_info = cfg_dict[cns[0]], cfg_dict[cns[1]]
xi_cfg_info['gn_info'] = {'gn_type': LAYER_WISE_TYPE}
wi_cfg_info['gn_info'] = {'gn_type': LAYER_WISE_TYPE}
yi_cfg_info = {
'gn_info': {'gn_type': LAYER_WISE_TYPE},
'quant_type': US_QUANT_TYPE,
'opt_info': cfg_dict[name]['opt_info'],
}
xs = sym_slice(X, ichannel, step, **kwargs)
ws = sym_slice(W, ichannel, step, **kwargs)

nodes = []
for i in range(0, xshp[1], step):
suffix = '_' + str(i)+'-'+str(i+step)
xni = xs[i].attr('name')
cfg_dict[xni] = xi_cfg_info
wni = ws[i].attr('name')
cfg_dict[wni] = wi_cfg_info
yni = N.n(name+suffix)
Yi = get_mxnet_op(op_name)(xs[i], ws[i], **attr, name=yni)
cfg_dict[yni] = yi_cfg_info
nodes.append(Yi)

op = mx.sym.add_n(*nodes, name=name)
return op

def rewrite(self, op, **kwargs):
op = super().rewrite(op, **kwargs)
op = separate_pad(op, **kwargs)
Expand Down Expand Up @@ -312,3 +356,20 @@ def _quantize_xw(op, **kwargs):
infer_prec = kprec + xprec + wprec
precs[name][OUT_KEY] = infer_prec
return op

def sym_slice(op, ichannel, step, **kwargs):
name = op.attr('name')
shp = kwargs['infer_shapes'][name][get_entry_id(op)]
ndims = len(shp)
nodes = []
rchannel = ndims-ichannel-1
for i in range(0, shp[ichannel], step):
suffix = '_' + str(i)+'-'+str(i+step)
opi = mx.sym.slice(
op, begin=(None,)*ichannel+(i,)+(None,)*rchannel,
end=(None,)*ichannel+(i+step,)+(None,)*rchannel,
step=(-1,)*ichannel+(step,)+(-1,)*rchannel,
name=N.n(name+suffix))
nodes.append(opi)
return nodes

49 changes: 26 additions & 23 deletions python/mrt/gen/tfm_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@

from mrt import sym_utils as sutils

#----------------------------
# Channel Slice interfaces
#----------------------------

def sym_slice_channel(symbol, params, cfg_dict={}):
""" Customized graph-level topo pass definition.

Interface for granularity control.
While layer-wise feature is by default,
MRT support channel-wise features specified in cfg_dict.
"""

def _slice_channel(op, **kwargs):
name, op_name = op.attr("name"), op.attr("op_name")
gn_info = cfg_dict[name].get("gn_info", DEFAULT_GN_INFO)
gn_type = gn_info["gn_type"]
if gn_type == CHANNEL_WISE_TYPE:
op = apply_pass(
"slice_channel", cfg_dict=cfg_dict)(op, **kwargs)
return op

return topo_visit_transformer(symbol, params, _slice_channel)

#----------------------------
# Module main interfaces
#----------------------------
Expand Down Expand Up @@ -291,6 +268,32 @@ def rewrite(symbol, params):
return topo_visit_transformer(symbol, params,
apply_pass("rewrite", infer_shapes=infer_shapes))

#----------------------------
# Channel Slice interfaces
#----------------------------

@N.register_nm("slice_channel")
def sym_slice_channel(symbol, params, cfg_dict={}):
""" Customized graph-level topo pass definition.

Interface for granularity control.
While layer-wise feature is by default,
MRT support channel-wise features specified in cfg_dict.
"""
infer_shapes = infer_shape(symbol, params)

def _slice_channel(op, **kwargs):
name, op_name = op.attr("name"), op.attr("op_name")
gn_info = cfg_dict[name].get("gn_info", DEFAULT_GN_INFO)
gn_type = gn_info["gn_type"]
if gn_type == CHANNEL_WISE_TYPE:
op = apply_pass(
"slice_channel", cfg_dict=cfg_dict,
infer_shapes=infer_shapes)(op, **kwargs)
return op

return topo_visit_transformer(symbol, params, _slice_channel)

#----------------------------
# Module quantize interfaces
#----------------------------
Expand Down
6 changes: 4 additions & 2 deletions python/mrt/gen/tfm_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ def int_realize(self, data, prec, **kwargs):
" base `int_realize` function " + \
"defined in Quantizer")

US_QUANT_TYPE = "UniformSymmetric"

@register_quantizer("UniformSymmetric")

@register_quantizer(US_QUANT_TYPE)
class USQuantizer(Quantizer):
""" Information data type for uniform symmetric quantizaton
"""
Expand Down Expand Up @@ -493,7 +495,7 @@ def int_realize(self, data, prec, **kwargs):
out = out.clip(a_min=lower, a_max=upper)
return out, self.get_prec(out)

DEFAULT_QUANT_TYPE = "UniformSymmetric"
DEFAULT_QUANT_TYPE = US_QUANT_TYPE
DEFAULT_QUANTIZER = USQuantizer()

QUANT_INSTANCES = {
Expand Down