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

Function get_custom_quantizer

examples/qualcomm/oss_scripts/fastvit.py:74–116  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72 pte_filename = "fastvit_qnn"
73
74 def get_custom_quantizer():
75 quantizer = make_quantizer(
76 quant_dtype=QuantDtype.use_8a8w,
77 backend=qnn_config.backend,
78 soc_model=qnn_config.soc_model,
79 )
80
81 # there are lots of outliers appearing in fastvit parameters
82 # we need to apply special configuration to saturate their impact
83 act_qspec = QuantizationSpec(
84 dtype=torch.uint8,
85 qscheme=torch.per_tensor_affine,
86 observer_or_fake_quant_ctr=MovingAverageMinMaxObserver.with_args(
87 **{"averaging_constant": 0.01}
88 ),
89 )
90 weight_qspec = QuantizationSpec(
91 dtype=torch.int8,
92 quant_min=torch.iinfo(torch.int8).min + 1,
93 quant_max=torch.iinfo(torch.int8).max,
94 qscheme=torch.per_channel_symmetric,
95 ch_axis=0,
96 observer_or_fake_quant_ctr=PerChannelParamObserverWithLossEvaluation.with_args(
97 **{"steps": 100, "use_mse": True}
98 ),
99 )
100 # rewrite default per-channel ptq config
101 quantizer.default_quant_config.per_channel_quant_config = QuantizationConfig(
102 input_activation=act_qspec,
103 output_activation=act_qspec,
104 weight=weight_qspec,
105 bias=_derived_bias_quant_spec,
106 )
107
108 # rewrite default ptq config
109 q_config = quantizer.default_quant_config.quant_config
110 quantizer.default_quant_config.quant_config = QuantizationConfig(
111 input_activation=act_qspec,
112 output_activation=act_qspec,
113 weight=q_config.weight,
114 bias=q_config.bias,
115 )
116 return quantizer
117
118 # lower to QNN
119 quantizer = {

Callers 1

mainFunction · 0.70

Calls 2

make_quantizerFunction · 0.90
QuantizationConfigClass · 0.90

Tested by

no test coverage detected