Skip to content

Commit 7b72383

Browse files
committed
Add cpu test for parallel_executor_crf executor_fetch_feed, and enable these tests
1 parent d24e046 commit 7b72383

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

paddle/fluid/framework/details/all_reduce_op_handle.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ void AllReduceOpHandle::RunImpl() {
107107
auto &trg = *this->local_scopes_[0]
108108
->FindVar(kLocalExecScopeName)
109109
->Get<Scope *>()
110-
->FindVar(in_var_handles[0]->name_)
110+
->FindVar(out_var_handles[0]->name_)
111111
->GetMutable<framework::LoDTensor>();
112112

113113
// Reduce All Tensor to trg in CPU
114114
ReduceLoDTensor func(lod_tensors, &trg);
115115
VisitDataType(ToDataType(lod_tensors[0]->type()), func);
116116

117-
for (size_t i = 0; i < local_scopes_.size(); ++i) {
117+
for (size_t i = 1; i < local_scopes_.size(); ++i) {
118118
auto &scope =
119119
*local_scopes_[i]->FindVar(kLocalExecScopeName)->Get<Scope *>();
120120
auto &p = places_[i];
121-
auto *var = scope.FindVar(in_var_handles[i]->name_);
121+
auto *var = scope.FindVar(out_var_handles[i]->name_);
122122
auto *dev_ctx = dev_ctxes_[p];
123123

124124
RunAndRecordEvent(p, [&trg, var, dev_ctx, p] {

paddle/fluid/framework/details/reduce_and_gather.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ struct ReduceLoDTensor {
3737
PADDLE_ENFORCE_NE(t0.numel(), 0);
3838
dst_tensor_.Resize(t0.dims());
3939
T *dst = dst_tensor_.mutable_data<T>(platform::CPUPlace());
40-
std::copy(t0.data<T>(), t0.data<T>() + t0.numel(), dst);
40+
if (dst != t0.data<T>()) {
41+
std::copy(t0.data<T>(), t0.data<T>() + t0.numel(), dst);
42+
}
4143

4244
for (size_t i = 1; i < src_tensors_.size(); ++i) {
4345
auto &t = *src_tensors_[i];

python/paddle/fluid/tests/unittests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function(py_test_modules TARGET_NAME)
4141
endfunction()
4242
list(REMOVE_ITEM TEST_OPS test_warpctc_op)
4343
list(REMOVE_ITEM TEST_OPS test_dist_train)
44-
list(REMOVE_ITEM TEST_OPS test_parallel_executor_crf)
45-
list(REMOVE_ITEM TEST_OPS test_parallel_executor_fetch_feed)
44+
#list(REMOVE_ITEM TEST_OPS test_parallel_executor_crf)
45+
#list(REMOVE_ITEM TEST_OPS test_parallel_executor_fetch_feed)
4646
# TODO(wuyi): this test hungs on CI, will add it back later
4747
list(REMOVE_ITEM TEST_OPS test_listen_and_serv_op)
4848
foreach(TEST_OP ${TEST_OPS})

python/paddle/fluid/tests/unittests/test_parallel_executor_crf.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import unittest
1818
import paddle
1919
import numpy as np
20+
import os
2021

2122
word_dict, verb_dict, label_dict = conll05.get_dict()
2223
word_dict_len = len(word_dict)
@@ -101,7 +102,11 @@ def db_lstm(word, predicate, ctx_n2, ctx_n1, ctx_0, ctx_p1, ctx_p2, mark,
101102

102103

103104
class TestCRFModel(unittest.TestCase):
104-
def check_network_convergence(self, is_sparse, build_strategy=None):
105+
def check_network_convergence(self,
106+
is_sparse,
107+
build_strategy=None,
108+
use_cuda=True):
109+
os.environ['CPU_NUM'] = str(4)
105110
main = fluid.Program()
106111
startup = fluid.Program()
107112
with fluid.program_guard(main, startup):
@@ -145,12 +150,12 @@ def check_network_convergence(self, is_sparse, build_strategy=None):
145150
paddle.dataset.conll05.test(), buf_size=8192),
146151
batch_size=16)
147152

148-
place = fluid.CUDAPlace(0)
153+
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
149154
exe = fluid.Executor(place)
150155
exe.run(startup)
151156

152157
pe = fluid.ParallelExecutor(
153-
use_cuda=True,
158+
use_cuda=use_cuda,
154159
loss_name=avg_cost.name,
155160
build_strategy=build_strategy)
156161

@@ -172,25 +177,33 @@ def test_update_sparse_parameter_all_reduce(self):
172177
build_strategy = fluid.BuildStrategy()
173178
build_strategy.reduce_strategy = fluid.BuildStrategy.ReduceStrategy.AllReduce
174179
self.check_network_convergence(
175-
is_sparse=True, build_strategy=build_strategy)
180+
is_sparse=True, build_strategy=build_strategy, use_cuda=True)
181+
self.check_network_convergence(
182+
is_sparse=True, build_strategy=build_strategy, use_cuda=False)
176183

177184
def test_update_dense_parameter_all_reduce(self):
178185
build_strategy = fluid.BuildStrategy()
179186
build_strategy.reduce_strategy = fluid.BuildStrategy.ReduceStrategy.AllReduce
180187
self.check_network_convergence(
181-
is_sparse=False, build_strategy=build_strategy)
188+
is_sparse=False, build_strategy=build_strategy, use_cuda=True)
189+
self.check_network_convergence(
190+
is_sparse=False, build_strategy=build_strategy, use_cuda=False)
182191

183192
def test_update_sparse_parameter_reduce(self):
184193
build_strategy = fluid.BuildStrategy()
185194
build_strategy.reduce_strategy = fluid.BuildStrategy.ReduceStrategy.Reduce
186195
self.check_network_convergence(
187-
is_sparse=True, build_strategy=build_strategy)
196+
is_sparse=True, build_strategy=build_strategy, use_cuda=True)
197+
self.check_network_convergence(
198+
is_sparse=True, build_strategy=build_strategy, use_cuda=False)
188199

189200
def test_update_dense_parameter_reduce(self):
190201
build_strategy = fluid.BuildStrategy()
191202
build_strategy.reduce_strategy = fluid.BuildStrategy.ReduceStrategy.Reduce
192203
self.check_network_convergence(
193-
is_sparse=False, build_strategy=build_strategy)
204+
is_sparse=False, build_strategy=build_strategy, use_cuda=True)
205+
self.check_network_convergence(
206+
is_sparse=False, build_strategy=build_strategy, use_cuda=False)
194207

195208

196209
if __name__ == '__main__':

python/paddle/fluid/tests/unittests/test_parallel_executor_fetch_feed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def test_fetch_op(self):
8989
for i in range(iters):
9090
train_inputs.append(tst_reader_iter.next())
9191

92-
self.parallel_exe(train_inputs, seed=1, use_cuda=True)
9392
os.environ['CPU_NUM'] = str(4)
93+
self.parallel_exe(train_inputs, seed=1, use_cuda=True)
9494
self.parallel_exe(train_inputs, seed=1, use_cuda=False)
9595

9696

@@ -134,8 +134,8 @@ def parallel_exe(self, use_cuda, seed):
134134
break
135135

136136
def test_feed_op(self):
137-
self.parallel_exe(use_cuda=True, seed=1)
138137
os.environ['CPU_NUM'] = str(4)
138+
self.parallel_exe(use_cuda=True, seed=1)
139139
self.parallel_exe(use_cuda=False, seed=1)
140140

141141

python/paddle/fluid/tests/unittests/test_parallel_executor_seresnext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ def check_resnet_convergence(self,
135135
balance_parameter_opt_between_cards,
136136
use_cuda=True,
137137
iter=20):
138+
os.environ['CPU_NUM'] = str(4)
139+
138140
import functools
139141
batch_size = 2
140142
self.check_network_convergence(
@@ -147,12 +149,10 @@ def check_resnet_convergence(self,
147149
)
148150

149151
def test_resnet(self):
150-
os.environ['CPU_NUM'] = str(4)
151152
self.check_resnet_convergence(False, use_cuda=True)
152153
self.check_resnet_convergence(False, use_cuda=False, iter=5)
153154

154155
def test_resnet_with_new_strategy(self):
155-
os.environ['CPU_NUM'] = str(4)
156156
self.check_resnet_convergence(True, use_cuda=True)
157157
self.check_resnet_convergence(True, use_cuda=False, iter=5)
158158

0 commit comments

Comments
 (0)