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

fail to quantize custom symbols exported from hybrid block #11794

@CodePlay2016

Description

@CodePlay2016

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugQuantizationIssues/Feature Requests related to Quantization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions