PrepareCustomConfig¶
- class torch.ao.quantization.fx.custom_config.PrepareCustomConfig[source][source]¶
为
prepare_fx()
和prepare_qat_fx()
自定义配置。使用示例
prepare_custom_config = PrepareCustomConfig() .set_standalone_module_name("module1", qconfig_mapping, example_inputs, child_prepare_custom_config, backend_config) .set_standalone_module_class(MyStandaloneModule, qconfig_mapping, example_inputs, child_prepare_custom_config, backend_config) .set_float_to_observed_mapping(FloatCustomModule, ObservedCustomModule) .set_non_traceable_module_names(["module2", "module3"]) .set_non_traceable_module_classes([NonTraceableModule1, NonTraceableModule2]) .set_input_quantized_indexes([0]) .set_output_quantized_indexes([0]) .set_preserved_attributes(["attr1", "attr2"])
- classmethod from_dict(prepare_custom_config_dict)[source][source]¶
从具有以下项目的字典创建
PrepareCustomConfig
“standalone_module_name”:(module_name, qconfig_mapping, example_inputs, child_prepare_custom_config, backend_config) 元组列表
“standalone_module_class”:(module_class, qconfig_mapping, example_inputs, child_prepare_custom_config, backend_config) 元组列表
“float_to_observed_custom_module_class”:从量化模式到从浮点模块类到观察模块类的内部映射的嵌套字典,例如 {“static”: {FloatCustomModule: ObservedCustomModule}}
“non_traceable_module_name”:不可符号跟踪的模块名称列表 “non_traceable_module_class”:不可符号跟踪的模块类列表 “input_quantized_idxs”:应量化的图形输入索引列表 “output_quantized_idxs”:应量化的图形输出索引列表 “preserved_attributes”:即使在
forward
中未使用也持久存在的属性列表此函数主要用于向后兼容,将来可能会被删除。
- 返回类型
- set_float_to_observed_mapping(float_class, observed_class, quant_type=QuantType.STATIC)[source][source]¶
设置从自定义浮点模块类到自定义观察模块类的映射。
观察模块类必须具有
from_float
类方法,该方法将浮点模块类转换为观察模块类。目前仅静态量化支持此功能。- 返回类型
- set_preserved_attributes(attributes)[source][source]¶
设置即使在模型的
forward
方法中未使用也将在图形模块中持久存在的属性名称。- 返回类型
- set_standalone_module_class(module_class, qconfig_mapping, example_inputs, prepare_custom_config, backend_config)[source][source]¶
设置用于运行由
module_class
标识的独立模块的配置。如果
qconfig_mapping
为 None,则将改为使用父qconfig_mapping
。如果prepare_custom_config
为 None,则将使用空的PrepareCustomConfig
。如果backend_config
为 None,则将改为使用父backend_config
。- 返回类型
- set_standalone_module_name(module_name, qconfig_mapping, example_inputs, prepare_custom_config, backend_config)[source][source]¶
设置用于运行由
module_name
标识的独立模块的配置。如果
qconfig_mapping
为 None,则将改为使用父qconfig_mapping
。如果prepare_custom_config
为 None,则将使用空的PrepareCustomConfig
。如果backend_config
为 None,则将改为使用父backend_config
。- 返回类型