Skip to content

Commit 401c03f

Browse files
author
chengduo
authored
update reduce config (#18335)
test=release/1.5
1 parent e0cb671 commit 401c03f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

paddle/fluid/framework/parallel_executor.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,25 +314,23 @@ ParallelExecutor::ParallelExecutor(const std::vector<platform::Place> &places,
314314
member_->use_all_reduce_ =
315315
build_strategy.reduce_ == BuildStrategy::ReduceStrategy::kAllReduce;
316316
member_->nranks_ = build_strategy.num_trainers_ * places.size();
317+
if (!member_->use_all_reduce_ && member_->nranks_ == 1) {
318+
LOG(INFO) << "If you set build_strategy.reduce with 'Reduce',"
319+
"the number of places should be greater than 1.";
320+
member_->build_strategy_.reduce_ =
321+
BuildStrategy::ReduceStrategy::kAllReduce;
322+
member_->use_all_reduce_ = true;
323+
}
317324
#if defined(PADDLE_WITH_CUDA) && defined(_WIN32)
318325
if (member_->use_cuda_) {
319326
PADDLE_ENFORCE(places.size() == 1, "Windows can support Single GPU only.");
320327
}
321328
#endif
322-
if (!member_->use_all_reduce_) {
323-
if (places.size() == 1) {
324-
LOG(INFO) << "If you set build_strategy.reduce with 'Reduce',"
325-
"the number of places should be greater than 1.";
326-
member_->use_all_reduce_ = true;
327-
}
328-
}
329-
330329
LOG(INFO) << string::Sprintf(
331330
"The number of %s, which is used in ParallelExecutor, is %lu. And "
332331
"the Program will be copied %lu copies",
333332
(member_->use_cuda_ ? "CUDAPlace" : "CPUPlace"), places.size(),
334333
places.size());
335-
336334
// Step 1. Bcast the bcast_vars to devs.
337335
// Create local scopes
338336
if (local_scopes.empty()) {

0 commit comments

Comments
 (0)