mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
0c58a017bd
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/43990 Allow user to register custom quantization and fusion patterns Test Plan: Imported from OSS Reviewed By: z-a-f Differential Revision: D23485344 fbshipit-source-id: 4f0174ee6d8000d83de0f73cb370e9a1941d54aa
58 lines
2.2 KiB
Python
58 lines
2.2 KiB
Python
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
from .quantize import *
|
|
from .observer import *
|
|
from .qconfig import *
|
|
from .fake_quantize import *
|
|
from .fuse_modules import fuse_modules
|
|
from .stubs import *
|
|
from .quant_type import *
|
|
from .quantize_jit import *
|
|
from .quantize_fx import *
|
|
from .quantization_mappings import *
|
|
from .fuser_method_mappings import *
|
|
|
|
def default_eval_fn(model, calib_data):
|
|
r"""
|
|
Default evaluation function takes a torch.utils.data.Dataset or a list of
|
|
input Tensors and run the model on the dataset
|
|
"""
|
|
for data, target in calib_data:
|
|
model(data)
|
|
|
|
_all__ = [
|
|
'QuantWrapper', 'QuantStub', 'DeQuantStub',
|
|
# Top level API for eager mode quantization
|
|
'quantize', 'quantize_dynamic', 'quantize_qat',
|
|
'prepare', 'convert', 'prepare_qat',
|
|
# Top level API for graph mode quantization on TorchScript
|
|
'quantize_jit', 'quantize_dynamic_jit',
|
|
# Top level API for graph mode quantization on GraphModule(torch.fx)
|
|
'fuse_fx', 'quantize_fx', # TODO: add quantize_dynamic_fx
|
|
'prepare_fx', 'prepare_dynamic_fx', 'convert_fx',
|
|
'QuantType', # quantization type
|
|
# custom module APIs
|
|
'register_static_quant_module_mapping',
|
|
'get_static_quant_module_mappings', 'get_static_quant_module_class',
|
|
'register_dynamic_quant_module_mapping',
|
|
'get_dynamic_quant_module_mappings',
|
|
'register_qat_module_mapping',
|
|
'get_qat_module_mappings',
|
|
'get_qconfig_propagation_list',
|
|
'get_compare_output_module_list',
|
|
'register_quantized_operator_mapping', 'get_quantized_operator',
|
|
'register_fuser_method', 'get_fuser_method',
|
|
# Sub functions for `prepare` and `swap_module`
|
|
'propagate_qconfig_', 'add_quant_dequant', 'add_observer_', 'swap_module',
|
|
'default_eval_fn', 'get_observer_dict',
|
|
'register_activation_post_process_hook',
|
|
# Observers
|
|
'ObserverBase', 'WeightObserver', 'observer', 'default_observer',
|
|
'default_weight_observer',
|
|
# QConfig
|
|
'QConfig', 'default_qconfig', 'default_dynamic_qconfig', 'float16_dynamic_qconfig',
|
|
# QAT utilities
|
|
'default_qat_qconfig', 'prepare_qat', 'quantize_qat',
|
|
# module transformations
|
|
'fuse_modules',
|
|
]
|