转换 ¶
- 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][source]¶
将输入模块中的子模块转换为不同的模块,根据映射调用目标模块类的 from_float 方法。如果 remove_qconfig 设置为 True,则在最后删除 qconfig。
- 参数:
module – 准备和校准的模块
映射 – 从源模块类型到目标模块类型的映射字典,可以重写以允许交换用户定义的模块
原地执行 – 在原地执行模型转换,原始模块被修改
convert_custom_config_dict – 转换函数的自定义配置字典
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 } }