評價此頁

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]