Skip to content

Commit

Permalink
convert graph to program to let SandaloneExecutor supporrt CompiledPr…
Browse files Browse the repository at this point in the history
…ogram (#43448)

* convert graph to program to let sSandaloneExecutor supporrt CompiledProgram

* skip case that compiled_program._program is None

* execute CompiledProgram._compile to apply build_strategy
  • Loading branch information
pangyoki committed Jul 1, 2022
1 parent f1ffd59 commit 8d9f00a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions python/paddle/fluid/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down Expand Up @@ -1402,6 +1414,9 @@ def _can_use_interpreter_core(program, place):
# 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:
Expand Down Expand Up @@ -1438,6 +1453,12 @@ def _can_use_interpreter_core(program, place):
# 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ def test_compiled_program(self):
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)
Expand Down

0 comments on commit 8d9f00a

Please sign in to comment.