PrepareCustomConfig¶
- 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
中使用,也會保留的屬性列表此函數主要用於向後相容性,並且將來可能會被移除。
- 回傳類型
- set_float_to_observed_mapping(float_class, observed_class, quant_type=QuantType.STATIC)[原始碼][原始碼]¶
設定從自訂浮點模組類別到自訂觀察模組類別的對應。
觀察模組類別必須具有
from_float
類別方法,該方法將浮點模組類別轉換為觀察模組類別。 目前僅支援靜態量化。- 回傳類型
- 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
。- 回傳類型
- 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
。- 回傳類型