Skip to content

Commit a8df411

Browse files
committed
Replace random_shuffle using shuffle.
* reduce trainer count for unit test on MAC OSX
1 parent 1d4bc47 commit a8df411

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

paddle/gserver/dataproviders/DataProviderGroup.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ void DataProviderGroup<T>::reset() {
6565
provider_ = nullptr;
6666

6767
// shuffle file list
68-
std::random_shuffle(fileList_.begin(), fileList_.end());
68+
std::shuffle(fileList_.begin(), fileList_.end(),
69+
ThreadLocalRandomEngine::get());
6970

7071
startLoader();
7172
DataProvider::reset();

paddle/gserver/dataproviders/ProtoDataProvider.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ void ProtoDataProvider::reset() {
374374
}
375375

376376
void ProtoDataProvider::shuffle() {
377-
std::random_shuffle(shuffledSequenceIds_.begin(), shuffledSequenceIds_.end());
377+
std::shuffle(shuffledSequenceIds_.begin(), shuffledSequenceIds_.end(),
378+
ThreadLocalRandomEngine::get());
378379
}
379380

380381
/*

paddle/math/Matrix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2514,7 +2514,8 @@ void SharedCpuMatrix::mul(CpuSparseMatrix* a, CpuMatrix* b, real scaleAB,
25142514
for (int k = 0; k < blockNum_; ++k) {
25152515
blockSeq.push_back(k);
25162516
}
2517-
std::random_shuffle(blockSeq.begin(), blockSeq.end());
2517+
std::shuffle(blockSeq.begin(), blockSeq.end(),
2518+
ThreadLocalRandomEngine::get());
25182519
}
25192520
std::vector<int>& localBufRows = *localBufRows_;
25202521
int* cols = a->getCols();

paddle/trainer/tests/test_CompareSparse.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ TEST(compareSparse, remote_cpu) {
146146
TEST(compareSparse, cpu10_local_vs_remote) {
147147
FLAGS_local = 1; // disable remote sparse update in parameter config
148148
std::vector<ParameterPtr> localParameters =
149-
trainerOnePassTest(configFile1, true, 10);
149+
trainerOnePassTest(configFile1, true, 2);
150150

151151
FLAGS_local = 0; // will enable remote sparse update
152152
FLAGS_ports_num_for_sparse = 5;
153153
std::vector<ParameterPtr> remoteParameters =
154-
trainerOnePassTest(configFile1, true, 10);
154+
trainerOnePassTest(configFile1, true, 2);
155155

156156
compareValue(localParameters, remoteParameters);
157157
}
@@ -174,7 +174,7 @@ TEST(compareSparse, multiGradientMachine) {
174174
FLAGS_parallel_nn = useGpu;
175175
LOG(INFO) << " local=" << local
176176
<< " useGpu=" << useGpu;
177-
int trainerCount = useGpu ? numGpu : 10;
177+
int trainerCount = useGpu ? numGpu : 2;
178178
std::vector<ParameterPtr> parameters =
179179
trainerOnePassTest(configFile1, true, trainerCount, useGpu);
180180
compareValue(getDenseParameters(), parameters, eps);

0 commit comments

Comments
 (0)