|
|
|
@ -184,9 +184,10 @@ std::vector<Scope *> &ParallelExecutor::GetLocalScopes() {
|
|
|
|
|
ParallelExecutor::ParallelExecutor(
|
|
|
|
|
const std::vector<platform::Place> &places,
|
|
|
|
|
const std::unordered_set<std::string> &bcast_vars,
|
|
|
|
|
const std::vector<ir::Graph *> &graphs, const std::string &loss_var_name,
|
|
|
|
|
Scope *scope, const std::vector<Scope *> &local_scopes,
|
|
|
|
|
const ExecutionStrategy &exec_strategy, const BuildStrategy &build_strategy)
|
|
|
|
|
const std::string &loss_var_name, Scope *scope,
|
|
|
|
|
const std::vector<Scope *> &local_scopes,
|
|
|
|
|
const ExecutionStrategy &exec_strategy, const BuildStrategy &build_strategy,
|
|
|
|
|
ir::Graph *graph)
|
|
|
|
|
: member_(new ParallelExecutorPrivate(places)) {
|
|
|
|
|
member_->global_scope_ = scope;
|
|
|
|
|
member_->use_cuda_ = exec_strategy.use_cuda_;
|
|
|
|
@ -216,34 +217,17 @@ ParallelExecutor::ParallelExecutor(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
std::unique_ptr<ir::Graph> temp_owned_graph(graph);
|
|
|
|
|
|
|
|
|
|
// FIXME(Yancey1989): parallel graph mode get better performance
|
|
|
|
|
// in GPU allreduce distributed training. Need an elegant way to
|
|
|
|
|
// choice the execution strategy.
|
|
|
|
|
build_strategy.enable_parallel_graph_ =
|
|
|
|
|
EnableParallelGraphExecution(*temp_owned_graph, exec_strategy, build_strategy);
|
|
|
|
|
build_strategy.enable_parallel_graph_ = EnableParallelGraphExecution(
|
|
|
|
|
*temp_owned_graph, exec_strategy, build_strategy);
|
|
|
|
|
if (build_strategy.enable_parallel_graph_)
|
|
|
|
|
VLOG(0) << "The Executor would execute the graph by ParallelGraph "
|
|
|
|
|
"Execution which can get better performance,"
|
|
|
|
|
<< "you can force it off by env FLAGS_enable_parallel_graph=0";
|
|
|
|
|
=======
|
|
|
|
|
// TODO(panyx0718): Update pass interface so we don't need this here.
|
|
|
|
|
std::vector<std::unique_ptr<ir::Graph>> temp_owned_graphs;
|
|
|
|
|
for (ir::Graph *g : graphs) {
|
|
|
|
|
temp_owned_graphs.emplace_back(g);
|
|
|
|
|
}
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
>>>>>>> fix parallel graph mode program
|
|
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
bool parallel_graphs = (temp_owned_graphs.size() > 1);
|
|
|
|
|
if (parallel_graphs) {
|
|
|
|
|
PADDLE_ENFORCE_EQ(temp_owned_graphs.size(), places.size());
|
|
|
|
|
}
|
|
|
|
|
VLOG(1) << "Enable ParallelGraph Execution: " << parallel_graphs;
|
|
|
|
|
>>>>>>> polish
|
|
|
|
|
|
|
|
|
|
if (member_->use_cuda_) {
|
|
|
|
|
// Bcast Parameters to all GPUs
|
|
|
|
@ -255,7 +239,7 @@ ParallelExecutor::ParallelExecutor(
|
|
|
|
|
if (nccl_id_var != nullptr) {
|
|
|
|
|
nccl_id = nccl_id_var->GetMutable<ncclUniqueId>();
|
|
|
|
|
}
|
|
|
|
|
if (parallel_graphs && member_->nranks_ > 1UL) {
|
|
|
|
|
if (build_strategy.enable_parallel_graph_ && member_->nranks_ > 1UL) {
|
|
|
|
|
if (nccl_id == nullptr) {
|
|
|
|
|
local_nccl_id_.reset(new ncclUniqueId());
|
|
|
|
|
platform::dynload::ncclGetUniqueId(local_nccl_id_.get());
|
|
|
|
@ -273,105 +257,54 @@ ParallelExecutor::ParallelExecutor(
|
|
|
|
|
if (member_->local_scopes_.size() != 1 && local_scopes.empty()) {
|
|
|
|
|
BCastParamsToDevices(bcast_vars);
|
|
|
|
|
}
|
|
|
|
|
// Startup Program has been run. All local scopes has correct parameters.
|
|
|
|
|
// Startup Program has been run. All local scopes has correct parameters.
|
|
|
|
|
|
|
|
|
|
// Step 2. Convert main_program to SSA form and dependency graph. Also, insert
|
|
|
|
|
// ncclOp
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
std::unique_ptr<ir::Graph> graph;
|
|
|
|
|
// Step 2. Convert main_program to SSA form and dependency graph. Also, insert
|
|
|
|
|
// ncclOp
|
|
|
|
|
#if defined(PADDLE_WITH_CUDA) && !defined(_WIN32)
|
|
|
|
|
|
|
|
|
|
temp_owned_graph = build_strategy.Apply(std::move(temp_owned_graph), member_->places_, loss_var_name,
|
|
|
|
|
member_->local_scopes_, member_->nranks_,
|
|
|
|
|
member_->use_cuda_, member_->nccl_ctxs_.get());
|
|
|
|
|
#else
|
|
|
|
|
temp_owned_graph = build_strategy.Apply(std::move(temp_owned_graph), member_->places_, loss_var_name,
|
|
|
|
|
member_->local_scopes_, member_->nranks_,
|
|
|
|
|
member_->use_cuda_);
|
|
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
std::vector<ir::Graph *> compiled_graphs;
|
|
|
|
|
#if defined(PADDLE_WITH_CUDA) && !defined(_WIN32)
|
|
|
|
|
if (parallel_graphs) {
|
|
|
|
|
for (size_t i = 0; i < member_->places_.size(); ++i) {
|
|
|
|
|
auto temp_owned_graph = build_strategy.Apply(
|
|
|
|
|
std::move(temp_owned_graphs[i]), {member_->places_[i]}, loss_var_name,
|
|
|
|
|
{member_->local_scopes_[i]}, member_->nranks_, member_->use_cuda_,
|
|
|
|
|
member_->nccl_ctxs_.get());
|
|
|
|
|
compiled_graphs.push_back(temp_owned_graph.release());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
auto temp_owned_graph = build_strategy.Apply(
|
|
|
|
|
std::move(temp_owned_graphs[0]), member_->places_, loss_var_name,
|
|
|
|
|
member_->local_scopes_, member_->nranks_, member_->use_cuda_,
|
|
|
|
|
member_->nccl_ctxs_.get());
|
|
|
|
|
compiled_graphs.push_back(temp_owned_graph.release());
|
|
|
|
|
}
|
|
|
|
|
temp_owned_graph = build_strategy.Apply(
|
|
|
|
|
std::move(temp_owned_graph), member_->places_, loss_var_name,
|
|
|
|
|
member_->local_scopes_, member_->nranks_, member_->use_cuda_,
|
|
|
|
|
member_->nccl_ctxs_.get());
|
|
|
|
|
#else
|
|
|
|
|
auto temp_owned_graph = build_strategy.Apply(
|
|
|
|
|
std::move(temp_owned_graphs[0]), member_->places_, loss_var_name,
|
|
|
|
|
temp_owned_graph = build_strategy.Apply(
|
|
|
|
|
std::move(temp_owned_graph), member_->places_, loss_var_name,
|
|
|
|
|
member_->local_scopes_, member_->nranks_, member_->use_cuda_);
|
|
|
|
|
compiled_graphs.push_back(temp_owned_graph.release());
|
|
|
|
|
>>>>>>> fix parallel graph mode program
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
auto max_memory_size = GetEagerDeletionThreshold();
|
|
|
|
|
VLOG(10) << "Eager Deletion Threshold "
|
|
|
|
|
<< static_cast<float>(max_memory_size) / (1 << 30);
|
|
|
|
|
if (max_memory_size >= 0) {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
graph = member_->PrepareGCAndRefCnts(std::move(graph),
|
|
|
|
|
static_cast<size_t>(max_memory_size)).release();
|
|
|
|
|
=======
|
|
|
|
|
for (size_t i = 0; i < graphs.size(); ++i) {
|
|
|
|
|
compiled_graphs[i] =
|
|
|
|
|
member_
|
|
|
|
|
->PrepareGCAndRefCnts(
|
|
|
|
|
std::unique_ptr<ir::Graph>(compiled_graphs[i]),
|
|
|
|
|
static_cast<size_t>(max_memory_size))
|
|
|
|
|
.release();
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> fix parallel graph mode program
|
|
|
|
|
graph = member_
|
|
|
|
|
->PrepareGCAndRefCnts(std::move(temp_owned_graph),
|
|
|
|
|
static_cast<size_t>(max_memory_size))
|
|
|
|
|
.release();
|
|
|
|
|
} else {
|
|
|
|
|
graph = temp_owned_graph.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 3. Create vars in each scope. Passes may also create new vars.
|
|
|
|
|
// skip control vars and empty vars
|
|
|
|
|
std::vector<details::VariableInfo> var_infos;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
for (auto &node : graph->Nodes()) {
|
|
|
|
|
if (node->IsVar() && !node->IsCtrlVar() && node->Var()) {
|
|
|
|
|
var_infos.emplace_back();
|
|
|
|
|
var_infos.back().name_ = node->Var()->Name();
|
|
|
|
|
var_infos.back().type_ = node->Var()->GetType();
|
|
|
|
|
var_infos.back().persistable_ = node->Var()->Persistable();
|
|
|
|
|
=======
|
|
|
|
|
for (auto &graph : compiled_graphs) {
|
|
|
|
|
for (auto &node : graph->Nodes()) {
|
|
|
|
|
if (node->IsVar() && !node->IsCtrlVar() && node->Var()) {
|
|
|
|
|
var_infos.emplace_back();
|
|
|
|
|
var_infos.back().name_ = node->Var()->Name();
|
|
|
|
|
var_infos.back().type_ = node->Var()->GetType();
|
|
|
|
|
var_infos.back().persistable_ = node->Var()->Persistable();
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> fix parallel graph mode program
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the loss_var_name is given, the number of graph should be only one.
|
|
|
|
|
if (loss_var_name.size()) {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
size_t graph_num = ir::GraphNum(*graph);
|
|
|
|
|
=======
|
|
|
|
|
size_t graph_num = ir::GraphNum(*compiled_graphs[0]);
|
|
|
|
|
>>>>>>> fix parallel graph mode program
|
|
|
|
|
if (graph_num > 1) {
|
|
|
|
|
LOG(WARNING)
|
|
|
|
|
<< "The number of graph should be only one, "
|
|
|
|
|
"but the current graph has "
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
<< ir::GraphNum(*graph)
|
|
|
|
|
=======
|
|
|
|
|
<< ir::GraphNum(*compiled_graphs[0])
|
|
|
|
|
>>>>>>> fix parallel graph mode program
|
|
|
|
|
<< " sub_graphs. If you want to see the nodes of the "
|
|
|
|
|
"sub_graphs, you should use 'FLAGS_print_sub_graph_dir' "
|
|
|
|
|
"to specify the output dir. NOTES: if you not do training, "
|
|
|
|
@ -379,18 +312,12 @@ ParallelExecutor::ParallelExecutor(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
if (build_strategy.enable_parallel_graph_) {
|
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
|
// TODO(Yancey1989): Remove passing in the main_program when
|
|
|
|
|
// allreduce_seq_pass doesn't need it as the attr.
|
|
|
|
|
=======
|
|
|
|
|
if (parallel_graphs) {
|
|
|
|
|
>>>>>>> polish
|
|
|
|
|
member_->executor_.reset(new details::ParallelSSAGraphExecutor(
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
exec_strategy, member_->local_scopes_, member_->places_, main_program,
|
|
|
|
|
graph));
|
|
|
|
|
exec_strategy, member_->local_scopes_, member_->places_, graph));
|
|
|
|
|
#else
|
|
|
|
|
PADDLE_THROW(
|
|
|
|
|
"Paddle should be compiled with CUDA for ParallelGraph Execution.");
|
|
|
|
@ -402,19 +329,6 @@ ParallelExecutor::ParallelExecutor(
|
|
|
|
|
} else {
|
|
|
|
|
member_->executor_.reset(new details::FastThreadedSSAGraphExecutor(
|
|
|
|
|
exec_strategy, member_->local_scopes_, member_->places_, graph));
|
|
|
|
|
=======
|
|
|
|
|
exec_strategy, member_->local_scopes_, member_->places_,
|
|
|
|
|
compiled_graphs));
|
|
|
|
|
} else {
|
|
|
|
|
if (exec_strategy.type_ == ExecutionStrategy::kDefault) {
|
|
|
|
|
member_->executor_.reset(new details::ThreadedSSAGraphExecutor(
|
|
|
|
|
exec_strategy, member_->local_scopes_, member_->places_,
|
|
|
|
|
compiled_graphs[0]));
|
|
|
|
|
} else {
|
|
|
|
|
member_->executor_.reset(new details::FastThreadedSSAGraphExecutor(
|
|
|
|
|
exec_strategy, member_->local_scopes_, member_->places_,
|
|
|
|
|
compiled_graphs[0]));
|
|
|
|
|
>>>>>>> fix parallel graph mode program
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -551,9 +465,9 @@ ParallelExecutor::~ParallelExecutor() {
|
|
|
|
|
delete member_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EnableParallelGraphExecution(const ir::Graph &graph,
|
|
|
|
|
const ExecutionStrategy &exec_strategy,
|
|
|
|
|
const BuildStrategy &build_strategy) {
|
|
|
|
|
bool ParallelExecutor::EnableParallelGraphExecution(
|
|
|
|
|
const ir::Graph &graph, const ExecutionStrategy &exec_strategy,
|
|
|
|
|
const BuildStrategy &build_strategy) const {
|
|
|
|
|
if (!FLAGS_enable_parallel_graph) return false;
|
|
|
|
|
|
|
|
|
|
bool enable_parallel_graph = true;
|
|
|
|
|