From 9f001c65253a419fa351e094cee7533cfafa0653 Mon Sep 17 00:00:00 2001 From: dzhwinter Date: Thu, 31 Jan 2019 22:57:02 +0800 Subject: [PATCH] skip dist. test=develop --- .../framework/details/inplace_op_pass.cc | 23 ++++++++++++++++--- .../fluid/framework/details/inplace_op_pass.h | 7 ++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/details/inplace_op_pass.cc b/paddle/fluid/framework/details/inplace_op_pass.cc index a8e133e3d5e..64368a5e873 100644 --- a/paddle/fluid/framework/details/inplace_op_pass.cc +++ b/paddle/fluid/framework/details/inplace_op_pass.cc @@ -301,7 +301,7 @@ void InplacePass::TryInplaceOpInputOutput(ir::Node* op, // 3. if output has been memory optimize by python(fluid.memory_optmize()). // this candidate can not be inplaced. Will be deprecated in the future. - if (view_.ReusedInPythonMemOpt(out_node->Name())) { + if (view_.InSkipSet(out_node->Name())) { VLOG(4) << string::Sprintf( "Skiped %s => %s reused previous memory block in python memory " "optmize," @@ -385,7 +385,7 @@ void GraphView::Build(ir::Graph* g) { // resolve data harzards depends on the var nodes in right order. ops_ = SortOpLikeDescOrder(*g); - // track the nodes which reused previous node in Python memory optimize. + // 1. track the nodes which reused previous node in Python memory optimize. // these node can not be inplaced, otherwise may generate a circle in graph. std::unordered_set all_vars; for (auto& node : g->Nodes()) { @@ -399,11 +399,28 @@ void GraphView::Build(ir::Graph* g) { } } } + + // 2. track the nodes which used by parameter server. + // these node can not be inplaced, otherwise trainer + // pserver can not find each other name. + for (auto& node : g->Nodes()) { + if (!node->IsOp()) continue; + if (node->Name() == "send") { + for (auto& in : node->inputs) { + dup_nodes_.emplace(in->Name()); + } + } + if (node->Name() == "recv") { + for (auto& out : node->outputs) { + dup_nodes_.emplace(out->Name()); + } + } + } } const std::vector& GraphView::AllOps() { return ops_; } -bool GraphView::ReusedInPythonMemOpt(const std::string& var) const { +bool GraphView::InSkipSet(const std::string& var) const { return dup_nodes_.count(var); } diff --git a/paddle/fluid/framework/details/inplace_op_pass.h b/paddle/fluid/framework/details/inplace_op_pass.h index e477ee2af19..1abcf1f279e 100644 --- a/paddle/fluid/framework/details/inplace_op_pass.h +++ b/paddle/fluid/framework/details/inplace_op_pass.h @@ -41,11 +41,14 @@ class GraphView { std::vector PendingOpsOnVar(ir::Node* var); // Will Deperated in the future. - // NOTE(dzhwinter) : Python memory optimize will reuse + // NOTE(dzhwinter) : + // 1. Python memory optimize will reuse // memory based var name, so different op output may // have the same variable name. enable inplace on such node // will generate a circle in ssa graph. - bool ReusedInPythonMemOpt(const std::string& var) const; + // 2. DistributeTranspiler will use unique name to + // map the parameter and gradient, must be skipped. + bool InSkipSet(const std::string& var) const; private: std::vector ops_; -- GitLab