Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions backends/arm/quantizer/arm_quantizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,20 @@ def get_symmetric_quantization_config(
weight_observer_or_fake_quant_ctr: ObserverOrFakeQuantizeConstructor = (
MinMaxObserver
)

# Determine the right observer/fake-quant constructor
if is_qat:
# Set plain fake-quant with true min/max
weight_observer_or_fake_quant_ctr = FakeQuantize
if is_per_channel:
weight_observer_or_fake_quant_ctr = PerChannelMinMaxObserver
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need a FakeQuantize variant of this observer with qat?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. Will look into a fix and proper testing of QAT.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here #14001

else:
# 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}

weight_quantization_spec = QuantizationSpec(
dtype=torch.int8,
quant_min=weight_qmin,
Expand Down
14 changes: 9 additions & 5 deletions backends/arm/test/misc/test_bn_relu_folding_qat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ def forward(self, x: torch.Tensor):


models = {
"conv_bn_relu": ConvModule(batch_norm=True),
"conv_relu": ConvModule(batch_norm=False),
# name : (model, is_per_channel)
"conv_bn_relu_per_channel": (ConvModule(batch_norm=True), True),
"conv_relu_per_channel": (ConvModule(batch_norm=False), True),
"conv_bn_relu_per_tensor": (ConvModule(batch_norm=True), False),
"conv_relu_per_tensor": (ConvModule(batch_norm=False), False),
}


@common.parametrize("model", models)
def test_qat_tosa_INT(model: torch.nn.Module):
@common.parametrize("test_data", models)
def test_qat_tosa_INT(test_data):
model, per_channel = test_data
pipeline = TosaPipelineINT[input_t1](model, model.test_data, [], [], qtol=1)
tosa_version = conftest.get_option("tosa_version")
tosa_profiles = {
Expand All @@ -59,7 +63,7 @@ def test_qat_tosa_INT(model: torch.nn.Module):
Quantize(
quantizer=quantizer,
quantization_config=get_symmetric_quantization_config(
is_qat=True, is_per_channel=False
is_qat=True, is_per_channel=per_channel
),
is_qat=True,
),
Expand Down
Loading