Shortcuts

转换

class torch.ao.quantization.convert(module, mapping=None, inplace=False, remove_qconfig=True, is_reference=False, convert_custom_config_dict=None)[源代码]

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

Parameters
  • 模块 – 准备并校准的模块

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

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

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

# 转换自定义配置字典的示例:
convert_custom_config_dict = {
    # 用户将手动定义相应的量化模块类,该类具有一个from_observed类方法,用于将观察到的自定义模块转换为量化的自定义模块
    "observed_to_quantized_custom_module_class": {
        ObservedCustomModule: QuantizedCustomModule
    }
}
优云智算