

1.34X
   


By default, users on x86 platforms will utilize the x86 quantization backend and their PyTorch programs will remain unchanged when using the default backend. Alternatively, users have the option to specify "X86" as the quantization backend explicitly. Example code is shown below:
import torch
from torch.ao.quantization import get_default_qconfig_mappingfrom torch.quantization.quantize_fx
import prepare_fx, convert_fx

# get default configuration
qconfig_mapping = get_default_qconfig_mapping()

# or explicitly specify the backend
# qengine = 'x86'
# torch.backends.quantized.engine = qengine
# qconfig_mapping = get_default_qconfig_mapping(qengine)

# construct fp32 model
model_fp32 = ...

# prepare
prepared_model = prepare_fx(model_fp32, qconfig_mapping, example_inputs=x)

# calibrate
...

# convert
quantized_model = convert_fx(prepared_model)
