評價此頁

convert#

class torch.ao.quantization.convert(module, mapping=None, inplace=False, remove_qconfig=True, is_reference=False, convert_custom_config_dict=None, use_precomputed_fake_quant=False)[source]#

根據 mapping 引數,透過呼叫目標模組類的 from_float 方法,將輸入模組中的子模組轉換為不同的模組。如果 remove_qconfig 設定為 True,則最後移除 qconfig。

引數
  • module – 經過準備(prepared)和校準(calibrated)的模組

  • mapping – 一個字典,將源模組型別對映到目標模組型別,可以被覆蓋以允許替換使用者定義的模組

  • inplace – 就地執行模型轉換,原始模組將被修改

  • convert_custom_config_dict – convert 函式的自定義配置字典

  • use_precomputed_fake_quant – 一個用於啟用預計算的 fake quant 的標誌

# Example of convert_custom_config_dict:
convert_custom_config_dict = {
    # user will manually define the corresponding quantized
    # module class which has a from_observed class method that converts
    # observed custom module to quantized custom module
    "observed_to_quantized_custom_module_class": {
        ObservedCustomModule: QuantizedCustomModule
    }
}