Skip to content

Commit 486121d

Browse files
author
Yancey
authored
Merge pull request #12120 from Yancey1989/fix_cpu_pe
fix bcast with parallel executor + cpu
2 parents a376efb + 3b45aa8 commit 486121d

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

paddle/fluid/framework/parallel_executor.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ParallelExecutor::ParallelExecutor(
9595
}
9696

9797
if (member_->local_scopes_.size() != 1 && local_scopes.empty()) {
98-
BCastParamsToGPUs(bcast_vars);
98+
BCastParamsToDevs(bcast_vars);
9999
}
100100
// Startup Program has been run. All local scopes has correct parameters.
101101

@@ -131,7 +131,7 @@ ParallelExecutor::ParallelExecutor(
131131
member_->places_, std::move(member_->executor_)));
132132
}
133133

134-
void ParallelExecutor::BCastParamsToGPUs(
134+
void ParallelExecutor::BCastParamsToDevs(
135135
const std::unordered_set<std::string> &vars) const {
136136
// the the initializing bcast, all vars would be bcast from device(0),
137137
// otherwise
@@ -202,7 +202,11 @@ void ParallelExecutor::BCastParamsToGPUs(
202202
#endif
203203
} else {
204204
platform::CPUPlace cpu;
205-
for (size_t i = 1; i < member_->places_.size(); ++i) {
205+
for (size_t i = 0; i < member_->places_.size(); ++i) {
206+
if ((initializing && i == 0) ||
207+
(!initializing && static_cast<int>(i) == var_dev_id))
208+
continue;
209+
206210
auto local_scope = member_->local_scopes_[i];
207211
auto *t = local_scope->Var(var)->GetMutable<LoDTensor>();
208212
t->Resize(dims);

paddle/fluid/framework/parallel_executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class ParallelExecutor {
6666
void Run(const std::vector<std::string> &fetch_tensors,
6767
const std::string &fetched_var_name);
6868

69-
void BCastParamsToGPUs(const std::unordered_set<std::string> &vars) const;
69+
void BCastParamsToDevs(const std::unordered_set<std::string> &vars) const;
7070

7171
private:
7272
ParallelExecutorPrivate *member_;

paddle/fluid/pybind/pybind.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ All parameter, weight, gradient are variables in Paddle.
665665
const std::string &, Scope *, std::vector<Scope *> &,
666666
const ExecutionStrategy &, const BuildStrategy &, size_t,
667667
size_t>())
668-
.def("bcast_params", &ParallelExecutor::BCastParamsToGPUs)
668+
.def("bcast_params", &ParallelExecutor::BCastParamsToDevs)
669669
// NOTE: even we return a vec<Scope*>* to Python use reference policy.
670670
// We still cannot get local_scope from this vector, since the element
671671
// of vec<Scope*> will be freed by Python GC. We can only return Scope*

0 commit comments

Comments
 (0)