PrepareCustomConfig#
- class torch.ao.quantization.fx.custom_config.PrepareCustomConfig[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]#
从具有以下条目的字典创建
PrepareCustomConfig
“standalone_module_name”: (module_name, qconfig_mapping, example_inputs, child_prepare_custom_config, backend_config) 元组列表
“standalone_module_class” a list of (module_class, qconfig_mapping, example_inputs, child_prepare_custom_config, backend_config) tuples
“float_to_observed_custom_module_class”: 一个嵌套字典,将量化模式映射到内部映射,将 float 模块类映射到 observed 模块类,例如 {“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]#
设置自定义 float 模块类到自定义 observed 模块类的映射。
observed 模块类必须有一个
from_float
类方法,该方法将 float 模块类转换为 observed 模块类。目前仅支持静态量化。- 返回类型
- set_standalone_module_class(module_class, qconfig_mapping, example_inputs, prepare_custom_config, backend_config)[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]#
设置由
module_name
标识的独立模块的运行配置。如果
qconfig_mapping
为 None,则将使用父qconfig_mapping
。如果prepare_custom_config
为 None,则将使用空的PrepareCustomConfig
。如果backend_config
为 None,则将使用父backend_config
。- 返回类型