@@ -169,6 +169,56 @@ def partition_types(self):
169169 return [torch .ops .aten .relu_ .default ]
170170
171171
172+ class HardTanhPattern (QuantizationPattern ):
173+ """
174+ Quantizer for HardTanh operator. Shared quantization spec is selected, as activation functions usually follows
175+ computation layer.
176+ """
177+
178+ def partition_types (self ):
179+ return [torch .ops .aten .hardtanh .default ]
180+
181+ def get_anchors (
182+ self , gm : fx .GraphModule , fused_partition : List [fx .GraphModule ]
183+ ) -> PartitionAnchors | None :
184+ node = fused_partition [0 ].nodes [- 1 ]
185+
186+ return PartitionAnchors (
187+ inputs = [(node , 0 )],
188+ weights = [],
189+ biases = [],
190+ output = [(node ,)],
191+ )
192+
193+ def replacement_op (self ):
194+ assert False
195+
196+
197+ class HardTanhInPlacePattern (QuantizationPattern ):
198+ """
199+ Quantizer for HardTanh operator with param inplace=True. Shared quantization spec is selected, as activation
200+ functions usually follows computation layer.
201+ """
202+
203+ def partition_types (self ):
204+ return [torch .ops .aten .hardtanh_ .default ]
205+
206+ def get_anchors (
207+ self , gm : fx .GraphModule , fused_partition : List [fx .GraphModule ]
208+ ) -> PartitionAnchors | None :
209+ node = fused_partition [0 ].nodes [- 1 ]
210+
211+ return PartitionAnchors (
212+ inputs = [(node , 0 )],
213+ weights = [],
214+ biases = [],
215+ output = [(node ,)],
216+ )
217+
218+ def replacement_op (self ):
219+ assert False
220+
221+
172222class ReshapePattern (SharedSpecPattern ):
173223 """
174224 Quantizer for Reshape operator.
@@ -317,6 +367,8 @@ def __init__(self):
317367 CadenceAtenQuantizer (PermutePattern (), static_qconfig ),
318368 CadenceAtenQuantizer (PadPattern (), static_qconfig ),
319369 CadenceAtenQuantizer (ReluPattern (), static_qconfig ),
370+ CadenceAtenQuantizer (HardTanhPattern (), static_qconfig ),
371+ CadenceAtenQuantizer (HardTanhInPlacePattern (), static_qconfig ),
320372 CadenceAtenQuantizer (ReluInPlacePattern (), static_qconfig ),
321373 CadenceAtenQuantizer (AvgPoolPattern (), static_qconfig ),
322374 CadenceAtenQuantizer (ViewPattern (), static_qconfig ),
0 commit comments