convert¶
- 类 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)[源][源]¶
根据 mapping 将输入模块中的子模块转换为不同的模块,通过在目标模块类上调用 from_float 方法实现。如果 remove_qconfig 设置为 True,最后会移除 qconfig。
- 参数
module – 已准备和校准的模块
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 } }