convert_fx
-
class torch.ao.quantization.quantize_fx.convert_fx(graph_module, convert_custom_config=None, _remove_qconfig=True, qconfig_mapping=None, backend_config=None, keep_original_weights=False)[source] -
Преобразует откалиброванную или обученную модель в квантованную модель
- Параметры:
-
- graph_module (*) – Подготовленная и откалиброванная/обученная модель (GraphModule)
-
convert_custom_config (*) – пользовательские конфигурации для функции преобразования. Подробнее см.
ConvertCustomConfig - _remove_qconfig (*) – Параметр, позволяющий удалить атрибуты qconfig из модели после преобразования.
-
qconfig_mapping (*) –
Конфигурация, указывающая, как преобразовать модель для квантования.
Ключи должны включать ключи из qconfig_mapping, переданного в
prepare_fxилиprepare_qat_fx, с теми же значениями илиNone. Дополнительным ключам можно назначить значенияNone.Для каждой записи со значением None квантование этой записи в модели пропускается:
qconfig_mapping = QConfigMapping .set_global(qconfig_from_prepare) .set_object_type(torch.nn.functional.add, None) # skip quantizing torch.nn.functional.add .set_object_type(torch.nn.functional.linear, qconfig_from_prepare) .set_module_name("foo.bar", None) # skip quantizing module "foo.bar"-
-
backend_config (BackendConfig): A configuration for the backend which describes how -
операторы должны поддерживать квантование в бэкенде; сюда входят поддержка режимов квантования (static/dynamic/weight_only), поддержка типов данных (quint8/qint8 и т. д.), размещение наблюдателей для каждого оператора и объединённых операторов. Подробнее см.
BackendConfig
-
-
- Возвращает:
-
Квантованная модель (torch.nn.Module)
- Тип возвращаемого значения:
Пример:
# prepared_model: the model after prepare_fx/prepare_qat_fx and calibration/training # convert_fx converts a calibrated/trained model to a quantized model for the # target hardware, this includes converting the model first to a reference # quantized model, and then lower the reference quantized model to a backend # Currently, the supported backends are fbgemm (onednn), qnnpack (xnnpack) and # they share the same set of quantized operators, so we are using the same # lowering procedure # # backend_config defines the corresponding reference quantized module for # the weighted modules in the model, e.g. nn.Linear # TODO: add backend_config after we split the backend_config for fbgemm and qnnpack # e.g. backend_config = get_default_backend_config("fbgemm") quantized_model = convert_fx(prepared_model)
© 2026, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.14/generated/torch.ao.quantization.quantize_fx.convert_fx.html