r"""Converts submodules in input module to a different module according to `mapping` by calling `from_float` method on the target module class. And remove qconfig at the end if remove_qconfig is set to True. Args: `module`: prepared and calibrated module `mapping`: a dic
(
module, mapping=None, inplace=False, remove_qconfig=True,
is_reference=False, convert_custom_config_dict=None)
| 519 | return model |
| 520 | |
| 521 | def convert( |
| 522 | module, mapping=None, inplace=False, remove_qconfig=True, |
| 523 | is_reference=False, convert_custom_config_dict=None): |
| 524 | r"""Converts submodules in input module to a different module according to `mapping` |
| 525 | by calling `from_float` method on the target module class. And remove qconfig at the |
| 526 | end if remove_qconfig is set to True. |
| 527 | |
| 528 | Args: |
| 529 | `module`: prepared and calibrated module |
| 530 | `mapping`: a dictionary that maps from source module type to target |
| 531 | module type, can be overwritten to allow swapping user defined |
| 532 | Modules |
| 533 | `inplace`: carry out model transformations in-place, the original module |
| 534 | is mutated |
| 535 | `convert_custom_config_dict`: custom configuration dictionary for convert function |
| 536 | |
| 537 | .. code-block:: python |
| 538 | |
| 539 | # Example of convert_custom_config_dict: |
| 540 | convert_custom_config_dict = { |
| 541 | # user will manually define the corresponding quantized |
| 542 | # module class which has a from_observed class method that converts |
| 543 | # observed custom module to quantized custom module |
| 544 | "observed_to_quantized_custom_module_class": { |
| 545 | ObservedCustomModule: QuantizedCustomModule |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | """ |
| 550 | torch._C._log_api_usage_once("quantization_api.quantize.convert") |
| 551 | if not inplace: |
| 552 | module = copy.deepcopy(module) |
| 553 | _convert( |
| 554 | module, mapping, inplace=True, is_reference=is_reference, |
| 555 | convert_custom_config_dict=convert_custom_config_dict) |
| 556 | if remove_qconfig: |
| 557 | _remove_qconfig(module) |
| 558 | return module |
| 559 | |
| 560 | def _convert( |
| 561 | module, mapping=None, inplace=False, |
searching dependent graphs…