diff --git a/python/paddle/fluid/tests/unittests/eager_op_test.py b/python/paddle/fluid/tests/unittests/eager_op_test.py index 189c59e5783e3716a2aede63f3f0967c992634d9..46c612cd07584db217f2bde51b3c184f99e2fdbe 100644 --- a/python/paddle/fluid/tests/unittests/eager_op_test.py +++ b/python/paddle/fluid/tests/unittests/eager_op_test.py @@ -920,7 +920,7 @@ class OpTest(unittest.TestCase): enable_inplace=None, for_inplace_test=None, ): - with paddle.fluid.framework._dygraph_guard(None): + with paddle.static.program_guard(paddle.static.Program()): program = Program() block = program.global_block() op = self._append_ops(block) @@ -1249,7 +1249,7 @@ class OpTest(unittest.TestCase): Returns: res (tuple(outs, fetch_list, feed_map, program, op_desc)): The results of given grad_op_desc. """ - with paddle.fluid.framework._dygraph_guard(None): + with paddle.static.program_guard(paddle.static.Program()): ( fwd_outs, fwd_fetch_list, @@ -2360,7 +2360,7 @@ class OpTest(unittest.TestCase): user_defined_grad_outputs=None, parallel=False, ): - with paddle.fluid.framework._dygraph_guard(None): + with paddle.static.program_guard(paddle.static.Program()): prog = Program() scope = core.Scope() block = prog.global_block() diff --git a/python/paddle/fluid/tests/unittests/op_test.py b/python/paddle/fluid/tests/unittests/op_test.py index 1e3170dfc97a0a93311e1387923326419f010c4b..81a2cb12f7fcc24a1c896ab852216220a0a79c13 100644 --- a/python/paddle/fluid/tests/unittests/op_test.py +++ b/python/paddle/fluid/tests/unittests/op_test.py @@ -930,7 +930,7 @@ class OpTest(unittest.TestCase): enable_inplace=None, for_inplace_test=None, ): - with paddle.fluid.framework._dygraph_guard(None): + with paddle.static.program_guard(paddle.static.Program()): program = Program() block = program.global_block() op = self._append_ops(block) @@ -1259,7 +1259,7 @@ class OpTest(unittest.TestCase): Returns: res (tuple(outs, fetch_list, feed_map, program, op_desc)): The results of given grad_op_desc. """ - with paddle.fluid.framework._dygraph_guard(None): + with paddle.static.program_guard(paddle.static.Program()): ( fwd_outs, fwd_fetch_list, @@ -2472,7 +2472,7 @@ class OpTest(unittest.TestCase): user_defined_grad_outputs=None, parallel=False, ): - with paddle.fluid.framework._dygraph_guard(None): + with paddle.static.program_guard(paddle.static.Program()): prog = Program() scope = core.Scope() block = prog.global_block() diff --git a/python/paddle/fluid/tests/unittests/prim_op_test.py b/python/paddle/fluid/tests/unittests/prim_op_test.py index fb5b8e5088b8e146ee0d14cfa2af2465dfc66908..7d9c706801b2acd205fc7f20b96f4cad9d037104 100644 --- a/python/paddle/fluid/tests/unittests/prim_op_test.py +++ b/python/paddle/fluid/tests/unittests/prim_op_test.py @@ -244,7 +244,7 @@ class PrimForwardChecker: def init_checker(self): assert hasattr( self.op_test, 'prim_op_type' - ), "if you want to test comp op, please set prim_op_type in setUp function." + ), "if you want to test comp op, please set prim_op_type with \'prim\' or \'comp\' in setUp function." assert self.op_test.prim_op_type in [ "comp", "prim", @@ -786,11 +786,12 @@ class PrimGradChecker(PrimForwardChecker): self.recover_eager_or_static_status() def get_output_dict(self, np_outputs, api_outputs, outputs_sig): - assert len(api_outputs) == len(outputs_sig), ( - "forward api outputs length must be the same as KernelSignature outputs,but recive %s and %s" + assert len(api_outputs) <= len(outputs_sig), ( + "forward api outputs length must be the less than or equal to KernelSignature outputs,but recive %s and %s" ) % (len(api_outputs), len(outputs_sig)) output_dict = {} - for i, output_name in enumerate(outputs_sig): + for i in range(len(api_outputs)): + output_name = outputs_sig[i] if isinstance(np_outputs[output_name], list): for j, tup in enumerate(np_outputs[output_name]): output_dict.update({tup[0]: api_outputs[i][j]})