From 7ae7d2bba2f686e42ca36e722dcd8841b304a9e4 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 14 Nov 2018 23:45:54 +0000 Subject: [PATCH 1/2] enabling test_dropout after fixing flaky issue --- src/operator/nn/dropout-inl.h | 4 ++-- tests/python/unittest/test_operator.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/operator/nn/dropout-inl.h b/src/operator/nn/dropout-inl.h index b7c40fbdf52a..52e56f41a80b 100644 --- a/src/operator/nn/dropout-inl.h +++ b/src/operator/nn/dropout-inl.h @@ -82,7 +82,7 @@ class DropoutOp { static void BernoulliGenerate(common::random::RandGenerator gen, int n, double p, int* r) { typename RandGenerator::Impl genImpl(&gen, 1); - const int seed = 17 + genImpl.rand() % 4096; // NOLINT(runtime/threadsafe_fn) + const int seed = 17 + abs(genImpl.rand() % 4096); const int nthr = engine::OpenMP::Get()->GetRecommendedOMPThreadCount(); #pragma omp parallel num_threads(nthr) { @@ -92,7 +92,7 @@ class DropoutOp { const int my_amount = std::min(my_offset + avg_amount, n) - my_offset; if (my_amount > 0) { VSLStreamStatePtr stream; - vslNewStream(&stream, VSL_BRNG_MCG31, seed + my_offset); + vslNewStream(&stream, VSL_BRNG_MCG31, seed); vslSkipAheadStream(stream, my_offset); viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, stream, my_amount, r + my_offset, p); vslDeleteStream(&stream); diff --git a/tests/python/unittest/test_operator.py b/tests/python/unittest/test_operator.py index 5fe9e3e048aa..4613ce8874b5 100644 --- a/tests/python/unittest/test_operator.py +++ b/tests/python/unittest/test_operator.py @@ -5807,7 +5807,6 @@ def test_stack(): @with_seed() -@unittest.skip("Flaky test, tracked at https://github.com/apache/incubator-mxnet/issues/12314") def test_dropout(): def zero_count(array, ratio): zeros = 0 From 85f6adb43f64880a2e34c6ffd43ac6154e3a8dca Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 16 Nov 2018 21:41:17 +0000 Subject: [PATCH 2/2] adding a check for positive seed --- src/operator/nn/dropout-inl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operator/nn/dropout-inl.h b/src/operator/nn/dropout-inl.h index 52e56f41a80b..9668c227b309 100644 --- a/src/operator/nn/dropout-inl.h +++ b/src/operator/nn/dropout-inl.h @@ -83,6 +83,7 @@ class DropoutOp { int n, double p, int* r) { typename RandGenerator::Impl genImpl(&gen, 1); const int seed = 17 + abs(genImpl.rand() % 4096); + CHECK_GE(seed, 0); const int nthr = engine::OpenMP::Get()->GetRecommendedOMPThreadCount(); #pragma omp parallel num_threads(nthr) {