Skip to content

Commit 7e46a8d

Browse files
committed
fix logical bug, optimize code
1 parent d04dca3 commit 7e46a8d

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

paddle/fluid/operators/listen_and_serv_op.cc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,14 @@ void ListenAndServOp::RunSyncLoop(
130130

131131
int32_t profile_step = 0;
132132
while (true) {
133-
if (FLAGS_listen_and_serv_profile_period > 0 && profile_step == 0) {
134-
auto pf_state = paddle::platform::ProfilerState::kCPU;
135-
paddle::platform::EnableProfiler(pf_state);
133+
PADDLE_ENFORCE_LE(profile_step, FLAGS_listen_and_serv_profile_period,
134+
"profile_step should not be larger then "
135+
"FLAGS_listen_and_serv_profile_period");
136+
if (FLAGS_listen_and_serv_profile_period > 0) {
137+
if (profile_step == 0) {
138+
auto pf_state = paddle::platform::ProfilerState::kCPU;
139+
paddle::platform::EnableProfiler(pf_state);
140+
}
136141
}
137142
// Get from multiple trainers, we don't care about the order in which
138143
// the gradients arrives, just add suffix 0~n and merge the gradient.
@@ -175,13 +180,14 @@ void ListenAndServOp::RunSyncLoop(
175180
// reset received sparse vars to avoid reuse it in the next mini-batch
176181
dynamic_cast<distributed::RequestSendHandler *>(request_send_handler_.get())
177182
->ResetSparseVarRecorder();
178-
if (FLAGS_listen_and_serv_profile_period > 0 &&
179-
profile_step == FLAGS_listen_and_serv_profile_period) {
180-
paddle::platform::DisableProfiler(
181-
paddle::platform::EventSortingKey::kTotal, "/dev/null");
182-
profile_step = 0;
183-
} else {
184-
profile_step++;
183+
if (FLAGS_listen_and_serv_profile_period > 0) {
184+
if (profile_step == FLAGS_listen_and_serv_profile_period) {
185+
paddle::platform::DisableProfiler(
186+
paddle::platform::EventSortingKey::kTotal, "/dev/null");
187+
profile_step = 0;
188+
} else {
189+
profile_step++;
190+
}
185191
}
186192
} // while(true)
187193
}

0 commit comments

Comments
 (0)