diff --git a/src/operator/nn/dropout-inl.h b/src/operator/nn/dropout-inl.h index b7c40fbdf52a..9668c227b309 100644 --- a/src/operator/nn/dropout-inl.h +++ b/src/operator/nn/dropout-inl.h @@ -82,7 +82,8 @@ 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); + CHECK_GE(seed, 0); const int nthr = engine::OpenMP::Get()->GetRecommendedOMPThreadCount(); #pragma omp parallel num_threads(nthr) { @@ -92,7 +93,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 283a2820a4c3..1bf9ca0237ab 100644 --- a/tests/python/unittest/test_operator.py +++ b/tests/python/unittest/test_operator.py @@ -5808,7 +5808,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