Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions backends/arm/quantizer/arm_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
HistogramObserver,
MinMaxObserver,
MovingAverageMinMaxObserver,
MovingAveragePerChannelMinMaxObserver,
ObserverOrFakeQuantizeConstructor,
PerChannelMinMaxObserver,
PlaceholderObserver,
Expand Down Expand Up @@ -95,24 +94,26 @@ def get_symmetric_quantization_config(
**extra_args,
),
)

# Setup quantization config for weights
weight_qscheme = (
torch.per_channel_symmetric if is_per_channel else torch.per_tensor_symmetric
)
weight_observer_or_fake_quant_ctr: ObserverOrFakeQuantizeConstructor = (
MinMaxObserver
)
# Determine the right observer/fake-quant constructor
if is_qat:
# TODO: qat + per channel?
weight_observer_or_fake_quant_ctr = FusedMovingAvgObsFakeQuantize
elif is_per_channel:
weight_observer_or_fake_quant_ctr = PerChannelMinMaxObserver
# Set plain fake-quant with true min/max
weight_observer_or_fake_quant_ctr = FakeQuantize
else:
# PTQ: set min/max observer
weight_observer_or_fake_quant_ctr = (
PerChannelMinMaxObserver if is_per_channel else MinMaxObserver
)

extra_args = {"eps": 2**-12}

extra_args: Dict[str, Any] = {"eps": 2**-12}
if is_qat:
if weight_qscheme == torch.per_tensor_symmetric:
extra_args["observer"] = MovingAverageMinMaxObserver
else:
extra_args["observer"] = MovingAveragePerChannelMinMaxObserver # type: ignore[dict-item]
weight_quantization_spec = QuantizationSpec(
dtype=torch.int8,
quant_min=weight_qmin,
Expand Down
Loading