88
99from  typing  import  Callable , Optional , Tuple , Union 
1010
11- import  executorch .backends .test .harness .stages  as  BaseStages 
12- 
1311import  torch 
1412from  executorch .backends .test .harness .stages  import  StageType 
13+ from  executorch .backends .xnnpack .test .tester  import  RunPasses , Tester 
14+ from  executorch .backends .xnnpack .test .tester  import  Quantize  as  XNNPackQuantize 
15+ import  executorch .backends .test .harness .stages  as  BaseStages 
16+ from  executorch .backends .xnnpack .test .tester .tester  import  (
17+     ToEdgeTransformAndLower ,
18+ )
1519from  executorch .backends .xnnpack .partition .config .xnnpack_config  import  (
1620    ConfigPrecisionType ,
1721)
1822from  executorch .backends .xnnpack .partition .xnnpack_partitioner  import  (
1923    XnnpackFloatingPointPartitioner ,
2024    XnnpackPartitioner ,
2125)
22- 
23- from  executorch .backends .xnnpack .quantizer .xnnpack_quantizer  import  (
24-     get_symmetric_quantization_config ,
25- )
26- from  executorch .backends .xnnpack .test .tester  import  (
27-     Quantize  as  XNNPackQuantize ,
28-     RunPasses ,
29-     Tester ,
30- )
31- from  executorch .backends .xnnpack .test .tester .tester  import  ToEdgeTransformAndLower 
3226from  executorch .exir  import  (
3327    EdgeCompileConfig ,
3428    ExecutorchBackendConfig ,
3529    to_edge_transform_and_lower ,
3630)
31+ 
32+ from  executorch .backends .xnnpack .quantizer .xnnpack_quantizer  import  (
33+     get_symmetric_quantization_config ,
34+ )
3735from  executorch .exir .passes .external_constants_pass  import  (
3836    delegate_external_constants_pass_unlifted ,
3937)
5654    has_quantized_ops  =  False 
5755    print ("Missing quantized ops" )
5856
59- 
6057class  TestPropagateCustomMetaPass (unittest .TestCase ):
6158    class  ModuleLinear (torch .nn .Module ):
6259        def  __init__ (
@@ -99,14 +96,12 @@ def run(
9996                module = tagged_module ,
10097                gen_tag_fn = lambda  x : "model" ,  # This is the filename the weights will be saved to. In this case, weights will be saved as "model.ptd" 
10198            )
102-             self .exported_program  =  export (
103-                 tagged_module , inputs , dynamic_shapes = self .dynamic_shapes , strict = True 
104-             )
99+             self .exported_program  =  export (tagged_module , inputs , dynamic_shapes = self .dynamic_shapes , strict = True )
105100
106101    def  _test_linear (
107102        self ,
108103        partitioner : XnnpackPartitioner ,
109-         quantization_stage : Union [BaseStages .Quantize , BaseStages .Quantize_ ], 
104+         quantization_stage : Union [BaseStages .Quantize , BaseStages .Quantize_ ]
110105    ):
111106        eager_model  =  self .ModuleLinear (
112107            in_size = 1 ,
@@ -143,8 +138,8 @@ def test_quantize_(self):
143138            weight_granularity = PerGroup (32 ),
144139        )
145140        self ._test_linear (
146-             DynamicallyQuantizedPartitioner ,  BaseStages . Quantize_ ( config = linear_config ) 
147-         )
141+             DynamicallyQuantizedPartitioner ,
142+              BaseStages . Quantize_ ( config = linear_config ) )
148143
149144    def  test_pt2e_quantize (self ):
150145        # Quantize with pt2e quantize. 
@@ -157,10 +152,7 @@ def test_pt2e_quantize(self):
157152            get_symmetric_quantization_config (is_per_channel = True , is_dynamic = True ),
158153        ]
159154        partitioners  =  []
160-         for  config_precision  in  [
161-             ConfigPrecisionType .STATIC_QUANT ,
162-             ConfigPrecisionType .DYNAMIC_QUANT ,
163-         ]:
155+         for  config_precision  in  [ConfigPrecisionType .STATIC_QUANT , ConfigPrecisionType .DYNAMIC_QUANT ]:
164156            for  per_op_mode  in  [True , False ]:
165157                partitioners .append (
166158                    XnnpackPartitioner (
@@ -170,6 +162,4 @@ def test_pt2e_quantize(self):
170162                )
171163        for  quant_config  in  quant_configs :
172164            for  partitioner  in  partitioners :
173-                 self ._test_linear (
174-                     partitioner , XNNPackQuantize (quantization_config = quant_config )
175-                 )
165+                 self ._test_linear (partitioner , XNNPackQuantize (quantization_config = quant_config ))
0 commit comments