22
22
23
23
import paddle
24
24
from paddle import base
25
- from paddle .base import Program , Variable , core
25
+ from paddle .base import core
26
26
from paddle .base .core import AnalysisConfig , create_paddle_predictor
27
27
from paddle .base .framework import IrGraph
28
+ from paddle .static import Variable
28
29
from paddle .static .io import append_fetch_ops , prepend_feed_ops
29
30
from paddle .static .quantization import (
30
31
AddQuantDequantPass ,
@@ -39,10 +40,10 @@ class QuantDequantTest(unittest.TestCase):
39
40
def __init__ (self , methodName = 'runTest' ):
40
41
super ().__init__ (methodName )
41
42
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 ()
46
47
self .feeds = None
47
48
self .fetch_list = None
48
49
self .enable_mkldnn = False
@@ -62,10 +63,9 @@ def __init__(self, methodName='runTest'):
62
63
63
64
# from Paddle release2.1
64
65
def _normalize_program (self , program , feed_vars , fetch_vars ):
65
- if not isinstance (program , Program ):
66
+ if not isinstance (program , paddle . static . Program ):
66
67
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 )} `"
69
69
)
70
70
if not isinstance (feed_vars , list ):
71
71
feed_vars = [feed_vars ]
@@ -127,7 +127,7 @@ def _save_models(
127
127
if var .name in feeded_var_names :
128
128
feeded_vars .append (var )
129
129
130
- with base .scope_guard (scope ):
130
+ with paddle . static .scope_guard (scope ):
131
131
paddle .static .io .save_inference_model (
132
132
dirname ,
133
133
feeded_vars ,
@@ -155,7 +155,7 @@ def _get_paddle_outs(self, feed, fetch_list, executor, program, scope):
155
155
'''
156
156
Return PaddlePaddle outputs.
157
157
'''
158
- with base .scope_guard (scope ):
158
+ with paddle . static .scope_guard (scope ):
159
159
outs = executor .run (
160
160
program = program ,
161
161
feed = feed ,
@@ -245,12 +245,12 @@ def check_output_with_option(
245
245
or disable TensorRT, enable MKLDNN or disable MKLDNN
246
246
are all the same.
247
247
'''
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 ()
251
251
device = "GPU" if use_gpu else "CPU"
252
252
253
- with base .scope_guard (scope ):
253
+ with paddle . static .scope_guard (scope ):
254
254
executor .run (self .startup_program )
255
255
executor .run (self .test_startup_program )
256
256
main_graph = IrGraph (core .Graph (self .main_program .desc ), for_test = False )
@@ -274,11 +274,11 @@ def check_output_with_option(
274
274
scale_training_pass = OutScaleForTrainingPass (scope = scope , place = place )
275
275
scale_training_pass .apply (main_graph )
276
276
277
- build_strategy = base .BuildStrategy ()
277
+ build_strategy = paddle . static .BuildStrategy ()
278
278
build_strategy .memory_optimize = False
279
279
build_strategy .enable_inplace = False
280
280
build_strategy .fuse_all_reduce_ops = False
281
- binary = base .CompiledProgram (main_graph .graph )
281
+ binary = paddle . static .CompiledProgram (main_graph .graph )
282
282
283
283
iters = 10
284
284
batch_size = 1
@@ -287,7 +287,7 @@ def check_output_with_option(
287
287
batch_size = batch_size ,
288
288
)
289
289
feeder = base .DataFeeder (feed_list = [self .data , self .label ], place = place )
290
- with base .scope_guard (scope ):
290
+ with paddle . static .scope_guard (scope ):
291
291
for _ in range (iters ):
292
292
data = next (train_reader ())
293
293
loss_v = executor .run (
@@ -307,7 +307,7 @@ def check_output_with_option(
307
307
308
308
self .main_program = test_graph .to_program ()
309
309
310
- with base .scope_guard (scope ):
310
+ with paddle . static .scope_guard (scope ):
311
311
self .main_program = self ._normalize_program (
312
312
self .main_program , self .data , self .fetch_list
313
313
)
@@ -450,6 +450,6 @@ def __init__(
450
450
self .disable_trt_plugin_fp16 = disable_trt_plugin_fp16
451
451
452
452
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