-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eagerly drop local scope in iteration #9838
Changes from 1 commit
3d165b6
bf16efd
4f255fd
d3763e7
968667b
0e41230
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ limitations under the License. */ | |
#include "paddle/fluid/framework/parallel_executor.h" | ||
|
||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#ifdef PADDLE_WITH_CUDA | ||
|
@@ -41,6 +42,8 @@ class ParallelExecutorPrivate { | |
#ifdef PADDLE_WITH_CUDA | ||
std::unique_ptr<platform::NCCLContextMap> nccl_ctxs_; | ||
#endif | ||
|
||
std::vector<std::pair<std::string, proto::VarType::Type>> var_types_; | ||
}; | ||
|
||
std::vector<Scope *> &ParallelExecutor::GetLocalScopes() { | ||
|
@@ -97,14 +100,8 @@ ParallelExecutor::ParallelExecutor( | |
allow_op_delay)); | ||
|
||
// Step 3. Create vars in each scope; | ||
for (auto *scope : member_->local_scopes_) { | ||
for (auto *var : main_program.Block(0).AllVars()) { | ||
if (scope->FindVar(var->Name()) != nullptr) { | ||
continue; | ||
} | ||
|
||
InitializeVariable(scope->Var(var->Name()), var->GetType()); | ||
} | ||
for (auto *var : main_program.Block(0).AllVars()) { | ||
member_->var_types_.emplace_back(var->Name(), var->GetType()); | ||
} | ||
} | ||
|
||
|
@@ -165,9 +162,39 @@ void ParallelExecutor::Run( | |
const std::unordered_map<std::string, LoDTensor> &feed_tensors) { | ||
platform::RecordBlock b(0); | ||
SplitTensorToPlaces(feed_tensors); | ||
|
||
// Create local scopes. | ||
for (auto &scope : member_->local_scopes_) { | ||
Scope &local_scope = scope->NewScope(); | ||
*scope->Var(details::kLocalExecScopeName)->GetMutable<Scope *>() = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is usefule of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, all non-persistable variables will be in the 'sub-scope of local scope'. The sub-scope is created before batch training and deleted after batch training. |
||
&local_scope; | ||
} | ||
|
||
for (auto *scope : member_->local_scopes_) { | ||
for (auto &name_type_pair : member_->var_types_) { | ||
if (scope->FindVar(name_type_pair.first) != nullptr) { | ||
continue; | ||
} | ||
|
||
InitializeVariable(scope->Var(name_type_pair.first), | ||
name_type_pair.second); | ||
} | ||
} | ||
|
||
auto fetch_data = member_->executor_->Run(fetch_tensors); | ||
*member_->global_scope_->Var(fetched_var_name)->GetMutable<FeedFetchList>() = | ||
fetch_data; | ||
|
||
// Wait All computational streams | ||
for (auto p : member_->places_) { | ||
platform::DeviceContextPool::Instance().Get(p)->Wait(); | ||
} | ||
for (auto &scope : member_->local_scopes_) { | ||
auto &local_scope = | ||
*scope->Var(details::kLocalExecScopeName)->GetMutable<Scope *>(); | ||
scope->DeleteScope(local_scope); | ||
local_scope = nullptr; | ||
} | ||
} | ||
|
||
void ParallelExecutor::SplitTensorToPlaces( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used to fetch the variable in the local scope?