diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index d932b3f219bc2848d234498e1eda78896d027400..78c3f413966e9a16040fc32e03b1686b8bdd63f9 100755 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -411,6 +411,18 @@ def _is_enable_standalone_executor(): return flag +def _is_standalone_executor_enable_compiled_program(): + """ + Whether to use experimental executor `StandaloneExecutor` in CompiledProgram. + Convert Graph to Program. + """ + flag = False + env_val = os.environ.get('FLAGS_CONVERT_GRAPH_TO_PROGRAM', None) + if env_val in [1, '1', True, 'True', 'true']: + flag = True + return flag + + def _prepare_fleet_executor(): from ..distributed.fleet.proto import fleet_executor_desc_pb2 trainer_endpoints_str = os.getenv("PADDLE_TRAINER_ENDPOINTS", "") @@ -1402,6 +1414,9 @@ class Executor(object): # print("compiled is : {}".format(compiled)) # NOTE(zhiqiu): do not support compiled program now if compiled: + if program._program is not None and _is_standalone_executor_enable_compiled_program( + ): + return True return False # if program._is_data_parallel and len( # program._get_places(place, program._places)) == 1: @@ -1438,6 +1453,12 @@ class Executor(object): # a little bit tricy here, use inner_program before _add_feed_fetch_ops to get key # while use program to geet _StandaloneExecutor if key not in self._executor_cache._cached_executors: + if isinstance(program, compiler.CompiledProgram): + program._compile(scope, self.place) + compiled_graph = program._graph + ir_graph = framework.IrGraph(compiled_graph, + for_test=True) + inner_program = ir_graph.to_program() program = self._add_feed_fetch_ops( program=inner_program, feed=feed, diff --git a/python/paddle/fluid/tests/unittests/interpreter/test_standalone_executor.py b/python/paddle/fluid/tests/unittests/interpreter/test_standalone_executor.py index 6fa419ae282286257320045986622c95e7f89fa3..f1b1bc118eb3014c24097c267c36485df4a6fd60 100644 --- a/python/paddle/fluid/tests/unittests/interpreter/test_standalone_executor.py +++ b/python/paddle/fluid/tests/unittests/interpreter/test_standalone_executor.py @@ -382,6 +382,17 @@ class SwitchExecutorInterfaceWithFeed(unittest.TestCase): for x, y in zip(gt, res): self.assertTrue(np.array_equal(x, y)) + def test_compiled_program_convert_graph_to_program(self): + data = np.ones([2, 2], dtype="float32") + feed = {"a": data} + + os.environ['FLAGS_CONVERT_GRAPH_TO_PROGRAM'] = '1' + res = self.run_new_executor(feed, use_compiled=True) + del os.environ['FLAGS_CONVERT_GRAPH_TO_PROGRAM'] + gt = self.run_raw_executor(feed, use_compiled=True) + for x, y in zip(gt, res): + self.assertTrue(np.array_equal(x, y)) + def test_empty_program(self): program = paddle.static.Program() exe = paddle.static.Executor(self.place)