Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

fail to quantize custom symbols exported from hybrid block #11794

Open
CodePlay2016 opened this issue Jul 18, 2018 · 13 comments
Open

fail to quantize custom symbols exported from hybrid block #11794

CodePlay2016 opened this issue Jul 18, 2018 · 13 comments
Labels
Bug Quantization Issues/Feature Requests related to Quantization

Comments

@CodePlay2016
Copy link

CodePlay2016 commented Jul 18, 2018

Description

when i quantized my custom symbol exported from hybrid block use the quantization tool, there will always be a duplicated output node which will lead to an error when i bind the module.

Environment info (Required)

----------Python Info----------
('Version      :', '2.7.12')
('Compiler     :', 'GCC 5.4.0 20160609')
('Build        :', ('default', 'Nov 19 2016 06:48:10'))
('Arch         :', ('64bit', 'ELF'))
------------Pip Info-----------
('Version      :', '10.0.1')
('Directory    :', '/usr/local/lib/python2.7/dist-packages/pip')
----------MXNet Info-----------
('Version      :', '1.2.0')
('Directory    :', '/usr/local/lib/python2.7/dist-packages/mxnet')
('Commit Hash   :', '297c64fd2ee404612aa3ecc880b940fb2538039c')
----------System Info----------
('Platform     :', 'Linux-4.4.0-87-generic-x86_64-with-Ubuntu-16.04-xenial')
('system       :', 'Linux')
('node         :', 'BoHong')
('release      :', '4.4.0-87-generic')
('version      :', '#110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017')
----------Hardware Info----------
('machine      :', 'x86_64')
('processor    :', 'x86_64')
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                48
On-line CPU(s) list:   0-47
Thread(s) per core:    2
Core(s) per socket:    12
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
Stepping:              1
CPU MHz:               2508.429
CPU max MHz:           2900.0000
CPU min MHz:           1200.0000
BogoMIPS:              4401.31
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              30720K
NUMA node0 CPU(s):     0-11,24-35
NUMA node1 CPU(s):     12-23,36-47
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb intel_pt tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0190 sec, LOAD: 1.5759 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0134 sec, LOAD: 9.3883 sec.
Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ubyte.gz, DNS: 0.2021 sec, LOAD: 1.9859 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0132 sec, LOAD: 1.3754 sec.
Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.4865 sec, LOAD: 3.5648 sec.
Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.4228 sec, LOAD: 1.7980 sec.

Error Message:

Traceback (most recent call last):
  File "/opt/pycharm-community-2017.3.2/helpers/pydev/pydevd.py", line 1668, in <module>
    main()
  File "/opt/pycharm-community-2017.3.2/helpers/pydev/pydevd.py", line 1662, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/opt/pycharm-community-2017.3.2/helpers/pydev/pydevd.py", line 1072, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/hfq/model_compress/prune/1611.06440/prune_mx_face/quantization.py", line 49, in <module>
    mod.bind(data_shapes=[('data', (32, 3, 96, 112))],for_training=False)
  File "/usr/local/lib/python2.7/dist-packages/mxnet/module/module.py", line 430, in bind
    state_names=self._state_names)
  File "/usr/local/lib/python2.7/dist-packages/mxnet/module/executor_group.py", line 265, in __init__
    self.bind_exec(data_shapes, label_shapes, shared_group)
  File "/usr/local/lib/python2.7/dist-packages/mxnet/module/executor_group.py", line 361, in bind_exec
    shared_group))
  File "/usr/local/lib/python2.7/dist-packages/mxnet/module/executor_group.py", line 639, in _bind_ith_exec
    shared_buffer=shared_data_arrays, **input_shapes)
  File "/usr/local/lib/python2.7/dist-packages/mxnet/symbol/symbol.py", line 1519, in simple_bind
    raise RuntimeError(error_msg)
RuntimeError: simple_bind error. Arguments:
data: (32, 3, 96, 112)
Error in operator spherenet200_dense0_fwd_dequantize: Shape inconsistent, Provided = [10574,512], inferred shape=[1]

Minimum reproducible example

    excluded_sym_names = ['spherenet200_conv0_fwd'] # exclude the first layer
    for name in sym.get_internals().list_outputs():
        if 'residual' in name:
            excluded_sym_names.append(name[:-7])
    cqsym, qarg_params, aux_params = quantize_model(sym=sym, arg_params=arg_params, aux_params=aux_params,
                                                    ctx=ctx,calib_mode='none',
                                                    excluded_sym_names=excluded_sym_names)
    cqnodes = cqsym.get_internals().list_outputs()
    for ii, name in enumerate(cqnodes):
        print ii, name
        if name == 'spherenet200_dense0_fwd_dequantize_output':
            cqfeatures = cqsym.get_internals()[:ii+1]
            break
    mod = mx.mod.Module(symbol=cqfeatures, context=ctx,label_names=None)
    mod.bind(data_shapes=[('data', (32, 3, 96, 112))],for_training=False)

Steps to reproduce

i have tried to replace the custom blocks with the original mxnet gluon block (use gluon.nn.LeakyReLU instead of custom PReLU), which could solve this problem, but i need that custom layer, so this is not a feasible solution to me.

@reminisce
Copy link
Contributor

Could you share the symbol you want to quantize?

@CodePlay2016
Copy link
Author

@reminisce I'm not sure whether u want this, and i printed sym.get_internals().list_outputs() as follow:

['data', 'spherenet200_conv0_weight', 'spherenet200_conv0_bias', 'spherenet200_conv0_fwd_output', 'spherenet200_mprelu0__maximumscalar0_output', 'spherenet200_mprelu0_alpha', 'spherenet200_mprelu0_broadcast_mul0_output', 'spherenet200_mprelu0__minimumscalar0_output', 'spherenet200_mprelu0__plus0_output', 'spherenet200_conv1_weight', 'spherenet200_conv1_bias', 'spherenet200_conv1_fwd_output', 'spherenet200_mprelu1__maximumscalar0_output', 'spherenet200_mprelu1_alpha', 'spherenet200_mprelu1_broadcast_mul0_output', 'spherenet200_mprelu1__minimumscalar0_output', 'spherenet200_mprelu1__plus0_output', 'spherenet200_conv2_weight', 'spherenet200_conv2_bias', 'spherenet200_conv2_fwd_output', 'spherenet200_mprelu2__maximumscalar0_output', 'spherenet200_mprelu2_alpha', 'spherenet200_mprelu2_broadcast_mul0_output', 'spherenet200_mprelu2__minimumscalar0_output', 'spherenet200_mprelu2__plus0_output', 'spherenet200_residual0__plus0_output', 'spherenet200_conv3_weight', 'spherenet200_conv3_bias', 'spherenet200_conv3_fwd_output', 'spherenet200_mprelu3__maximumscalar0_output', 'spherenet200_mprelu3_alpha', 'spherenet200_mprelu3_broadcast_mul0_output', 'spherenet200_mprelu3__minimumscalar0_output', 'spherenet200_mprelu3__plus0_output', 'spherenet200_conv4_weight', 'spherenet200_conv4_bias', 'spherenet200_conv4_fwd_output', 'spherenet200_mprelu4__maximumscalar0_output', 'spherenet200_mprelu4_alpha', 'spherenet200_mprelu4_broadcast_mul0_output', 'spherenet200_mprelu4__minimumscalar0_output', 'spherenet200_mprelu4__plus0_output', 'spherenet200_conv5_weight', 'spherenet200_conv5_bias', 'spherenet200_conv5_fwd_output', 'spherenet200_mprelu5__maximumscalar0_output', 'spherenet200_mprelu5_alpha', 'spherenet200_mprelu5_broadcast_mul0_output', 'spherenet200_mprelu5__minimumscalar0_output', 'spherenet200_mprelu5__plus0_output', 'spherenet200_residual1__plus0_output', 'spherenet200_conv6_weight', 'spherenet200_conv6_bias', 'spherenet200_conv6_fwd_output', 'spherenet200_mprelu6__maximumscalar0_output', 'spherenet200_mprelu6_alpha', 'spherenet200_mprelu6_broadcast_mul0_output', 'spherenet200_mprelu6__minimumscalar0_output', 'spherenet200_mprelu6__plus0_output', 'spherenet200_conv7_weight', 'spherenet200_conv7_bias', 'spherenet200_conv7_fwd_output', 'spherenet200_mprelu7__maximumscalar0_output', 'spherenet200_mprelu7_alpha', 'spherenet200_mprelu7_broadcast_mul0_output', 'spherenet200_mprelu7__minimumscalar0_output', 'spherenet200_mprelu7__plus0_output', 'spherenet200_residual2__plus0_output', 'spherenet200_conv8_weight', 'spherenet200_conv8_bias', 'spherenet200_conv8_fwd_output', 'spherenet200_mprelu8__maximumscalar0_output', 'spherenet200_mprelu8_alpha', 'spherenet200_mprelu8_broadcast_mul0_output', 'spherenet200_mprelu8__minimumscalar0_output', 'spherenet200_mprelu8__plus0_output', 'spherenet200_conv9_weight', 'spherenet200_conv9_bias', 'spherenet200_conv9_fwd_output', 'spherenet200_mprelu9__maximumscalar0_output', 'spherenet200_mprelu9_alpha', 'spherenet200_mprelu9_broadcast_mul0_output', 'spherenet200_mprelu9__minimumscalar0_output', 'spherenet200_mprelu9__plus0_output', 'spherenet200_conv10_weight', 'spherenet200_conv10_bias', 'spherenet200_conv10_fwd_output', 'spherenet200_mprelu10__maximumscalar0_output', 'spherenet200_mprelu10_alpha', 'spherenet200_mprelu10_broadcast_mul0_output', 'spherenet200_mprelu10__minimumscalar0_output', 'spherenet200_mprelu10__plus0_output', 'spherenet200_residual3__plus0_output', 'spherenet200_conv11_weight', 'spherenet200_conv11_bias', 'spherenet200_conv11_fwd_output', 'spherenet200_mprelu11__maximumscalar0_output', 'spherenet200_mprelu11_alpha', 'spherenet200_mprelu11_broadcast_mul0_output', 'spherenet200_mprelu11__minimumscalar0_output', 'spherenet200_mprelu11__plus0_output', 'spherenet200_conv12_weight', 'spherenet200_conv12_bias', 'spherenet200_conv12_fwd_output', 'spherenet200_mprelu12__maximumscalar0_output', 'spherenet200_mprelu12_alpha', 'spherenet200_mprelu12_broadcast_mul0_output', 'spherenet200_mprelu12__minimumscalar0_output', 'spherenet200_mprelu12__plus0_output', 'spherenet200_residual4__plus0_output', 'spherenet200_conv13_weight', 'spherenet200_conv13_bias', 'spherenet200_conv13_fwd_output', 'spherenet200_mprelu13__maximumscalar0_output', 'spherenet200_mprelu13_alpha', 'spherenet200_mprelu13_broadcast_mul0_output', 'spherenet200_mprelu13__minimumscalar0_output', 'spherenet200_mprelu13__plus0_output', 'spherenet200_conv14_weight', 'spherenet200_conv14_bias', 'spherenet200_conv14_fwd_output', 'spherenet200_mprelu14__maximumscalar0_output', 'spherenet200_mprelu14_alpha', 'spherenet200_mprelu14_broadcast_mul0_output', 'spherenet200_mprelu14__minimumscalar0_output', 'spherenet200_mprelu14__plus0_output', 'spherenet200_residual5__plus0_output', 'spherenet200_conv15_weight', 'spherenet200_conv15_bias', 'spherenet200_conv15_fwd_output', 'spherenet200_mprelu15__maximumscalar0_output', 'spherenet200_mprelu15_alpha', 'spherenet200_mprelu15_broadcast_mul0_output', 'spherenet200_mprelu15__minimumscalar0_output', 'spherenet200_mprelu15__plus0_output', 'spherenet200_conv16_weight', 'spherenet200_conv16_bias', 'spherenet200_conv16_fwd_output', 'spherenet200_mprelu16__maximumscalar0_output', 'spherenet200_mprelu16_alpha', 'spherenet200_mprelu16_broadcast_mul0_output', 'spherenet200_mprelu16__minimumscalar0_output', 'spherenet200_mprelu16__plus0_output', 'spherenet200_residual6__plus0_output', 'spherenet200_conv17_weight', 'spherenet200_conv17_bias', 'spherenet200_conv17_fwd_output', 'spherenet200_mprelu17__maximumscalar0_output', 'spherenet200_mprelu17_alpha', 'spherenet200_mprelu17_broadcast_mul0_output', 'spherenet200_mprelu17__minimumscalar0_output', 'spherenet200_mprelu17__plus0_output', 'spherenet200_conv18_weight', 'spherenet200_conv18_bias', 'spherenet200_conv18_fwd_output', 'spherenet200_mprelu18__maximumscalar0_output', 'spherenet200_mprelu18_alpha', 'spherenet200_mprelu18_broadcast_mul0_output', 'spherenet200_mprelu18__minimumscalar0_output', 'spherenet200_mprelu18__plus0_output', 'spherenet200_conv19_weight', 'spherenet200_conv19_bias', 'spherenet200_conv19_fwd_output', 'spherenet200_mprelu19__maximumscalar0_output', 'spherenet200_mprelu19_alpha', 'spherenet200_mprelu19_broadcast_mul0_output', 'spherenet200_mprelu19__minimumscalar0_output', 'spherenet200_mprelu19__plus0_output', 'spherenet200_residual7__plus0_output', 'spherenet200_dense0_weight', 'spherenet200_dense0_bias', 'spherenet200_dense0_fwd_output']

@reminisce
Copy link
Contributor

I need the json file/str which describes the network structure to debug. Can you provide that?

@CodePlay2016
Copy link
Author

@reminisce sure, it can be found in this repo

@reminisce
Copy link
Contributor

It contains only quantized symbol. Do you have original symbol and param files?

@CodePlay2016
Copy link
Author

CodePlay2016 commented Jul 20, 2018

@reminisce In fact that quantized symbol file is for another issue, sorry for the trouble. I have uploaded the related file to Baidu Drive(the access key is 881o) in the symbol.rar file. The original symbol and param files are named model_symbol-symbol.json and model_symbol-0000.params; The quantized symbol and param files are named model_symbol_quantized.json and model_symbol_quantized.param. What's more, the gluon hybrid block model file is named model, whose architecture is defined in the script named models.py in my repo. Thank you.

@nswamy nswamy added Quantization Issues/Feature Requests related to Quantization Bug labels Jul 21, 2018
@nswamy
Copy link
Member

nswamy commented Jul 21, 2018

@reminisce feel free to remove the Label Bug and apply the appropriate label after your analysis

@reminisce
Copy link
Contributor

@CodePlay2016 Sorry for the late reply. Can you just attach the .json file here? Baidu drive is very slow and I have difficulty in downloading 266MB file from there.

@CodePlay2016
Copy link
Author

CodePlay2016 commented Jul 26, 2018

@reminisce So i attached the symbol file before and after quantization here. Due to the upload size limit, i just couldn't upload the .params file.
model_symbol_quantized.zip
model_symbol-symbol.zip

@reminisce
Copy link
Contributor

The quantized network has duplicate dequantize operators.

It is be a bug of the quantization flow. @xinyu-intel found similar things before and has already pinpointed the place of error.

image

@xinyu-intel
Copy link
Contributor

@reminisce @CodePlay2016 a fix pr has been open and may be helpful to this issues. You can have a pre-try and if still errors please let me know. Thanks!

@vandanavk
Copy link
Contributor

@CodePlay2016 do you still see this issue?
Please feel free to close it if it is resolved.

@Will0622
Copy link

Will0622 commented Sep 26, 2018

@reminisce @xinyu-intel I still see the same bug that the quantized network has duplicate dequantize operators when I use custom symbols. Attached are the network symbols before and after quantization of a tiny example where I use the custom op only once in the network.
symbols.tar.gz

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Quantization Issues/Feature Requests related to Quantization
Projects
None yet
Development

No branches or pull requests

6 participants