Skip to content

Commit 637827a

Browse files
authored
Use for_test=True in the Fluid Trainer to clone the test program (#11323)
* Use for_test=True in the Fluid Trainer to clone the test program * fix typo * Should do the samething to the inferencer
1 parent 52e2eb6 commit 637827a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

python/paddle/fluid/inferencer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def __init__(self, infer_func, param_path, place=None, parallel=False):
5656
else:
5757
self.exe = executor.Executor(self.place)
5858

59+
self.inference_program = self.inference_program.clone(for_test=True)
60+
5961
def infer(self, inputs, return_numpy=True):
6062
"""
6163
:param inputs: a map of {"input_name": input_var} that will be feed into the inference program

python/paddle/fluid/trainer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def __init__(self,
115115
program_func_outs = train_func()
116116
self.train_func_outputs = program_func_outs if isinstance(
117117
program_func_outs, list) else [program_func_outs]
118-
self.test_program = self.train_program.clone()
118+
self.test_program = self.train_program.clone(for_test=True)
119119

120-
# The fisrt element of program_func_outs is loss.
120+
# The first element of program_func_outs is loss.
121121
loss = self.train_func_outputs[0]
122122

123123
optimizer = optimizer_func()

0 commit comments

Comments
 (0)