评价此页

prepare#

class torch.ao.quantization.prepare(model, inplace=False, allow_list=None, observer_non_leaf_module_list=None, prepare_custom_config_dict=None)[source]#

为量化校准或量化感知训练准备模型副本。

量化配置应在 .qconfig 属性中为各个子模块预先指定。

模型将附加观察器或伪量化模块,并且 qconfig 将被传播。

参数
  • model – 输入模型,将在原地进行修改

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

  • allow_list – 可量化模块列表

  • observer_non_leaf_module_list – 我们想要添加观察器的非叶子模块列表

  • prepare_custom_config_dict – prepare 函数的自定义配置字典

# Example of prepare_custom_config_dict:
prepare_custom_config_dict = {
    # user will manually define the corresponding observed
    # module class which has a from_float class method that converts
    # float custom module to observed custom module
    "float_to_observed_custom_module_class": {CustomModule: ObservedCustomModule}
}