2222
2323import paddle
2424from paddle import base
25- from paddle .base import Program , Variable , core
25+ from paddle .base import core
2626from paddle .base .core import AnalysisConfig , create_paddle_predictor
2727from paddle .base .framework import IrGraph
28+ from paddle .static import Variable
2829from paddle .static .io import append_fetch_ops , prepend_feed_ops
2930from paddle .static .quantization import (
3031 AddQuantDequantPass ,
@@ -39,10 +40,10 @@ class QuantDequantTest(unittest.TestCase):
3940 def __init__ (self , methodName = 'runTest' ):
4041 super ().__init__ (methodName )
4142 paddle .enable_static ()
42- self .main_program = base .Program ()
43- self .startup_program = base .Program ()
44- self .test_main_program = base .Program ()
45- self .test_startup_program = base .Program ()
43+ self .main_program = paddle . static .Program ()
44+ self .startup_program = paddle . static .Program ()
45+ self .test_main_program = paddle . static .Program ()
46+ self .test_startup_program = paddle . static .Program ()
4647 self .feeds = None
4748 self .fetch_list = None
4849 self .enable_mkldnn = False
@@ -62,10 +63,9 @@ def __init__(self, methodName='runTest'):
6263
6364 # from Paddle release2.1
6465 def _normalize_program (self , program , feed_vars , fetch_vars ):
65- if not isinstance (program , Program ):
66+ if not isinstance (program , paddle . static . Program ):
6667 raise TypeError (
67- "program type must be `base.Program`, but received `%s`"
68- % type (program )
68+ f"program type must be `paddle.static.Program`, but received `{ type (program )} `"
6969 )
7070 if not isinstance (feed_vars , list ):
7171 feed_vars = [feed_vars ]
@@ -127,7 +127,7 @@ def _save_models(
127127 if var .name in feeded_var_names :
128128 feeded_vars .append (var )
129129
130- with base .scope_guard (scope ):
130+ with paddle . static .scope_guard (scope ):
131131 paddle .static .io .save_inference_model (
132132 dirname ,
133133 feeded_vars ,
@@ -155,7 +155,7 @@ def _get_paddle_outs(self, feed, fetch_list, executor, program, scope):
155155 '''
156156 Return PaddlePaddle outputs.
157157 '''
158- with base .scope_guard (scope ):
158+ with paddle . static .scope_guard (scope ):
159159 outs = executor .run (
160160 program = program ,
161161 feed = feed ,
@@ -245,12 +245,12 @@ def check_output_with_option(
245245 or disable TensorRT, enable MKLDNN or disable MKLDNN
246246 are all the same.
247247 '''
248- place = base .CUDAPlace (0 ) if use_gpu else base .CPUPlace ()
249- executor = base .Executor (place )
250- scope = base .Scope ()
248+ place = paddle .CUDAPlace (0 ) if use_gpu else paddle .CPUPlace ()
249+ executor = paddle . static .Executor (place )
250+ scope = paddle . static .Scope ()
251251 device = "GPU" if use_gpu else "CPU"
252252
253- with base .scope_guard (scope ):
253+ with paddle . static .scope_guard (scope ):
254254 executor .run (self .startup_program )
255255 executor .run (self .test_startup_program )
256256 main_graph = IrGraph (core .Graph (self .main_program .desc ), for_test = False )
@@ -274,11 +274,11 @@ def check_output_with_option(
274274 scale_training_pass = OutScaleForTrainingPass (scope = scope , place = place )
275275 scale_training_pass .apply (main_graph )
276276
277- build_strategy = base .BuildStrategy ()
277+ build_strategy = paddle . static .BuildStrategy ()
278278 build_strategy .memory_optimize = False
279279 build_strategy .enable_inplace = False
280280 build_strategy .fuse_all_reduce_ops = False
281- binary = base .CompiledProgram (main_graph .graph )
281+ binary = paddle . static .CompiledProgram (main_graph .graph )
282282
283283 iters = 10
284284 batch_size = 1
@@ -287,7 +287,7 @@ def check_output_with_option(
287287 batch_size = batch_size ,
288288 )
289289 feeder = base .DataFeeder (feed_list = [self .data , self .label ], place = place )
290- with base .scope_guard (scope ):
290+ with paddle . static .scope_guard (scope ):
291291 for _ in range (iters ):
292292 data = next (train_reader ())
293293 loss_v = executor .run (
@@ -307,7 +307,7 @@ def check_output_with_option(
307307
308308 self .main_program = test_graph .to_program ()
309309
310- with base .scope_guard (scope ):
310+ with paddle . static .scope_guard (scope ):
311311 self .main_program = self ._normalize_program (
312312 self .main_program , self .data , self .fetch_list
313313 )
@@ -450,6 +450,6 @@ def __init__(
450450 self .disable_trt_plugin_fp16 = disable_trt_plugin_fp16
451451
452452 def quant_dequant (self ):
453- place = base .CPUPlace ()
454- exe = base .Executor (place )
455- scope = base .Scope ()
453+ place = paddle .CPUPlace ()
454+ exe = paddle . static .Executor (place )
455+ scope = paddle . static .Scope ()
0 commit comments