prepare¶
- class torch.ao.quantization.prepare(model, inplace=False, allow_list=None, observer_non_leaf_module_list=None, prepare_custom_config_dict=None)[source][source]¶
準備模型的副本以進行量化校準或量化感知訓練。
量化配置應搶先指派給 .qconfig 屬性中的各個子模組。
該模型將附加觀察者或偽量化模組,並且 qconfig 將被傳播。
- 參數
model – 要就地修改的輸入模型
inplace – 直接執行模型轉換,原始模組會被修改
allow_list – 可量化模組的列表
observer_non_leaf_module_list – 我們想要添加觀察者 (observer) 的非葉節點模組列表
prepare_custom_config_dict – 用於 prepare 函數的自定義配置字典
# Example of prepare_custom_config_dict: prepare_custom_config_dict = { # user will manually define the corresponding observed # module class which has a from_float class method that converts # float custom module to observed custom module "float_to_observed_custom_module_class": { CustomModule: ObservedCustomModule } }