prepare_fx
- class torch.ao.quantization.quantize_fx.prepare_fx(model, qconfig_mapping, example_inputs, prepare_custom_config=None, _equalization_config=None, backend_config=None)
Prepare a model for post training quantization
model (*) – torch.nn.Module model
qconfig_mapping (*) – QConfigMapping object to configure how a model is
quantized, see QConfigMapping
for more details
example_inputs (*) – Example inputs for forward function of the model, Tuple of positional args (keyword args can be passed as positional args as well)
prepare_custom_config (*) – customization configuration for quantization tool.
See PrepareCustomConfig for more details
_equalization_config (*) – config for specifying how to perform equalization on the model
backend_config (*) – config that specifies how operators are quantized
in a backend, this includes how the operators are observed,
supported fusion patterns, how quantize/dequantize ops are
inserted, supported dtypes etc. See BackendConfig for more details
A GraphModule with observer (configured by qconfig_mapping), ready for calibration
Example:
import torch
from torch.ao.quantization import get_default_qconfig_mapping
from torch.ao.quantization.quantize_fx import prepare_fx
class Submodule(torch.nn.Module):
def __init__(self) -> None:
super().__init__