Skip to content

Commit cf04cc9

Browse files
committed
NXP backend: Remove linear output quantization in QAT
1 parent 6e49e50 commit cf04cc9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

backends/nxp/quantizer/patterns.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,16 @@ def get_anchors(
691691
output = []
692692
activation.meta["quantization_annotation"].input_qspec_map = {}
693693

694+
# In order for QAT to be numerically correct, there should be no quantization between
695+
# linear node and batch norm node.
696+
if self.is_qat:
697+
linear_users = linear_node.users
698+
possibly_bn = (
699+
list(linear_users.keys())[0] if len(linear_users) == 1 else None
700+
)
701+
if possibly_bn and _is_batch_norm(possibly_bn):
702+
output = []
703+
694704
return PartitionAnchors(
695705
inputs=[(linear_node, NodeArgsIdx(0))],
696706
weights=[(linear_node, NodeArgsIdx(1))],

0 commit comments

Comments
 (0)