Shortcuts

准备自定义配置

class torch.ao.quantization.fx.custom_config.PrepareCustomConfig[源代码]

自定义配置用于 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)[源代码]

从字典创建一个 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中未使用也保留的属性列表

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

Return type

PrepareCustomConfig

set_float_to_observed_mapping(float_class, observed_class, quant_type=QuantType.STATIC)[源代码]

设置从自定义浮点模块类到自定义观察模块类的映射。

观察到的模块类必须有一个 from_float 类方法,该方法将浮点模块类转换为观察到的模块类。目前这仅支持静态量化。

Return type

PrepareCustomConfig

set_input_quantized_indexes(indexes)[源代码]

设置应量化的图输入的索引。 否则,默认情况下输入被假定为fp32。

Return type

自定义配置准备

set_non_traceable_module_classes(module_classes)[源代码]

设置不可符号化追踪的模块,通过类进行标识。

Return type

PrepareCustomConfig

set_non_traceable_module_names(module_names)[源代码]

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

Return type

PrepareCustomConfig

set_output_quantized_indexes(indexes)[源代码]

设置应量化的图的输出的索引。 否则,默认情况下输出被假定为fp32。

Return type

PrepareCustomConfig

set_preserved_attributes(attributes)[源代码]

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

Return type

PrepareCustomConfig

set_standalone_module_class(module_class, qconfig_mapping, example_inputs, prepare_custom_config, backend_config)[源代码]

设置由 module_class 标识的独立模块的配置。

如果 qconfig_mapping 为 None,则将使用父级的 qconfig_mapping。 如果 prepare_custom_config 为 None,则将使用空的 PrepareCustomConfig。 如果 backend_config 为 None,则将使用父级的 backend_config

Return type

PrepareCustomConfig

set_standalone_module_name(module_name, qconfig_mapping, example_inputs, prepare_custom_config, backend_config)[源代码]

设置由 module_name 标识的独立模块的配置。

如果 qconfig_mapping 为 None,则将使用父级的 qconfig_mapping。 如果 prepare_custom_config 为 None,则将使用空的 PrepareCustomConfig。 如果 backend_config 为 None,则将使用父级的 backend_config

Return type

PrepareCustomConfig

to_dict()[源代码]

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

Return type

字典[字符串, 任意]

优云智算