Skip to content

Commit

Permalink
remove static.ExecutionStrategy api
Browse files Browse the repository at this point in the history
  • Loading branch information
ccsuzzh committed Apr 4, 2024
1 parent b0a10db commit 11469cb
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 128 deletions.
1 change: 0 additions & 1 deletion python/paddle/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
from .compiler import ( # noqa: F401
BuildStrategy,
CompiledProgram,
ExecutionStrategy,
IpuCompiledProgram,
IpuStrategy,
)
Expand Down
28 changes: 0 additions & 28 deletions python/paddle/base/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
# limitations under the License.

import sys
import warnings

from . import core, framework
from .framework import cpu_places, cuda_places, xpu_places

__all__ = []

ExecutionStrategy = core.ParallelExecutor.ExecutionStrategy
BuildStrategy = core.ParallelExecutor.BuildStrategy
InferNativeConfig = core.NativeConfig
InferAnalysisConfig = core.AnalysisConfig
Expand Down Expand Up @@ -210,32 +208,6 @@ def _compile_data_parallel(self, places, use_device, scope=None):
self._build_strategy = BuildStrategy()
self._build_strategy.is_distribution = _is_pserver_mode(self._program)

if self._exec_strategy is None:
self._exec_strategy = ExecutionStrategy()
self._exec_strategy._use_device = use_device

if self._exec_strategy.num_threads == 0:
if self._exec_strategy._use_device == DeviceType.CUDA:
# Experiments on se-resnext shows that too many threads hurt
# performance. Worth tunning for other models in the future.
self._exec_strategy.num_threads = len(places) * 4
elif self._exec_strategy._use_device == DeviceType.XPU:
# Currently only single thread is supported in Kunlun XPU.
self._exec_strategy.num_threads = 1
else:
self._exec_strategy.num_threads = len(places) * 2

if (
"FLAGS_use_cinn" in core.globals()
and core.globals()["FLAGS_use_cinn"]
and self._exec_strategy.num_threads != 1
):
warnings.warn(
"At present, when CINN is turned on, each process can "
"only contain one thread, so reset the number of threads to 1 here."
)
self._exec_strategy.num_threads = 1

# TODO(wuyi): trainer endpoints should be passed in through
# build_strategy, not program.xxx.
# TODO(gongwb): let user to set them once.
Expand Down
53 changes: 2 additions & 51 deletions python/paddle/distributed/fleet/base/distributed_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,45 +262,6 @@ def load_from_prototxt(self, pb_file):
str(f.read()), self.strategy
)

@property
def execution_strategy(self):
"""
Configure ExecutionStrategy for DistributedStrategy
Examples:
.. code-block:: python
>>> import paddle
>>> exe_strategy = paddle.static.ExecutionStrategy()
>>> exe_strategy.num_threads = 10
>>> exe_strategy.num_iteration_per_drop_scope = 10
>>> exe_strategy.num_iteration_per_run = 10
>>> strategy = paddle.distributed.fleet.DistributedStrategy()
>>> strategy.execution_strategy = exe_strategy
"""
execution_strategy = paddle.static.ExecutionStrategy()
fields = self.strategy.execution_strategy.DESCRIPTOR.fields
for f in fields:
setattr(
execution_strategy,
f.name,
getattr(self.strategy.execution_strategy, f.name),
)
return execution_strategy

@execution_strategy.setter
@is_strict_auto
def execution_strategy(self, strategy):
fields = self.strategy.execution_strategy.DESCRIPTOR.fields
for f in fields:
setattr(
self.strategy.execution_strategy,
f.name,
getattr(strategy, f.name),
)

@property
def build_strategy(self):
"""
Expand Down Expand Up @@ -2660,7 +2621,7 @@ def __repr__(self):

env_draws = line + "\n"
for f in fields:
if "build_strategy" in f.name or "execution_strategy" in f.name:
if "build_strategy" in f.name:
continue
if "_configs" in f.name:
continue
Expand Down Expand Up @@ -2736,15 +2697,5 @@ def __repr__(self):
)
build_strategy_str += border + "\n"

execution_strategy_str = h1_format.format("Execution Strategy")
execution_strategy_str += line + "\n"

fields = self.strategy.execution_strategy.DESCRIPTOR.fields
for f in fields:
execution_strategy_str += h2_format.format(
f.name, str(getattr(self.strategy.execution_strategy, f.name))
)
execution_strategy_str += border + "\n"

result_res += build_strategy_str + execution_strategy_str
result_res += build_strategy_str
return result_res
2 changes: 0 additions & 2 deletions python/paddle/incubate/distributed/fleet/collective.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ def __init__(self):
self.use_amp = False # use mixed precision optimizer
self.amp_loss_scaling = 2**15

self.exec_strategy = base.ExecutionStrategy()

# configurations below are used for unit test
self._ut4grad_allreduce = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def __init__(self):
self._server_runtime_config = ServerRuntimeConfig()
num_threads = int(os.getenv("CPU_NUM", "1"))

self._execute_strategy = base.ExecutionStrategy()
self._build_strategy = base.BuildStrategy()

self._execute_strategy.num_threads = num_threads
Expand Down Expand Up @@ -281,31 +280,6 @@ def check_server_runtime_config(self):
"check_server_runtime_config must be implemented by derived class. You should use StrategyFactory to create DistributedStrategy."
)

def get_execute_strategy(self):
return self._execute_strategy

def set_execute_strategy(self, config):
if isinstance(config, base.ExecutionStrategy):
self._execute_strategy = config
elif isinstance(config, dict):
for key in config:
if hasattr(self._execute_strategy, key):
setattr(self._execute_strategy, key, config[key])
else:
raise ValueError(
f"ExecutionStrategy doesn't have key: {key}"
)
else:
raise TypeError(
"execute_strategy only accept input type: dict or ExecutionStrategy"
)
self.check_execute_strategy()

def check_execute_strategy(self):
raise NotImplementedError(
"check_execute_strategy must be implemented by derived class. You should use StrategyFactory to create DistributedStrategy."
)

def get_build_strategy(self):
return self._build_strategy

Expand Down Expand Up @@ -337,7 +311,6 @@ def __init__(self):
self.check_trainer_runtime_config()
self.check_server_runtime_config()
self.check_build_strategy()
self.check_execute_strategy()

def check_trainer_runtime_config(self):
self._trainer_runtime_config.mode = DistributedMode.SYNC
Expand All @@ -351,9 +324,6 @@ def check_program_config(self):
def check_server_runtime_config(self):
pass

def check_execute_strategy(self):
self._execute_strategy.use_thread_barrier = True

def check_build_strategy(self):
self._build_strategy.async_mode = True

Expand All @@ -365,7 +335,6 @@ def __init__(self):
self.check_trainer_runtime_config()
self.check_server_runtime_config()
self.check_build_strategy()
self.check_execute_strategy()

def check_trainer_runtime_config(self):
self._trainer_runtime_config.mode = DistributedMode.ASYNC
Expand All @@ -377,9 +346,6 @@ def check_program_config(self):
def check_server_runtime_config(self):
pass

def check_execute_strategy(self):
pass

def check_build_strategy(self):
self._build_strategy.async_mode = True

Expand All @@ -391,7 +357,6 @@ def __init__(self):
self.check_trainer_runtime_config()
self.check_server_runtime_config()
self.check_build_strategy()
self.check_execute_strategy()

def check_trainer_runtime_config(self):
self._trainer_runtime_config.mode = DistributedMode.HALF_ASYNC
Expand All @@ -404,9 +369,6 @@ def check_program_config(self):
def check_server_runtime_config(self):
pass

def check_execute_strategy(self):
self._execute_strategy.use_thread_barrier = True

def check_build_strategy(self):
self._build_strategy.async_mode = True

Expand All @@ -419,7 +381,6 @@ def __init__(self, update_frequency=100):
self.check_trainer_runtime_config()
self.check_server_runtime_config()
self.check_build_strategy()
self.check_execute_strategy()

def check_program_config(self):
self._program_config.sync_mode = False
Expand All @@ -440,9 +401,6 @@ def check_trainer_runtime_config(self):
def check_server_runtime_config(self):
pass

def check_execute_strategy(self):
pass

def check_build_strategy(self):
self._build_strategy.async_mode = True

Expand Down
2 changes: 0 additions & 2 deletions python/paddle/static/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from ..base.compiler import (
BuildStrategy,
CompiledProgram,
ExecutionStrategy,
IpuCompiledProgram,
IpuStrategy,
)
Expand Down Expand Up @@ -82,7 +81,6 @@
'IpuStrategy',
'Print',
'py_func',
'ExecutionStrategy',
'name_scope',
'program_guard',
'WeightNormParamAttr',
Expand Down
2 changes: 0 additions & 2 deletions python/paddle/static/quantization/adaround.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ def run_adaround(
fetch_op_name = quant_op_out_name

# build adaround program
exec_strategy = static.ExecutionStrategy()
exec_strategy.num_iteration_per_drop_scope = 1
startup_program = static.Program()
train_program = static.Program()
with static.program_guard(train_program, startup_program):
Expand Down

0 comments on commit 11469cb

Please sign in to comment.