评价此页

convert#

class torch.ao.quantization.convert(module, mapping=None, inplace=False, remove_qconfig=True, is_reference=False, convert_custom_config_dict=None, use_precomputed_fake_quant=False)[source]#

根据 mapping 参数,通过调用目标模块类的 from_float 方法,将输入模块中的子模块转换为不同的模块。如果 remove_qconfig 设置为 True,则最后移除 qconfig。

参数
  • module – 经过准备(prepared)和校准(calibrated)的模块

  • mapping – 一个字典,将源模块类型映射到目标模块类型,可以被覆盖以允许替换用户定义的模块

  • inplace – 就地执行模型转换,原始模块将被修改

  • convert_custom_config_dict – convert 函数的自定义配置字典

  • use_precomputed_fake_quant – 一个用于启用预计算的 fake quant 的标志

# Example of convert_custom_config_dict:
convert_custom_config_dict = {
    # user will manually define the corresponding quantized
    # module class which has a from_observed class method that converts
    # observed custom module to quantized custom module
    "observed_to_quantized_custom_module_class": {
        ObservedCustomModule: QuantizedCustomModule
    }
}