Skip to content

Commit d114d2b

Browse files
authored
Merge pull request #10076 from reyoung/feature/FLAGS_eager_deletion_scope
Eager destruct local scope
2 parents ba927b8 + 92b5f49 commit d114d2b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

paddle/fluid/framework/scope.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ DEFINE_bool(benchmark, false,
2626
"Default cuda is asynchronous device, set to True will"
2727
"force op run in synchronous mode.");
2828

29+
DEFINE_bool(
30+
eager_delete_scope, true,
31+
"Delete local scope eagerly. It will reduce GPU memory usage but "
32+
"slow down the destruction of variables.(around 1% performance harm)");
33+
2934
namespace paddle {
3035
namespace framework {
3136

@@ -97,7 +102,7 @@ void Scope::DeleteScope(Scope* scope) const {
97102
PADDLE_ENFORCE(it != this->kids_.end(), "Cannot find %p as kid scope", scope);
98103
this->kids_.erase(it);
99104
// When making memory benchmark on Fluid, we have to delete scope sync.
100-
if (FLAGS_benchmark) {
105+
if (FLAGS_benchmark || FLAGS_eager_delete_scope) {
101106
delete scope;
102107
} else {
103108
Async([scope] { delete scope; });

python/paddle/fluid/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def __bootstrap__():
107107
os.environ['OMP_NUM_THREADS'] = str(num_threads)
108108

109109
read_env_flags = [
110-
'use_pinned_memory', 'check_nan_inf', 'benchmark', 'warpctc_dir'
110+
'use_pinned_memory', 'check_nan_inf', 'benchmark', 'warpctc_dir',
111+
'eager_delete_scope'
111112
]
112113
if core.is_compiled_with_cuda():
113114
read_env_flags += ['fraction_of_gpu_memory_to_use']

0 commit comments

Comments
 (0)