@@ -128,6 +128,48 @@ def test_convert(self):
128128 self .assertIsNotNone (results )
129129 paddle .disable_static ()
130130
131+ def test_convert_2times (self ):
132+ quant_model , ptq = self ._get_model_for_ptq ()
133+
134+ image = paddle .rand ([1 , 1 , 32 , 32 ], dtype = "float32" )
135+ converted_model = ptq .convert (quant_model )
136+ converted_model = ptq .convert (converted_model )
137+ out = converted_model (image )
138+ self .assertIsNotNone (out )
139+
140+ observer_count = self ._count_layers (
141+ converted_model , AbsmaxObserverLayer
142+ )
143+ quanter_count = self ._count_layers (converted_model , LinearQuanter )
144+ dequanter_count = self ._count_layers (converted_model , LinearDequanter )
145+ self .assertEqual (observer_count , 0 )
146+ self .assertEqual (dequanter_count , 14 )
147+ self .assertEqual (quanter_count , 9 )
148+
149+ save_path = os .path .join (self .temp_dir .name , 'int8_infer' )
150+ paddle .jit .save (converted_model , save_path , [image ])
151+
152+ paddle .enable_static ()
153+ exe = paddle .static .Executor (paddle .CPUPlace ())
154+ main_program = paddle .static .Program ()
155+ startup_program = paddle .static .Program ()
156+ with paddle .static .program_guard (main_program , startup_program ):
157+ [
158+ inference_program ,
159+ feed_target_names ,
160+ fetch_targets ,
161+ ] = paddle .static .load_inference_model (save_path , exe )
162+ tensor_img = np .array (
163+ np .random .random ((1 , 1 , 32 , 32 )), dtype = np .float32
164+ )
165+ results = exe .run (
166+ inference_program ,
167+ feed = {feed_target_names [0 ]: tensor_img },
168+ fetch_list = fetch_targets ,
169+ )
170+ self .assertIsNotNone (results )
171+ paddle .disable_static ()
172+
131173
132174if __name__ == '__main__' :
133175 unittest .main ()
0 commit comments