评价此页

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 – 准备并校准好的模块

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

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

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

  • use_precomputed_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
    }
}