Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions paddle/fluid/framework/details/async_ssa_graph_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ void ProcessGraph(std::vector<ir::Graph *> graphs, Scope *scope) {
// init communicator here
if (send_varname_to_ctx.size() > 0) {
VLOG(3) << "this is distribute mode, will use communicator";
operators::distributed::Communicator::Init(send_varname_to_ctx,
recv_varname_to_ctx, scope);
operators::distributed::Communicator::GetInstance()->Start();

if (operators::distributed::Communicator::GetInstance() == nullptr) {
operators::distributed::Communicator::Init(send_varname_to_ctx,
recv_varname_to_ctx, scope);
operators::distributed::Communicator::GetInstance()->Start();
} else {
VLOG(3) << "communicator has been initialized, skip";
}
}
#endif
}
Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/operators/distributed/communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ class Communicator {
void Start();
void Stop();

bool IsRunning() { return running_; }

// send grad
void Send(const std::string& var_name, const framework::Scope& scope);

Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/pybind/communicator_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ void BindCommunicator(py::module* m) {
return Communicator::GetInstantcePtr();
}))
.def("stop", &Communicator::Stop)
.def("start", &Communicator::Start);
.def("start", &Communicator::Start)
.def("is_running", &Communicator::IsRunning);
}

} // namespace pybind
Expand Down
18 changes: 18 additions & 0 deletions python/paddle/fluid/communicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,21 @@ def stop(self):
comm.stop()
"""
self.communicator_.stop()

def is_running(self):
"""
Get communicator is running or stop.

Returns:
bool

Examples:
.. code-block:: python

import paddle.fluid as fluid

prog = fluid.Program()
comm = fluid.communicator.Communicator(prog)
comm.is_running()
"""
self.communicator_.is_running()
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import warnings

import paddle.fluid.io as io
from paddle.fluid.communicator import Communicator
Expand Down Expand Up @@ -53,7 +54,11 @@ def init_worker(self):
"""
if not self._transpile_config.sync_mode:
self._communicator = Communicator(self.main_program)
self._communicator.start()

if not self._communicator.is_running():
self._communicator.start()
else:
warnings.warn("communicator has been initialized, skip")

def init_server(self, model_dir=None):
"""
Expand Down Expand Up @@ -104,7 +109,8 @@ def stop_worker(self):
Returns:
None
"""
if not self._transpile_config.sync_mode:
if not self._transpile_config.sync_mode and self._communicator.is_running(
):
self._communicator.stop()
self._executor.close()

Expand Down