-
Notifications
You must be signed in to change notification settings - Fork 6.7k
enabling test_dropout after fixing flaky issue #13276
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,8 @@ class DropoutOp { | |
| static void BernoulliGenerate(common::random::RandGenerator<cpu, DType> gen, | ||
| int n, double p, int* r) { | ||
| typename RandGenerator<xpu, DType>::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); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pengzhao-intel vslNewStream was passed (seed + my_offset) which is variable for different threads as my_offset depends on thread number. I have removed my_offset, so whatever seed value is generated, it's used to generate stream for each thread.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the my_offset here while leaving them in the vslSkipAheadStream and viRngBernoulli functions? What's the rationale behind? Thanks!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @apeforest By removing my_offset from vslNewStream and making the seed same for all threads, we are ensuring that the same stream is generated for each thread. |
||
| vslSkipAheadStream(stream, my_offset); | ||
| viRngBernoulli(VSL_RNG_METHOD_BERNOULLI_ICDF, stream, my_amount, r + my_offset, p); | ||
| vslDeleteStream(&stream); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be better to change this parallel approach to "#pragma omp paralle for" so it will be more readable than OMP section parallel.
Do you mind to change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pengzhao-intel Thanks for your feedback. I don't see why "#pragma omp parallel for" would be more readable in this case as there is no for loop involved. The job for each thread is defined based on its thread number. Introducing a for loop with "#pragma omp parallel for" would be redundant. Please correct me if I've misunderstood it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give more hint on why adding an abs function fixed the flakiness of the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apeforest vslNewStream expects a non-negative integer as seed by definition. genImpl.rand() generates negative numbers too, which sometimes leads to negative seed values being passed to vslNewStream. abs() helps keep that in check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. In this case I would suggest we add an assert here to make sure seed is nonnegative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a check to make sure seed is non-negative.