@@ -311,30 +311,28 @@ def test_no_replace_quant_permute_dequant_with_requantize(self):
311
311
)
312
312
313
313
def test_replace_quant_view_dequant_with_requantize (self ):
314
- class M (torch .nn .Module ):
315
- def __init__ (self ):
316
- super ().__init__ ()
317
-
318
- def forward (self , x ):
319
- x = torch .ops .quantized_decomposed .quantize_per_tensor (
320
- x , 1.2 , 3 , 0 , 127 , torch .int8
321
- )
322
- x = x .view (- 1 )
323
- x = torch .ops .quantized_decomposed .dequantize_per_tensor (
324
- x , 4.5 , 6 , 0 , 127 , torch .int8
325
- )
326
- return x
327
-
328
- inputs = torch .randn (2 , 12 , 1 , 6 )
329
- model = M ()
330
- graph_module = export_to_edge (model , (inputs ,)).exported_program ().graph_module
331
- graph_module = FuseQuantDequantToRequantizePass ()(graph_module ).graph_module
332
-
314
+ builder = GraphBuilder ()
315
+ x = builder .placeholder ("x" , torch .randn (2 , 12 , 1 , 6 , dtype = torch .float32 ))
316
+ quant = builder .call_operator (
317
+ op = exir_ops .edge .quantized_decomposed .quantize_per_tensor .default ,
318
+ args = (x , 1.2 , 3 , 0 , 127 , torch .int8 ),
319
+ )
320
+ view = builder .call_operator (
321
+ op = exir_ops .edge .aten .view_copy .default , args = (quant , [- 1 ])
322
+ )
323
+ dequant = builder .call_operator (
324
+ op = exir_ops .edge .quantized_decomposed .dequantize_per_tensor .default ,
325
+ args = (view , 4.5 , 6 , 0 , 127 , torch .int8 ),
326
+ )
327
+ builder .output (dequant )
328
+ original_graph = builder .get_graph_module ()
329
+ converted_graph = FuseQuantDequantToRequantizePass ()(
330
+ original_graph
331
+ ).graph_module
333
332
self .check_op_counts (
334
- graph_module ,
333
+ converted_graph ,
335
334
expected_op_counts = {
336
- # Verify that no dequant/quant pair was replaced with requantize.
337
- # quantize -> permute -> dequantize should not be replaced with requantize.
335
+ # Verify that dequant/quant pair was replaced with requantize.
338
336
exir_ops .edge .quantized_decomposed .quantize_per_tensor .default : 0 ,
339
337
exir_ops .edge .quantized_decomposed .dequantize_per_tensor .default : 0 ,
340
338
exir_ops .edge .cadence .requantize .default : 1 ,
0 commit comments