Classes | |
class | QuantModuleReplacementHelper |
Functions | |
def | initialize (float_module_list=None, custom_quant_modules=None) |
def | deactivate () |
Variables | |
_quant_entry = namedtuple('quant_entry', 'orig_mod mod_name replace_mod') | |
list | _DEFAULT_QUANT_MAP |
_quant_module_helper_object = QuantModuleReplacementHelper() | |
def pytorch_quantization.quant_modules.initialize | ( | float_module_list = None , |
|
custom_quant_modules = None |
|||
) |
Dynamic module replacement using monkey patching. Dynamically monkey patches the modules with their quantized versions. Internally, the state is maintained by a helper class object which helps in replacing the original modules back. Args: float_module_list: A list. User supplied list which indicates which modules to not monkey patch. custom_quant_modules: A dict. A mapping provided by user to indicate any other module apart from torch.nn and its corresponding quantized version. Returns: nothing. Typical usage example: # Define the deny list for torch.nn modules and custom map for modules other than torch.nn. float_module_list = ["Linear"] custom_quant_modules = [(torch.nn, "Linear", quant_nn.QuantLinear)] ## Monkey patch the modules pytorch_quantization.quant_modules.initialize(float_module_list, custom_modules) ## Use the quantized modules pytorch_quantization.quant_modules.deactivate()
def pytorch_quantization.quant_modules.deactivate | ( | ) |
Dynamic module replacement which reverses the monkey patching. Dynamically replaces back the original modules that were monkey patched earlier in the initialize() function call using helper class object which maintains the state.
|
private |
|
private |
|
private |