ModelTC / MQBench

Model Quantization Benchmark
Apache License 2.0
755 stars 137 forks source link

How to Register a new BackendType? #6

Closed YouCaiJun98 closed 3 years ago

YouCaiJun98 commented 3 years ago

NICE work! I tried to add a new type of backend according to my quantization needs, and I get stuck with some trouble. I just add my own backend name, say, 'dummy_type' to the class BackendType in prepare_by_platform.py, like:

class BackendType(Enum):
    Academic = 'Academic'
    Tensorrt = 'Tensorrt'
    SNPE = 'SNPE'
    PPLW8A16 = 'PPLW8A16'
    NNIE = 'NNIE'
    dummy_type = 'dummy_type'

and modified the corresponding ParamsTable:

ParamsTable = {
    BackendType.dummy_type: dict(qtype='affine', ...),}

However, when I reinstalled my env(updated the mqbench pack), I got this error:

File "./miniconda3/envs/mqbench/lib/python3.7/site-packages/mqbench/prepare_by_platform.py", line 274, in prepare_qat_fx_by_platform
    quantizer = DEFAULT_MODEL_QUANTIZER[deploy_backend](extra_quantizer_dict, extra_fuse_dict)
KeyError: <BackendType.dummy_type: 'dummy_type'>

It looks like that DEFAULT_MODEL_QUANTIZER can't recognize my own backend type, and I guess I might miss some other settings. So what should I do to fix this problem? And will you release some docs to help users set their own backend type? Thanks for your help ;)

Tracin commented 3 years ago

You need to register quantizer in custom_quantizer.py in order to specify how to insert quant nodes in this platform. For test, just register it on ModelQuantizer.

YouCaiJun98 commented 3 years ago

need to register quantizer in custom_quantizer.py in order to specify how to insert quant nodes in this platform. For test, just register it on ModelQuantizer.

I found it in the repo as soon as I released my issue, anyway, thanks for your quick response XD