From 566bbf0c50da18725035a2f340399f1341a7de4f Mon Sep 17 00:00:00 2001 From: Ruibiao Chen Date: Mon, 15 Aug 2022 11:17:40 +0800 Subject: [PATCH] Update FLAGS for standalone executor (#45127) * Update FLAGS for standalone executor * Update FLAGS_FORCE_USE_PROGRAM_CACHE --- python/paddle/fluid/executor.py | 64 +++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index fe7f65835ed..b8f6e2eceb5 100755 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -394,19 +394,9 @@ def _to_name_str(var): def _is_enable_standalone_executor(): - """ - Whether to use experimental executor `StandaloneExecutor`. - """ - flag = False - from ..distributed.fleet import fleet - # use standalone_executor by default if not distributed - if fleet._role_maker is None and framework._enable_standalone_executor_ is None: - framework._enable_standalone_executor_ = 1 - - if framework._enable_standalone_executor_ in [1, '1', True, 'True', 'true']: - flag = True - - return flag + return framework._enable_standalone_executor_ is None or framework._enable_standalone_executor_ in [ + 1, '1', True, 'True', 'true' + ] def _prepare_fleet_executor(): @@ -1289,6 +1279,17 @@ class Executor(object): # [-0.44514108 -0.2345845 ]] """ + # Temporary FLAGS, just for testing the performance of program cache + force_use_program_cache = os.environ.get( + 'FLAGS_FORCE_USE_PROGRAM_CACHE', None) + if force_use_program_cache is not None: + use_program_cache = force_use_program_cache in [ + 1, '1', True, 'True', 'true' + ] + warnings.warn( + f"use_program_cache is force set to {use_program_cache} by FLAGS_FORCE_USE_PROGRAM_CACHE", + UserWarning) + try: res = self._run_impl(program=program, feed=feed, @@ -1399,45 +1400,70 @@ class Executor(object): place, core.CustomPlace): return False + use_standalone_executor_for_compiled_program = os.environ.get( + 'FLAGS_CONVERT_GRAPH_TO_PROGRAM', + None) in [1, '1', True, 'True', 'true'] + + # Only support fleet when 'FLAGS_CONVERT_GRAPH_TO_PROGRAM' is set to true + from paddle.distributed.fleet import fleet + if fleet._role_maker is not None and not use_standalone_executor_for_compiled_program: + warnings.warn("Standalone executor is not used for fleet", + UserWarning) + return False + compiled = isinstance(program, compiler.CompiledProgram) if compiled: # Unsupported case 1 : the CompiledProgram is constructed by Graph if program._program is None: + warnings.warn("Standalone executor is not used for Graph", + UserWarning) return False # Unsupported case 2: data parallel if program._is_data_parallel and len( program._get_places(place, program._places)) != 1: + warnings.warn( + "Standalone executor is not used for data parallel", + UserWarning) return False # Unsupported case 3 : parallel graph if core.globals()['FLAGS_enable_parallel_graph'] in [ 1, '1', True, 'True', 'true' ]: + warnings.warn( + "Standalone executor is not used for parallel graph", + UserWarning) return False # Unsupported case 4: inference if program._is_inference: + warnings.warn( + "Standalone executor is not used for inference", + UserWarning) return False # Unsupported case 5: CUDA Graph if program._build_strategy is not None and program._build_strategy.allow_cuda_graph_capture: + warnings.warn( + "Standalone executor is not used for CUDA Graph", + UserWarning) return False # Unsupported case 6: distributed if program._build_strategy is not None and ( program._build_strategy.is_distribution or program._build_strategy.num_trainers > 1): + warnings.warn( + "Standalone executor is not used for distribution", + UserWarning) return False - # Unsupported case 6 : disabled by FLAGS_CONVERT_GRAPH_TO_PROGRAM - if os.environ.get('FLAGS_CONVERT_GRAPH_TO_PROGRAM', - None) not in [1, '1', True, 'True', 'true']: - return False - - return True + return use_standalone_executor_for_compiled_program else: if isinstance(program._graph, compiler.CompiledProgram): + warnings.warn("Standalone executor is not used for Graph", + UserWarning) return False assert isinstance(program, Program) return True -- GitLab