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

Unable to export to torchscript and int8 model #176

Open
vishnukarthik-1994 opened this issue Feb 10, 2022 · 3 comments
Open

Unable to export to torchscript and int8 model #176

vishnukarthik-1994 opened this issue Feb 10, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@vishnukarthik-1994
Copy link

vishnukarthik-1994 commented Feb 10, 2022

Hi,

When I try to export my trained model into int8 by calling convert_and_export_predictor_method, I run into the following issue: TypeError: 'bool' object is not iterable

Reference code:

`import copy
from detectron2.data import build_detection_test_loader
from d2go.export.api import convert_and_export_predictor
from d2go.export.d2_meta_arch import patch_d2_meta_arch

import logging

previous_level = logging.root.manager.disable
logging.disable(logging.INFO)

patch_d2_meta_arch()

pytorch_model = runner.build_model(cfg, eval_only=True)
pytorch_model.cpu()

datasets = cfg.DATASETS.TRAIN[0]
data_loader = runner.build_detection_test_loader(cfg, datasets)

predictor_path = convert_and_export_predictor(
copy.deepcopy(cfg),
copy.deepcopy(pytorch_model),
"torchscript_int8@tracing",
'./',
data_loader
)

logging.disable(previous_level)`

Issue seen:

File ~\anaconda3\envs\capstone_3\lib\site-packages\torch\ao\quantization\fuser_method_mappings.py:129, in get_fuser_method(op_list, additional_fuser_method_mapping)
127 if additional_fuser_method_mapping is None:
128 additional_fuser_method_mapping = dict()
--> 129 all_mappings = get_combined_dict(DEFAULT_OP_LIST_TO_FUSER_METHOD,
130 additional_fuser_method_mapping)
131 fuser_method = all_mappings.get(op_list, None)
132 assert fuser_method is not None, "did not find fuser method for: {} ".format(op_list)

File ~\anaconda3\envs\capstone_3\lib\site-packages\torch\ao\quantization\utils.py:12, in get_combined_dict(default_dict, additional_dict)
10 def get_combined_dict(default_dict, additional_dict):
11 d = default_dict.copy()
---> 12 d.update(additional_dict)
13 return d

TypeError: 'bool' object is not iterable

Before running into this issue, I had also faced another problem in fuse_utils.py which I overcame by making this change:

    if fuser_method is None or mod_list[0].training:
        #return fuse_known_modules(mod_list, is_qat=is_qat) -> old code
        return fuse_known_modules(mod_list, is_qat)

After this change, I run into the bool object not iterable issue.

My analysis:

  1. fuse_known_modules(mod_list, is_qat) -> here is_qat is false

  2. def fuse_known_modules(mod_list, additional_fuser_method_mapping=None):

  3. fuser_method = get_fuser_method(types, additional_fuser_method_mapping)

  4. additional_fuser_method_mapping is false now as it is is_qat from the call stack.

  5. get_fuser_method calls this function:
    all_mappings = get_combined_dict(DEFAULT_OP_LIST_TO_FUSER_METHOD,
    additional_fuser_method_mapping)

  6. def get_combined_dict(default_dict, additional_dict):
    d = default_dict.copy()
    d.update(additional_dict)
    return d

Since additional_dict is additional_fuser_method_mapping which is false (a boolean), I ran into this problem.

@vishnukarthik-1994 vishnukarthik-1994 added the bug Something isn't working label Feb 10, 2022
@vishnukarthik-1994 vishnukarthik-1994 changed the title Unable to export to trochscript and int8 model Unable to export to torchscript and int8 model Feb 10, 2022
@zhanghang1989
Copy link
Contributor

@wat3rBro
Copy link
Contributor

wat3rBro commented Mar 6, 2022

Please pull the latest mobile-vision repo as it has the latest fuse_utils.py, it should solve the issue.

@yuzhuhua
Copy link

您可以使用https://github.com/facebookresearch/d2go/tree/main/demo#export-to-torchscript--int8-model上的命令吗?

I used the above command, but because I was using a custom data set, I kept getting errors. KeyError showed an unregistered data set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants