MCPcopy Create free account
hub / github.com/pytorch/executorch / quantize_module

Function quantize_module

backends/samsung/utils/export_utils.py:55–74  ·  view source on GitHub ↗
(
    module: torch.nn.Module,
    inputs,
    calibration_dataset,
    precision: Precision,
    is_per_channel: bool = True,
    is_qat: bool = False,
)

Source from the content-addressed store, hash-verified

53
54
55def quantize_module(
56 module: torch.nn.Module,
57 inputs,
58 calibration_dataset,
59 precision: Precision,
60 is_per_channel: bool = True,
61 is_qat: bool = False,
62) -> torch.nn.Module:
63 quantizer = EnnQuantizer()
64 quantizer.setup_quant_params(precision, is_per_channel, is_qat)
65 logging.info("Export nn module for quantization...")
66 exported_module = torch.export.export(module, inputs).module()
67 DecomposeScaledDotProductAttention()(exported_module)
68 logging.info("Quantizing the module...")
69 annotated_module = prepare_pt2e(exported_module, quantizer)
70 for data in calibration_dataset:
71 annotated_module(*data)
72 quantized_module = convert_pt2e(annotated_module, fold_quantize=False)
73 logging.info("Quantizing finished.")
74 return quantized_module
75
76
77def to_edge_transform_and_lower_to_enn(

Callers 10

vit.pyFile · 0.90
mobilenet_v3.pyFile · 0.90
inception_v3.pyFile · 0.90
resnet18.pyFile · 0.90
resnet50.pyFile · 0.90
inception_v4.pyFile · 0.90
wav2letter.pyFile · 0.90
edsr.pyFile · 0.90
deeplab_v3.pyFile · 0.90
mobilenet_v2.pyFile · 0.90

Calls 6

setup_quant_paramsMethod · 0.95
EnnQuantizerClass · 0.90
infoMethod · 0.80
moduleMethod · 0.80
exportMethod · 0.45

Tested by

no test coverage detected