Skip to content

Commit 8acad27

Browse files
committed
refine code
1 parent 4b91cb5 commit 8acad27

File tree

4 files changed

+211
-204
lines changed

4 files changed

+211
-204
lines changed

paddle/fluid/operators/listen_and_serv_op.cc

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class ListenAndServOp : public framework::OperatorBase {
7575
server_thread_->join();
7676
}
7777

78-
void Run(const framework::Scope &scope,
79-
const platform::Place &dev_place) const override {
78+
void RunImpl(const framework::Scope &scope,
79+
const platform::Place &dev_place) const override {
8080
platform::DeviceContextPool &pool = platform::DeviceContextPool::Instance();
8181
auto &dev_ctx = *pool.Get(dev_place);
8282
framework::Scope &recv_scope = scope.NewScope();
@@ -101,7 +101,6 @@ class ListenAndServOp : public framework::OperatorBase {
101101
// the gradients arrives, just add suffix 0~n and merge the gradient.
102102
rpc_service_->SetCond(0);
103103
size_t recv_var_cnt = 0;
104-
size_t update_param_cnt = 0;
105104
int batch_barrier = 0;
106105
while (batch_barrier != fan_in) {
107106
const detail::MessageWithName &v = rpc_service_->Get();
@@ -128,37 +127,33 @@ class ListenAndServOp : public framework::OperatorBase {
128127
}
129128
}
130129
}
131-
VLOG(3) << "recv " << recv_var_cnt << " parmeters for one barrier.";
132130
if (exit_flag) {
133131
rpc_service_->ShutDown();
134132
}
135-
VLOG(3) << "run optimize graph...";
136133
try {
137134
executor.Run(*program, &recv_scope, block->ID(), /*global_block*/
138135
false /*create_local_scope*/, false /*create_vars*/);
139136
} catch (std::exception &e) {
140137
LOG(ERROR) << "run sub program error " << e.what();
141138
}
142-
143139
// Reset the received sparse variables, the sum operator would not
144140
// sum the input sparse variables which rows is empty at the next
145141
// mini-batch.
146-
// TOOD(Yancey1989): move the reset action into an operator, we couldn't
142+
// TODO(Yancey1989): move the reset action into an operator, we couldn't
147143
// have any hide logic in the operator.
148144
for (auto &var : sparse_vars) {
149145
var->GetMutable<framework::SelectedRows>()->mutable_rows()->clear();
150146
}
151147
rpc_service_->SetCond(1);
152-
rpc_service_->WaitClientGet(update_param_cnt);
153-
grads_counter_.clear();
148+
// FIXME(typhoonzero): use another condition to sync wait clients get.
149+
rpc_service_->WaitClientGet(ins.size());
154150
sparse_vars.clear();
155151
} // while(true)
156152
}
157153

158154
protected:
159155
std::shared_ptr<detail::AsyncGRPCServer> rpc_service_;
160156
std::shared_ptr<std::thread> server_thread_;
161-
mutable std::unordered_map<std::string, int> grads_counter_;
162157
};
163158

164159
class ListenAndServOpMaker : public framework::OpProtoAndCheckerMaker {

paddle/fluid/operators/recv_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class RecvOp : public framework::OperatorBase {
3232
const framework::AttributeMap& attrs)
3333
: OperatorBase(type, inputs, outputs, attrs) {}
3434

35-
void Run(const framework::Scope& scope,
36-
const platform::Place& place) const override {
35+
void RunImpl(const framework::Scope& scope,
36+
const platform::Place& place) const override {
3737
auto outs = Outputs("Out");
3838
std::vector<std::string> epmap = Attr<std::vector<std::string>>("epmap");
3939

paddle/fluid/operators/send_op.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class SendOp : public framework::OperatorBase {
4848
const framework::AttributeMap& attrs)
4949
: OperatorBase(type, inputs, outputs, attrs) {}
5050

51-
void Run(const framework::Scope& scope,
52-
const platform::Place& place) const override {
51+
void RunImpl(const framework::Scope& scope,
52+
const platform::Place& place) const override {
5353
auto ins = Inputs("X");
5454
auto outs = Outputs("Out");
5555
std::vector<std::string> epmap = Attr<std::vector<std::string>>("epmap");

0 commit comments

Comments
 (0)