评价此页

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 中未使用的属性列表

此函数主要用于向后兼容,将来可能会被删除。

返回类型

PrepareCustomConfig

set_float_to_observed_mapping(float_class, observed_class, quant_type=QuantType.STATIC)[source]#

设置自定义 float 模块类到自定义 observed 模块类的映射。

observed 模块类必须有一个 from_float 类方法,该方法将 float 模块类转换为 observed 模块类。目前仅支持静态量化。

返回类型

PrepareCustomConfig

set_input_quantized_indexes(indexes)[source]#

设置图中需要量化的输入的索引。默认情况下,输入假定为 fp32。

返回类型

PrepareCustomConfig

set_non_traceable_module_classes(module_classes)[source]#

按类设置不可符号追踪的模块。

返回类型

PrepareCustomConfig

set_non_traceable_module_names(module_names)[source]#

按名称设置不可符号追踪的模块。

返回类型

PrepareCustomConfig

set_output_quantized_indexes(indexes)[source]#

设置图中需要量化的输出的索引。默认情况下,输出假定为 fp32。

返回类型

PrepareCustomConfig

set_preserved_attributes(attributes)[source]#

设置将保留在图模块中的属性名称,即使它们未在模型的 forward 方法中使用。

返回类型

PrepareCustomConfig

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

返回类型

PrepareCustomConfig

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

返回类型

PrepareCustomConfig

to_dict()[source]#

将此 PrepareCustomConfig 转换为字典,其中包含 from_dict() 中描述的条目。

返回类型

dict[str, Any]