Skip to content

Commit cfcf7d5

Browse files
Marco Giordanofacebook-github-bot
authored andcommitted
Adapt sym quantizer to ET (#18870)
Summary: # Summary This diff includes a symmetric 8 bit quantizer in ET. --- #hthtemplate Reviewed By: hsharma35 Differential Revision: D91777784
1 parent 0852840 commit cfcf7d5

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

backends/cadence/aot/quantizer/quantizer.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@
9797
observer_or_fake_quant_ctr=MinMaxObserver,
9898
)
9999

100+
wgt_qspec_sym8s_127 = QuantizationSpec(
101+
dtype=torch.int8,
102+
quant_min=-127,
103+
quant_max=127,
104+
qscheme=torch.per_tensor_symmetric,
105+
is_dynamic=False,
106+
observer_or_fake_quant_ctr=MinMaxObserver,
107+
)
108+
100109
bias_qspec: Optional[QuantizationSpec] = None
101110

102111
qconfig_A8W8 = QuantizationConfig(
@@ -161,11 +170,11 @@
161170
None,
162171
)
163172

164-
qconfig_A32W8sym = QuantizationConfig(
173+
qconfig_A32W8sym_127 = QuantizationConfig(
165174
input_activation=None,
166175
output_activation=None,
167-
weight=wgt_qspec_sym8s,
168-
bias=wgt_qspec_sym8s,
176+
weight=wgt_qspec_sym8s_127,
177+
bias=wgt_qspec_sym8s_127,
169178
)
170179

171180

@@ -417,13 +426,13 @@ class CadenceW8A32MixedQuantizer(CadenceQuantizer):
417426
def __init__(self) -> None:
418427
quantizers = []
419428
quantizers.append(
420-
CadenceAtenQuantizer(MixedW8A32LinearPattern(), qconfig_A32W8sym)
429+
CadenceAtenQuantizer(MixedW8A32LinearPattern(), qconfig_A32W8sym_127)
421430
)
422431
quantizers.append(
423-
CadenceAtenQuantizer(MixedW8A32ConvPattern(), qconfig_A32W8sym)
432+
CadenceAtenQuantizer(MixedW8A32ConvPattern(), qconfig_A32W8sym_127)
424433
)
425434
quantizers.append(
426-
CadenceAtenQuantizer(MixedW8A32GruPattern(), qconfig_A32W8sym)
435+
CadenceAtenQuantizer(MixedW8A32GruPattern(), qconfig_A32W8sym_127)
427436
)
428437
super().__init__(quantizers)
429438

0 commit comments

Comments
 (0)