diff --git a/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc b/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc index 8459f3a47b44433d2ba0b877c3deafb226447897..4f8668966f39b350483b9b6cf61a31f6baf35959 100644 --- a/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc +++ b/paddle/fluid/framework/details/scope_buffered_ssa_graph_executor.cc @@ -25,6 +25,45 @@ namespace paddle { namespace framework { namespace details { + +static void CollectUniqueAllocations( + const Variable &var, + std::unordered_set *allocation_set) { + if (var.IsType()) { + allocation_set->insert(var.Get().Holder().get()); + } else if (var.IsType()) { + allocation_set->insert(var.Get().value().Holder().get()); + } else if (var.IsType()) { + for (auto &t : var.Get()) { + allocation_set->insert(t.Holder().get()); + } + } +} + +static void CollectUniqueAllocations( + const Scope &scope, + std::unordered_set *allocation_set) { + for (auto &var_name : scope.LocalVarNames()) { + CollectUniqueAllocations(*scope.FindVar(var_name), allocation_set); + } + + for (auto *kid : scope.kids()) { + CollectUniqueAllocations(*kid, allocation_set); + } +} + +static size_t GetScopeVarMemorySize(const Scope &scope) { + std::unordered_set allocation_set; + CollectUniqueAllocations(scope, &allocation_set); + size_t memory_size = 0; + for (auto *allocation : allocation_set) { + if (allocation) { + memory_size += allocation->size(); + } + } + return memory_size; +} + ScopeBufferedSSAGraphExecutor::ScopeBufferedSSAGraphExecutor( ExecutionStrategy strategy, std::vector local_scopes, std::vector local_exec_scopes, std::vector var_infos, @@ -55,10 +94,27 @@ FeedFetchList ScopeBufferedSSAGraphExecutor::Run( eptr = std::current_exception(); } + if (VLOG_IS_ON(5)) { + for (auto *scope : local_exec_scopes_) { + VLOG(5) << "Left " + << string::HumanReadableSize(GetScopeVarMemorySize(*scope)) + << " on scope " << scope << " before deleting"; + } + } + ++drop_scope_counter_; if (drop_scope_counter_ == strategy_.num_iteration_per_drop_scope_) { DropLocalExeScopes(); } + + if (VLOG_IS_ON(5)) { + for (auto *scope : local_exec_scopes_) { + VLOG(5) << "Left " + << string::HumanReadableSize(GetScopeVarMemorySize(*scope)) + << " on scope " << scope << " after deleting"; + } + } + if (eptr) { std::rethrow_exception(eptr); } else { diff --git a/python/paddle/fluid/tests/unittests/CMakeLists.txt b/python/paddle/fluid/tests/unittests/CMakeLists.txt index a3cbf1689a4798855a63a1b899a23afdaa4fad48..3646b65643fbcd4134b793c64f09f9a28ccb329f 100644 --- a/python/paddle/fluid/tests/unittests/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/CMakeLists.txt @@ -317,6 +317,10 @@ if (WITH_MKLDNN) add_subdirectory(mkldnn) endif() +if (WITH_TESTING) + set_property(TEST test_parallel_executor_mnist PROPERTY ENVIRONMENT GLOG_vmodule=scope_buffered_ssa_graph_executor=5) +endif() + set_tests_properties(test_parallel_executor_test_while_train test_parallel_executor_mnist test_parallel_executor_seresnext_base_gpu test_parallel_executor_seresnext_with_reduce_gpu test_parallel_executor_seresnext_with_fuse_all_reduce_gpu