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。
- 返回型別